-
Notifications
You must be signed in to change notification settings - Fork 0
/
wproc.cpp
204 lines (167 loc) · 5.78 KB
/
wproc.cpp
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
#include "wproc.hpp"
#include <windowsx.h>
#include "msg.hpp"
#include "runner.hpp"
#include "ui.hpp"
namespace wproc {
LRESULT CALLBACK wndProc(HWND hWnd, unsigned int uMsg, WPARAM wParam, LPARAM lParam) {
static HBRUSH BGDark = CreateSolidBrush(0x3f3936); // Background brush for the dark theme.
switch (uMsg) {
HANDLE_MSG(hWnd, WM_ACTIVATE, msg::onActivate);
HANDLE_MSG(hWnd, WM_CLOSE, msg::onClose);
HANDLE_MSG(hWnd, WM_COMMAND, msg::onCommand);
HANDLE_MSG(hWnd, WM_CREATE, msg::onCreate);
HANDLE_MSG(hWnd, WM_INITMENUPOPUP, msg::onInitMenuPopup);
HANDLE_MSG(hWnd, WM_SIZE, msg::onSize);
#ifndef UNDER_CE
HANDLE_MSG(hWnd, WM_DROPFILES, msg::onDropFiles);
HANDLE_MSG(hWnd, WM_GETMINMAXINFO, msg::onGetMinMaxInfo);
case 0x2e0: // WM_DPICHANGED
msg::onDPIChanged(hWnd, HIWORD(wParam), (const RECT *)lParam);
return 0;
#endif
case WM_CTLCOLOREDIT:
if (global::dark) {
SetTextColor((HDC)wParam, 0x00ff00);
SetBkColor((HDC)wParam, 0x3f3936);
return (LRESULT)BGDark;
} else {
return DefWindowProcW(hWnd, uMsg, wParam, lParam);
}
case WM_CTLCOLORSTATIC:
if (global::dark) {
SetTextColor((HDC)wParam, 0x00ff00);
SetBkColor((HDC)wParam, 0x000000);
return (LRESULT)GetStockObject(BLACK_BRUSH);
} else {
return DefWindowProcW(hWnd, uMsg, wParam, lParam);
}
case WM_DESTROY:
msg::onDestroy();
DeleteObject(BGDark);
PostQuitMessage(0);
return 0;
case WM_APP_THREADEND:
WaitForSingleObject(runner::hThread, INFINITE);
CloseHandle(runner::hThread);
runner::hThread = NULL;
runner::ctrlThread = runner::CTRLTHREAD_RUN;
return 0;
}
return DefWindowProcW(hWnd, uMsg, wParam, lParam);
}
LRESULT CALLBACK editorProc(HWND hWnd, unsigned uMsg, WPARAM wParam, LPARAM lParam) {
static WNDPROC prevWndProc = (WNDPROC)myGetWindowLongW(hWnd, GWL_USERDATA);
switch (uMsg) {
case EM_UNDO:
global::history.undo();
ui::updateTitle();
return 0;
case WM_DESTROY:
mySetWindowLongW(hWnd, GWL_WNDPROC, prevWndProc);
return 0;
}
return CallWindowProcW(prevWndProc, hWnd, uMsg, wParam, lParam);
}
LRESULT CALLBACK inputProc(HWND hWnd, unsigned uMsg, WPARAM wParam, LPARAM lParam) {
static WNDPROC prevWndProc = (WNDPROC)myGetWindowLongW(hWnd, GWL_USERDATA);
switch (uMsg) {
case EM_UNDO:
global::inputHistory.undo();
ui::updateTitle();
return 0;
case WM_DESTROY:
mySetWindowLongW(hWnd, GWL_WNDPROC, prevWndProc);
return 0;
}
return CallWindowProcW(prevWndProc, hWnd, uMsg, wParam, lParam);
}
LRESULT CALLBACK memViewDlgEditor(HWND hWnd, unsigned uMsg, WPARAM wParam, LPARAM lParam) {
static WNDPROC prevWndProc = (WNDPROC)myGetWindowLongW(hWnd, GWL_USERDATA);
switch (uMsg) {
case WM_CHAR:
switch ((wchar_t)wParam) {
case L'q':
SendMessageW(hWnd, EM_REPLACESEL, 0, (WPARAM)L"1");
return 0;
case L'w':
SendMessageW(hWnd, EM_REPLACESEL, 0, (WPARAM)L"2");
return 0;
case L'e':
SendMessageW(hWnd, EM_REPLACESEL, 0, (WPARAM)L"3");
return 0;
case L'r':
SendMessageW(hWnd, EM_REPLACESEL, 0, (WPARAM)L"4");
return 0;
case L't':
SendMessageW(hWnd, EM_REPLACESEL, 0, (WPARAM)L"5");
return 0;
case L'y':
SendMessageW(hWnd, EM_REPLACESEL, 0, (WPARAM)L"6");
return 0;
case L'u':
SendMessageW(hWnd, EM_REPLACESEL, 0, (WPARAM)L"7");
return 0;
case L'i':
SendMessageW(hWnd, EM_REPLACESEL, 0, (WPARAM)L"8");
return 0;
case L'o':
SendMessageW(hWnd, EM_REPLACESEL, 0, (WPARAM)L"9");
return 0;
case L'p':
SendMessageW(hWnd, EM_REPLACESEL, 0, (WPARAM)L"0");
return 0;
}
break;
case WM_DESTROY:
mySetWindowLongW(hWnd, GWL_WNDPROC, prevWndProc);
return 0;
}
return CallWindowProcW(prevWndProc, hWnd, uMsg, wParam, lParam);
}
INT_PTR CALLBACK memViewProc(HWND hDlg, unsigned uMsg, WPARAM wParam, LPARAM lParam) {
UNREFERENCED_PARAMETER(lParam);
switch (uMsg) {
case WM_INITDIALOG: {
// Puts the dialog at the center of the parent window.
RECT wndSize, wndRect, dlgRect;
GetWindowRect(hDlg, &dlgRect);
GetWindowRect(global::hWnd, &wndRect);
GetClientRect(global::hWnd, &wndSize);
int newPosX = wndRect.left + (wndSize.right - (dlgRect.right - dlgRect.left)) / 2,
newPosY = wndRect.top + (wndSize.bottom - (dlgRect.bottom - dlgRect.top)) / 2;
if (newPosX < 0) newPosX = 0;
if (newPosY < 0) newPosY = 0;
SetWindowPos(hDlg, NULL, newPosX, newPosY, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
wchar_t editBuf[10];
HWND hEdit = GetDlgItem(hDlg, 3);
wsprintfW(editBuf, L"%u", global::memViewStart <= 999999999 ? global::memViewStart : 999999999);
SendDlgItemMessageW(hDlg, 3, EM_SETLIMITTEXT, 9, 0);
SetDlgItemTextW(hDlg, 3, editBuf);
mySetWindowLongW(hEdit, GWL_USERDATA, mySetWindowLongW(hEdit, GWL_WNDPROC, memViewDlgEditor));
return TRUE;
}
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK: {
wchar_t editBuf[10];
long temp;
GetDlgItemTextW(hDlg, 3, (wchar_t *)editBuf, 10);
temp = wcstol(editBuf, NULL, 10);
if (temp < 0) {
util::messageBox(hDlg, global::hInst, L"Invalid input.", L"Error", MB_ICONWARNING);
} else {
global::memViewStart = temp;
EndDialog(hDlg, IDOK);
}
return TRUE;
}
case IDCANCEL:
EndDialog(hDlg, IDCANCEL);
return TRUE;
}
return FALSE;
}
return FALSE;
}
} // namespace wproc