-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsoroMfcKeyMoveExView.cpp
More file actions
461 lines (342 loc) · 10.4 KB
/
soroMfcKeyMoveExView.cpp
File metadata and controls
461 lines (342 loc) · 10.4 KB
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
// soroMfcKeyMoveExView.cpp : implementation of the CsoroMfcKeyMoveExView class
//
#include "pch.h"
#include "framework.h"
// SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
// and search filter handlers and allows sharing of document code with that project.
#ifndef SHARED_HANDLERS
#include "soroMfcKeyMoveEx.h"
#endif
#include "soroMfcKeyMoveExDoc.h"
#include "soroMfcKeyMoveExView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CsoroMfcKeyMoveExView
IMPLEMENT_DYNCREATE(CsoroMfcKeyMoveExView, CView)
BEGIN_MESSAGE_MAP(CsoroMfcKeyMoveExView, CView)
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CView::OnFilePrintPreview)
ON_WM_CREATE()
ON_WM_KEYDOWN()
ON_WM_CHAR()
ON_WM_SYSKEYDOWN()
ON_WM_SYSCHAR()
ON_WM_MOUSEMOVE()
ON_WM_PAINT()
ON_WM_MOUSEWHEEL()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONDBLCLK()
ON_WM_LBUTTONUP()
ON_WM_MOUSELEAVE()
END_MESSAGE_MAP()
// CsoroMfcKeyMoveExView construction/destruction
CsoroMfcKeyMoveExView::CsoroMfcKeyMoveExView() noexcept
{
// TODO: add construction code here
}
CsoroMfcKeyMoveExView::~CsoroMfcKeyMoveExView()
{
}
BOOL CsoroMfcKeyMoveExView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
// CsoroMfcKeyMoveExView drawing
void CsoroMfcKeyMoveExView::OnDraw(CDC* /*pDC*/)
{
CsoroMfcKeyMoveExDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: add draw code for native data here
}
// CsoroMfcKeyMoveExView printing
BOOL CsoroMfcKeyMoveExView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CsoroMfcKeyMoveExView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CsoroMfcKeyMoveExView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
// CsoroMfcKeyMoveExView diagnostics
#ifdef _DEBUG
void CsoroMfcKeyMoveExView::AssertValid() const
{
CView::AssertValid();
}
void CsoroMfcKeyMoveExView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CsoroMfcKeyMoveExDoc* CsoroMfcKeyMoveExView::GetDocument() const // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CsoroMfcKeyMoveExDoc)));
return (CsoroMfcKeyMoveExDoc*)m_pDocument;
}
#endif //_DEBUG
// CsoroMfcKeyMoveExView message handlers
int CsoroMfcKeyMoveExView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
m_wndChild.Create(_T("STATIC"),
_T("GoodNeighborhood"),
WS_CHILD | WS_VISIBLE | WS_BORDER,
CRect(100, 100, 400, 400),
this,
1234);
m_wndTrack.Create(_T("STATIC"),
_T("TRACT_TEST"),
WS_CHILD | WS_VISIBLE | WS_BORDER | SS_NOTIFY,
CRect(500, 100, 650, 400),
this,
12345);
m_ptChildWindowPos = CPoint(100, 100);
m_ptItemText = CPoint(10, 50);
m_pointMouse = NULL;
m_isDrag = false;
m_isDragForChildWindow = false;
m_isTrack = false;
return 0;
}
void CsoroMfcKeyMoveExView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
CPoint cPoint;
CRect cRect;
CString l_str = _T("");
// Get the child window's coordination points based on the Monitor
m_wndChild.GetWindowRect(&cRect);
cPoint.x = cRect.left;
cPoint.y = cRect.top;
l_str.Format(_T("※○※○※○ After GetWindowRect: %d, %d, %d, %d\n"),
cPoint.x, cPoint.y, cRect.Width(), cRect.Height());
OutputDebugStringW(l_str);
// convert view area coordination from screen(Monitor) coordination
ScreenToClient(&cPoint);
l_str.Format(_T("※○※○※○ After ScreenToClient: %d, %d, %d, %d\n"),
cPoint.x, cPoint.y, cRect.Width(), cRect.Height());
OutputDebugStringW(l_str);
int li_moving_step = (movingStep * 10);
switch (nChar)
{
case VK_LEFT:
cPoint.x -= li_moving_step;
break;
case VK_RIGHT:
cPoint.x += li_moving_step;
break;
case VK_UP:
cPoint.y -= li_moving_step;
break;
case VK_DOWN:
cPoint.y += li_moving_step;
break;
}
// move the child view (m_wndChild) with the convertied monitor coordinator
m_wndChild.SetWindowPos(&CWnd::wndTop,
cPoint.x, cPoint.y, 0, 0,
SWP_SHOWWINDOW | SWP_NOZORDER | SWP_NOSIZE);
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CsoroMfcKeyMoveExView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
CString ls_str = _T("");;
ls_str.Format(_T("※○※○※○ After OnChar: %c\n"),nChar);
m_wndChild.SetWindowTextW(ls_str);
OutputDebugStringW(ls_str);
CView::OnChar(nChar, nRepCnt, nFlags);
}
// Alt Key, F10 Key
void CsoroMfcKeyMoveExView::OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
CString ls_str = TEXT("");
WORD wResult = ::GetKeyState(VK_SPACE);
BYTE byHigh = HIBYTE(wResult);
if (byHigh & 0x01) {
// Alt
ls_str += TEXT("※○※○※○ Alt + Space\n");
wResult = ::GetKeyState(VK_CAPITAL);
// 하위 바이트이ㅡ 1번 비트가 1이면 토글 키가 켜진 상태
BYTE byLow = LOBYTE(wResult);
if (byLow & 0x01) ls_str += TEXT("※○※○※○ CAPS LOCK ON\n");
else ls_str += TEXT("※○※○※○ CAPS LOCK OFF\n");
OutputDebugStringW(ls_str);
}
CView::OnSysKeyDown(nChar, nRepCnt, nFlags);
}
void CsoroMfcKeyMoveExView::OnSysChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
CString ls_str = _T("");
if (nChar == VK_RETURN)
ls_str = _T("※○※○※○ Alt + Enter\n");
else if (nChar == 's' || nChar == 'S')
ls_str = _T("※○※○※○ Alt + S\n");
else if (nChar == 'x' || nChar == 'X') {
ls_str = _T("※○※○※○ Alt + X\n");
OutputDebugStringW(ls_str);
exit(1);
}
OutputDebugStringW(ls_str);
CView::OnSysChar(nChar, nRepCnt, nFlags);
}
void CsoroMfcKeyMoveExView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_pointMouse = point;
if (m_isDrag) {
CRect rect;
GetClientRect(&rect);
if (rect.PtInRect(point)) {
m_ptItemText = point;
}
else {
m_ptItemText.x = point.x < 0 ? 0 : (point.x > rect.right-20 ? rect.right-20 : point.x);
m_ptItemText.y = point.y < 0 ? 0 : (point.y > rect.bottom-20 ? rect.bottom-20 : point.y);
}
RedrawWindow();
}
if (m_isDragForChildWindow) {
CRect rect;
GetClientRect(&rect);
if (rect.PtInRect(point)) {
m_ptChildWindowPos = point;
}
else {
m_ptChildWindowPos.x = point.x < 0 ? 0 : (point.x > rect.right - 20 ? rect.right - 20 : point.x);
m_ptChildWindowPos.y = point.y < 0 ? 0 : (point.y > rect.bottom - 20 ? rect.bottom - 20 : point.y);
}
CRect cRectForChildWindow;
m_wndChild.GetWindowRect(&cRectForChildWindow);
ScreenToClient(&cRectForChildWindow);
InvalidateRect(&cRectForChildWindow, 1);
}
if (!m_isTrack) {
TRACKMOUSEEVENT tme = { 0 };
tme.cbSize = sizeof(tme);
tme.dwFlags = TME_LEAVE;
tme.hwndTrack = m_hWnd;
tme.dwHoverTime = 0;
m_isTrack = ::_TrackMouseEvent(&tme);
if (m_isTrack)
SetWindowText(_T("Tracking"));
CString ls_str = _T("");
ls_str = _T("※○※○※○ CsoroMfcKeyMoveExView-OnMouseMove TrackMouseEvent On\n");
OutputDebugStringW(ls_str);
}
CView::OnMouseMove(nFlags, point);
}
void CsoroMfcKeyMoveExView::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CView::OnPaint() for painting messages
CString ls_str = _T("");
ls_str.Format(_T("x: %03d, y: %03d"), m_pointMouse.x, m_pointMouse.y);
dc.TextOutW(10, 10, ls_str);
if (m_isDrag) {
ls_str.Format(_T("is dragging..."));
}
else {
ls_str.Format(_T("is not dragging"));
}
dc.TextOutW(m_ptItemText.x, m_ptItemText.y, ls_str);
if (m_isDragForChildWindow) {
m_wndChild.SetWindowPos(&CWnd::wndTop,
m_ptChildWindowPos.x, m_ptChildWindowPos.y, 0, 0,
SWP_SHOWWINDOW | SWP_NOZORDER | SWP_NOSIZE);
}
}
BOOL CsoroMfcKeyMoveExView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
// TODO: Add your message handler code here and/or call default
CString ls_str = _T("");
ls_str.Format(_T("※○※○※○ zDelta: %d\n"), zDelta);
OutputDebugStringW(ls_str);
return CView::OnMouseWheel(nFlags, zDelta, pt);
}
void CsoroMfcKeyMoveExView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (point.x >= m_ptItemText.x - 16 &&
point.x <= m_ptItemText.x + 16 &&
point.y >= m_ptItemText.y - 16 &&
point.y <= m_ptItemText.y + 16) {
m_isDrag = true;
RedrawWindow();
SetCapture();
}
CRect cRect;
m_wndChild.GetWindowRect(&cRect);
ScreenToClient(&cRect);
if (cRect.PtInRect(point)) {
m_ptChildWindowPos = point;
m_isDragForChildWindow = true;
InvalidateRect(&cRect, 1);
SetCapture();
}
CView::OnLButtonDown(nFlags, point);
}
void CsoroMfcKeyMoveExView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CView::OnLButtonDblClk(nFlags, point);
}
void CsoroMfcKeyMoveExView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (m_isDrag) {
CRect rect;
GetClientRect(&rect);
if (rect.PtInRect(point)) {
m_ptItemText = point;
}
else {
m_ptItemText.x = point.x < 0 ? 0 : (point.x > rect.right-20 ? rect.right-20 : point.x);
m_ptItemText.y = point.y < 0 ? 0 : (point.y > rect.bottom-20 ? rect.bottom-20 : point.y);
}
m_isDrag = false;
RedrawWindow();
ReleaseCapture();
}
if (m_isDragForChildWindow) {
CRect rect;
GetClientRect(&rect);
if (rect.PtInRect(point)) {
m_ptChildWindowPos = point;
}
else {
m_ptChildWindowPos.x = point.x < 0 ? 0 : (point.x > rect.right - 20 ? rect.right - 20 : point.x);
m_ptChildWindowPos.y = point.y < 0 ? 0 : (point.y > rect.bottom - 20 ? rect.bottom - 20 : point.y);
}
m_isDragForChildWindow = false;
RedrawWindow();
ReleaseCapture();
}
CView::OnLButtonUp(nFlags, point);
}
void CsoroMfcKeyMoveExView::OnMouseLeave()
{
// TODO: Add your message handler code here and/or call default
SetWindowText(_T("Track Test"));
m_isTrack = false;
CString ls_str = _T("");
ls_str = _T("※○※○※○ CsoroMfcKeyMoveExView-OnMouseLeave TrackMouseEvent Off\n");
OutputDebugStringW(ls_str);
CView::OnMouseLeave();
}