-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
XG_PictureBoxDialog.hpp
174 lines (146 loc) · 4.61 KB
/
XG_PictureBoxDialog.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#pragma once
#include "XG_Window.hpp"
class XG_PictureBoxDialog : public XG_Dialog
{
public:
XGStringW m_strFile;
HBITMAP m_hbm = nullptr;
HENHMETAFILE m_hEMF = nullptr;
XG_PictureBoxDialog() noexcept
{
}
~XG_PictureBoxDialog() noexcept
{
DoDelete();
}
void DoDelete() noexcept
{
DeleteObject(m_hbm);
m_hbm = nullptr;
::DeleteEnhMetaFile(m_hEMF);
m_hEMF = nullptr;
}
void RefreshImage(HWND hwnd)
{
HWND hCmb1 = GetDlgItem(hwnd, cmb1);
WCHAR szText[MAX_PATH];
ComboBox_RealGetText(hCmb1, szText, _countof(szText));
HWND hIco1 = GetDlgItem(hwnd, ico1);
HWND hIco2 = GetDlgItem(hwnd, ico2);
SendMessageW(hIco1, STM_SETIMAGE, IMAGE_ENHMETAFILE, 0);
SendMessageW(hIco2, STM_SETIMAGE, IMAGE_BITMAP, 0);
DoDelete();
SetWindowPos(hIco1, nullptr, 0, 0, 32, 32, SWP_NOMOVE | SWP_NOZORDER | SWP_HIDEWINDOW);
SetWindowPos(hIco2, nullptr, 0, 0, 32, 32, SWP_NOMOVE | SWP_NOZORDER | SWP_HIDEWINDOW);
if (XgLoadImage(szText, m_hbm, m_hEMF))
{
if (m_hbm) {
auto hbm2 = static_cast<HBITMAP>(::CopyImage(m_hbm, IMAGE_BITMAP, 32, 32, LR_CREATEDIBSECTION));
DeleteObject(m_hbm);
m_hbm = hbm2;
ShowWindow(hIco2, SW_SHOWNOACTIVATE);
SendMessageW(hIco2, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)m_hbm);
return;
}
if (m_hEMF) {
ShowWindow(hIco1, SW_SHOWNOACTIVATE);
SendMessageW(hIco1, STM_SETIMAGE, IMAGE_ENHMETAFILE, (LPARAM)m_hEMF);
return;
}
}
}
BOOL OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
XgCenterDialog(hwnd);
HWND hCmb1 = GetDlgItem(hwnd, cmb1);
// 画像ファイルリストを取得する。
std::vector<XGStringW> items;
XgGetFileManager()->get_list(items);
for (auto& item : items) {
ComboBox_AddString(hCmb1, item.c_str());
}
ComboBox_RealSetText(hCmb1, m_strFile.c_str());
RefreshImage(hwnd);
DragAcceptFiles(hwnd, TRUE);
return TRUE;
}
BOOL OnOK(HWND hwnd)
{
HWND hCmb1 = GetDlgItem(hwnd, cmb1);
WCHAR szText[MAX_PATH];
ComboBox_RealGetText(hCmb1, szText, _countof(szText));
m_strFile = szText;
return TRUE;
}
void OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
switch (id)
{
case IDOK:
if (OnOK(hwnd)) {
// ダイアログを終了。
::EndDialog(hwnd, id);
}
break;
case IDCANCEL:
// ダイアログを終了。
::EndDialog(hwnd, id);
break;
case psh1:
OnPsh1(hwnd);
break;
case cmb1:
if (codeNotify == CBN_SELCHANGE || codeNotify == CBN_EDITCHANGE)
{
RefreshImage(hwnd);
}
break;
default:
break;
}
}
void OnDropFiles(HWND hwnd, HDROP hdrop)
{
WCHAR szFile[MAX_PATH];
::DragQueryFile(hdrop, 0, szFile, _countof(szFile));
m_strFile = szFile;
HWND hCmb1 = GetDlgItem(hwnd, cmb1);
ComboBox_RealSetText(hCmb1, m_strFile.c_str());
RefreshImage(hwnd);
DragFinish(hdrop);
}
void OnPsh1(HWND hwnd)
{
WCHAR szFile[MAX_PATH] = L"";
OPENFILENAMEW ofn = { sizeof(ofn), hwnd };
ofn.lpstrFilter = L"Picture Files\0*.bmp;*.dib;*.emf;*.png;*.jpg;*.jpeg;*.jpe;*.jfif;*.tif;*.tiff;*.gif\0";
ofn.lpstrFile = szFile;
ofn.nMaxFile = _countof(szFile);
ofn.lpstrTitle = L"Choose Picture File";
ofn.Flags = OFN_EXPLORER | OFN_ENABLESIZING | OFN_HIDEREADONLY |
OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if (GetOpenFileNameW(&ofn)) {
m_strFile = szFile;
HWND hCmb1 = GetDlgItem(hwnd, cmb1);
ComboBox_RealSetText(hCmb1, m_strFile.c_str());
RefreshImage(hwnd);
}
}
INT_PTR CALLBACK
DialogProcDx(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) override
{
switch (uMsg)
{
HANDLE_MSG(hwnd, WM_INITDIALOG, OnInitDialog);
HANDLE_MSG(hwnd, WM_COMMAND, OnCommand);
HANDLE_MSG(hwnd, WM_DROPFILES, OnDropFiles);
default:
break;
}
return 0;
}
INT_PTR DoModal(HWND hwnd)
{
return DialogBoxDx(hwnd, IDD_PICTUREBOX);
}
};