-
Notifications
You must be signed in to change notification settings - Fork 0
/
control_event_test.cpp
235 lines (197 loc) · 5.69 KB
/
control_event_test.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#define LearningChapter "Control Event Test"
//page xxx
#include <Windows.h>
#include <tchar.h>
//#include "resource.h"
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
static LPCTSTR WindowClassName = _T(LearningChapter) _T(" Class");
static LPCTSTR WindowTitleName = _T(LearningChapter);
static const int WindowPosition[2] = { 400, 200 };
static const int WindowSize[2] = { 720, 480 };
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASS WndClass;
WndClass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInstance;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndClass.lpszMenuName = NULL;//MAKEINTRESOURCE(IDR_MENU0_0);
WndClass.lpszClassName = WindowClassName;
RegisterClass(&WndClass);
hwnd = CreateWindow(WindowClassName, WindowTitleName,
WS_OVERLAPPEDWINDOW,
WindowPosition[0], WindowPosition[1],
WindowSize[0], WindowSize[1],
NULL, NULL, hInstance, NULL
);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
static int x;
static int y;
static BOOL bnowDraw = FALSE;
static int isLBUTTONDOWN;
static int isLBUTTONUP ;
static int isLBUTTONDCLICK ;
static int isMOUSEMOVE ;
static int movePosX;
static int movePosY;
static int isRBUTTONDOWN;
static int isRBUTTONUP;
static int isRBUTTONDCLICK;
static int isMBUTTONDOWN;
static int isMBUTTONUP;
static int isMBUTTONDCLICK;
static int isMOUSEWHEEL;
static int wheel_zDelta;
static int wheel_xPos;
static int wheel_yPos;
static int isKEYDOWN;
static WPARAM isKEYDOWNwParam = 0;
static int isKEYUP= -1;
static int isCHAR;
static WPARAM isCHARwParam = 0;
//static int 변수를 하나씩 추가할 때마다 1씩 더한다
const int controlEvent = 14;
switch (iMsg) {
case WM_CREATE:
SetTimer(hwnd, 1, 10, NULL);
return 0;
case WM_LBUTTONDOWN:
isLBUTTONDOWN++;
x = LOWORD(lParam);
y = HIWORD(lParam);
bnowDraw = TRUE;
return 0;
case WM_LBUTTONUP:
isLBUTTONUP++;
bnowDraw = FALSE;
return 0;
case WM_LBUTTONDBLCLK:
isLBUTTONDCLICK++;
InvalidateRect(hwnd, NULL, TRUE);
return 0;
case WM_MOUSEMOVE:
isMOUSEMOVE++;
movePosX = LOWORD(lParam);
movePosY = HIWORD(lParam);
if (bnowDraw == TRUE) {
hdc = GetDC(hwnd);
MoveToEx(hdc, x, y, NULL);
x = LOWORD(lParam);
y = HIWORD(lParam);
LineTo(hdc, x, y);
ReleaseDC(hwnd, hdc);
}
return 0;
case WM_RBUTTONDOWN:
isRBUTTONDOWN++;
return 0;
case WM_RBUTTONUP:
isRBUTTONUP++;
return 0;
case WM_RBUTTONDBLCLK:
isRBUTTONDCLICK++;
return 0;
case WM_MBUTTONDOWN:
isMBUTTONDOWN++;
return 0;
case WM_MBUTTONUP:
isMBUTTONUP++;
return 0;
case WM_MBUTTONDBLCLK:
isMBUTTONDCLICK++;
return 0;
case WM_MOUSEWHEEL:
isMOUSEWHEEL++;
wheel_zDelta = (short)HIWORD(wParam);
wheel_xPos = LOWORD(lParam);
wheel_yPos = HIWORD(lParam);
return 0;
case WM_KEYDOWN:
isKEYDOWN++;
isKEYDOWNwParam = wParam;
if (wParam == VK_SPACE) {
isLBUTTONDOWN = 0;
isLBUTTONUP = 0;
isLBUTTONDCLICK = 0;
isMOUSEMOVE = 0;
isRBUTTONDOWN = 0;
isRBUTTONUP = 0;
isRBUTTONDCLICK = 0;
isMBUTTONDOWN = 0;
isMBUTTONUP = 0;
isMBUTTONDCLICK = 0;
isMOUSEWHEEL = 0;
wheel_zDelta = 0;
wheel_xPos = 0;
wheel_yPos = 0;
movePosX = 0;
movePosY = 0;
isKEYDOWN = 0;
isKEYDOWNwParam = 0;
isKEYUP = -1;
isCHAR = -1;
isCHARwParam = 0;
}
return 0;
case WM_KEYUP:
isKEYUP++;
return 0;
case WM_CHAR:
isCHAR++;
isCHARwParam = wParam;
return 0;
case WM_TIMER:
switch (wParam)
{
case 1:
{
TCHAR buff[controlEvent][256];
hdc = GetDC(hwnd);
_stprintf_s(buff[0], 256, _T("isLBUTTONDOWN(%d) "), isLBUTTONDOWN);
_stprintf_s(buff[1], 256, _T("isLBUTTONUP(%d) "), isLBUTTONUP);
_stprintf_s(buff[2], 256, _T("isLBUTTONDCLICK(%d) "), isLBUTTONDCLICK);
_stprintf_s(buff[3], 256, _T("isMOUSEMOVE(%d) "), isMOUSEMOVE);
_stprintf_s(buff[4], 256, _T("isRBUTTONDOWN(%d) "), isRBUTTONDOWN);
_stprintf_s(buff[5], 256, _T("isRBUTTONUP(%d) "), isRBUTTONUP);
_stprintf_s(buff[6], 256, _T("isRBUTTONDCLICK(%d) "), isRBUTTONDCLICK);
_stprintf_s(buff[7], 256, _T("isMBUTTONDOWN(%d) "), isMBUTTONDOWN);
_stprintf_s(buff[8], 256, _T("isMBUTTONUP(%d) "), isMBUTTONUP);
_stprintf_s(buff[9], 256, _T("isMBUTTONDCLICK(%d) "), isMBUTTONDCLICK);
_stprintf_s(buff[10], 256, _T("isMOUSEWHEEL(%d) "), isMOUSEWHEEL);
_stprintf_s(buff[11], 256, _T("isKEYDOWN(%d) w:%d "), isKEYDOWN, isKEYDOWNwParam);
_stprintf_s(buff[12], 256, _T("isKEYUP(%d) "), isKEYUP);
_stprintf_s(buff[13], 256, _T("isCHAR(%d) w:%d "), isCHAR, isCHARwParam);
for (int i = 0; i < controlEvent; i++)
TextOut(hdc, 0, i * 20, buff[i], _tcslen(buff[i]));
_stprintf_s(buff[10], 256, _T("zDelta:%d, xPos:%d, yPos:%d "), wheel_zDelta, wheel_xPos, wheel_yPos);
TextOut(hdc, 200, 0, buff[10], _tcslen(buff[10]));
_stprintf_s(buff[3], 256, _T("movePosX:%d, movePosY:%d "), movePosX, movePosY);
TextOut(hdc, 200, 20, buff[3], _tcslen(buff[3]));
ReleaseDC(hwnd, hdc);
}
break;
}
return 0;
case WM_DESTROY:
KillTimer(hwnd, 1);
PostQuitMessage(0);
return 0;
}
return(DefWindowProc(hwnd, iMsg, wParam, lParam));
}