-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialog.c
223 lines (186 loc) · 6.06 KB
/
dialog.c
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#include <windows.h>
#include <stdbool.h>
#include <commctrl.h>
#include <stdio.h>
#include <fcntl.h>
#include "custom.h"
#include "wm.h"
//#pragma comment(linker,"\"/manifestdependency:type='win32' \
//name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
//processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#define WINDOW_CLASS_NAME L"DialogTest"
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK DialogProc(HWND, UINT, WPARAM, LPARAM);
HINSTANCE g_hInst;
WNDPROC ButtonProc;
static LRESULT CALLBACK
ButtonSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{
printf("ButtonSubProc hwnd: %p msg: %s wParam: %p lParam: %p\n", hwnd, window_messages[uMsg], (void*)wParam, (void*)lParam);
if (!window_messages[uMsg]) {
printf(" -> unknown msg is %X\n", uMsg);
}
switch (uMsg) {
case WM_NCCREATE:
case WM_CREATE:
if (lParam) {
CREATESTRUCT* create_params = (CREATESTRUCT*)lParam;
const BYTE* data = create_params->lpCreateParams;
if (data) {
WORD len = *((WORD*)data);
printf("control data len: %d\n", len);
for (WORD i = 0; i < len; i++) {
printf("%02X ", data[2 + i]);
}
printf("\n");
}
}
break;
}
return DefSubclassProc(hwnd, uMsg, wParam, lParam);
}
static LRESULT CALLBACK
ButtonSuperProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
printf("ButtonSuperProc hwnd: %p msg: %s wParam: %p lParam: %p\n", hwnd, window_messages[uMsg], (void*)wParam, (void*)lParam);
if (!window_messages[uMsg]) {
printf(" -> unknown msg is %X\n", uMsg);
}
switch (uMsg) {
case WM_NCCREATE:
case WM_CREATE:
if (lParam) {
CREATESTRUCT* create_params = (CREATESTRUCT*)lParam;
const BYTE* data = create_params->lpCreateParams;
if (data) {
WORD len = *((WORD*)data);
printf("control data len: %d\n", len);
for (WORD i = 0; i < len; i++) {
printf("%02X ", data[2 + i]);
}
printf("\n");
}
}
break;
}
return ButtonProc(hwnd, uMsg, wParam, lParam);
}
void dump_error(DWORD err) {
wchar_t buf[256];
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
buf, (sizeof(buf) / sizeof(wchar_t)), NULL);
wprintf(L"%s", buf);
}
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR lpCmdLine, int nCmdShow)
{
g_hInst = hInstance;
AllocConsole();
freopen("CONOUT$", "w", stdout);
HICON hDefaultIcon = LoadIcon(NULL, IDI_APPLICATION);
HCURSOR hDefaultCursor = LoadCursor(NULL, IDC_ARROW);
WNDCLASSEXW buttonwc = { 0 };
buttonwc.cbSize = sizeof(WNDCLASSEXW);
if (GetClassInfoExW(NULL, L"BUTTON", &buttonwc) == 0) {
printf("GetClassInfoW failed: ");
dump_error(GetLastError());
}
ButtonProc = buttonwc.lpfnWndProc;
buttonwc.hInstance = hInstance;
buttonwc.lpfnWndProc = ButtonSuperProc;
// Note: If a manifest was used to set the version of the common controls to 6.0.0.0,
// then the RegisterClassExW would fail with "Class already registered", seemingly
// because the GetClassInfoExW call above implicitly registers the BUTTON class with
// our hInstance when using the newer common controls.
//
// So, if using common controls >= 6.0.0.0, an UnregisterClassW(L"BUTTON", hInstance)
// call is necessary before the RegisterClassExW call
// Don't care about the result of this call
UnregisterClassW(L"BUTTON", hInstance);
if (RegisterClassExW(&buttonwc) == 0) {
printf("RegisterClassW failed: ");
dump_error(GetLastError());
}
CustomRegister();
WNDCLASSW wc = { 0 };
wc.lpszClassName = WINDOW_CLASS_NAME;
wc.hInstance = hInstance;
wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
wc.lpfnWndProc = WndProc;
wc.hCursor = hDefaultCursor;
wc.hIcon = hDefaultIcon;
RegisterClassW(&wc);
HWND window = CreateWindowW(wc.lpszClassName, WINDOW_CLASS_NAME,
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, 400, 200, NULL, NULL, hInstance, NULL);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
if (IsDialogMessage(window, &msg))
continue;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
CustomUnregister();
return (int) msg.wParam;
}
LRESULT CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
printf("DialogProc hwnd: %p msg: %s wParam: %p lParam: %p\n", hwnd, window_messages[msg], (void*)wParam, (void*)lParam);
switch (msg) {
case WM_INITDIALOG:
HWND button = GetDlgItem(hwnd, 902);
SetWindowSubclass(button, ButtonSubProc, 0, 0);
break;
case WM_CTLCOLORDLG:
case WM_CTLCOLORSTATIC:
case WM_CTLCOLORBTN:
SetBkMode((HDC)wParam, TRANSPARENT);
return (LRESULT)GetSysColorBrush(COLOR_WINDOW);
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
return FALSE;
}
return 0;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
printf("WndProc hwnd: %p msg: %s wParam: %p lParam: %p\n", hwnd, window_messages[msg], (void*)wParam, (void*)lParam);
if (!window_messages[msg]) {
printf(" -> unknown msg is %X\n", msg);
}
switch(msg) {
case WM_INITDIALOG:
break;
case WM_CREATE:
HWND result = CreateDialogParamW(g_hInst, MAKEINTRESOURCEW(100), hwnd, DialogProc, (LPARAM)NULL);
if (!result) {
char buf[256];
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
buf, sizeof(buf), NULL);
printf("error creating dialog: %s\n", buf);
}
ShowWindow(result, SW_SHOWNORMAL);
break;
case WM_SIZE:
break;
case WM_COMMAND:
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_HSCROLL:
break;
case WM_CTLCOLORSTATIC:
case WM_CTLCOLORBTN:
SetBkMode((HDC)wParam, TRANSPARENT);
return (LRESULT) GetSysColorBrush(COLOR_WINDOW);
case WM_GETMINMAXINFO:
break;
}
return DefWindowProcW(hwnd, msg, wParam, lParam);
}