• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef UI_GFX_WIN_MSG_UTIL_H_
6 #define UI_GFX_WIN_MSG_UTIL_H_
7 
8 #include "base/logging.h"
9 #include "ui/gfx/geometry/point.h"
10 #include "ui/gfx/geometry/size.h"
11 
12 // Based on WTL version 8.0 atlcrack.h
13 
14 // This differs from the original atlcrack.h by removing usage of CPoint,
15 // CSize, etc.
16 
17 ///////////////////////////////////////////////////////////////////////////////
18 // Message map macro for cracked handlers
19 
20 // Note about message maps with cracked handlers:
21 // For ATL 3.0, a message map using cracked handlers MUST use BEGIN_MSG_MAP_EX.
22 // For ATL 7.0 or higher, you can use BEGIN_MSG_MAP for CWindowImpl/CDialogImpl
23 // derived classes,
24 // but must use BEGIN_MSG_MAP_EX for classes that don't derive from
25 // CWindowImpl/CDialogImpl.
26 
27 #define CR_BEGIN_MSG_MAP_EX(theClass)                             \
28  public:                                                          \
29   BOOL m_bMsgHandled;                                             \
30   /* "handled" management for cracked handlers */                 \
31   BOOL IsMsgHandled() const { return m_bMsgHandled; }             \
32   void SetMsgHandled(BOOL bHandled) { m_bMsgHandled = bHandled; } \
33   BOOL ProcessWindowMessage(HWND hWnd,                            \
34                             UINT uMsg,                            \
35                             WPARAM wParam,                        \
36                             LPARAM lParam,                        \
37                             LRESULT& lResult,                     \
38                             DWORD dwMsgMapID = 0) {               \
39     BOOL bOldMsgHandled = m_bMsgHandled;                          \
40     BOOL bRet = _ProcessWindowMessage(                            \
41         hWnd, uMsg, wParam, lParam, lResult, dwMsgMapID);         \
42     m_bMsgHandled = bOldMsgHandled;                               \
43     return bRet;                                                  \
44   }                                                               \
45   BOOL _ProcessWindowMessage(HWND hWnd,                           \
46                              UINT uMsg,                           \
47                              WPARAM wParam,                       \
48                              LPARAM lParam,                       \
49                              LRESULT& lResult,                    \
50                              DWORD dwMsgMapID) {                  \
51     BOOL bHandled = TRUE;                                         \
52     hWnd;                                                         \
53     uMsg;                                                         \
54     wParam;                                                       \
55     lParam;                                                       \
56     lResult;                                                      \
57     bHandled;                                                     \
58     switch (dwMsgMapID) {                                         \
59       case 0:
60 
61 // Replacement for atlwin.h's END_MSG_MAP for removing ATL usage.
62 #define CR_END_MSG_MAP()                                      \
63   break;                                                      \
64   default:                                                    \
65     NOTREACHED() << "Invalid message map ID: " << dwMsgMapID; \
66     break;                                                    \
67     }                                                         \
68     return FALSE;                                             \
69     }
70 
71 #define CR_GET_X_LPARAM(lParam) ((int)(short)LOWORD(lParam))
72 #define CR_GET_Y_LPARAM(lParam) ((int)(short)HIWORD(lParam))
73 
74 ///////////////////////////////////////////////////////////////////////////////
75 // Standard Windows message macros
76 
77 // int OnCreate(LPCREATESTRUCT lpCreateStruct)
78 #define CR_MSG_WM_CREATE(func)                       \
79   if (uMsg == WM_CREATE) {                           \
80     SetMsgHandled(TRUE);                             \
81     lResult = (LRESULT)func((LPCREATESTRUCT)lParam); \
82     if (IsMsgHandled())                              \
83       return TRUE;                                   \
84   }
85 
86 // BOOL OnInitDialog(CWindow wndFocus, LPARAM lInitParam)
87 #define CR_MSG_WM_INITDIALOG(func)                 \
88   if (uMsg == WM_INITDIALOG) {                     \
89     SetMsgHandled(TRUE);                           \
90     lResult = (LRESULT)func((HWND)wParam, lParam); \
91     if (IsMsgHandled())                            \
92       return TRUE;                                 \
93   }
94 
95 // BOOL OnCopyData(CWindow wnd, PCOPYDATASTRUCT pCopyDataStruct)
96 #define CR_MSG_WM_COPYDATA(func)                                    \
97   if (uMsg == WM_COPYDATA) {                                        \
98     SetMsgHandled(TRUE);                                            \
99     lResult = (LRESULT)func((HWND)wParam, (PCOPYDATASTRUCT)lParam); \
100     if (IsMsgHandled())                                             \
101       return TRUE;                                                  \
102   }
103 
104 // void OnDestroy()
105 #define CR_MSG_WM_DESTROY(func) \
106   if (uMsg == WM_DESTROY) {     \
107     SetMsgHandled(TRUE);        \
108     func();                     \
109     lResult = 0;                \
110     if (IsMsgHandled())         \
111       return TRUE;              \
112   }
113 
114 // void OnMove(CPoint ptPos)
115 #define CR_MSG_WM_MOVE(func)                                            \
116   if (uMsg == WM_MOVE) {                                                \
117     SetMsgHandled(TRUE);                                                \
118     func(gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
119     lResult = 0;                                                        \
120     if (IsMsgHandled())                                                 \
121       return TRUE;                                                      \
122   }
123 
124 // void OnSize(UINT nType, gfx::Size size)
125 #define CR_MSG_WM_SIZE(func)                                           \
126   if (uMsg == WM_SIZE) {                                               \
127     SetMsgHandled(TRUE);                                               \
128     func((UINT)wParam,                                                 \
129          gfx::Size(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
130     lResult = 0;                                                       \
131     if (IsMsgHandled())                                                \
132       return TRUE;                                                     \
133   }
134 
135 // void OnActivate(UINT nState, BOOL bMinimized, CWindow wndOther)
136 #define CR_MSG_WM_ACTIVATE(func)                                    \
137   if (uMsg == WM_ACTIVATE) {                                        \
138     SetMsgHandled(TRUE);                                            \
139     func((UINT)LOWORD(wParam), (BOOL)HIWORD(wParam), (HWND)lParam); \
140     lResult = 0;                                                    \
141     if (IsMsgHandled())                                             \
142       return TRUE;                                                  \
143   }
144 
145 // void OnSetFocus(CWindow wndOld)
146 #define CR_MSG_WM_SETFOCUS(func) \
147   if (uMsg == WM_SETFOCUS) {     \
148     SetMsgHandled(TRUE);         \
149     func((HWND)wParam);          \
150     lResult = 0;                 \
151     if (IsMsgHandled())          \
152       return TRUE;               \
153   }
154 
155 // void OnKillFocus(CWindow wndFocus)
156 #define CR_MSG_WM_KILLFOCUS(func) \
157   if (uMsg == WM_KILLFOCUS) {     \
158     SetMsgHandled(TRUE);          \
159     func((HWND)wParam);           \
160     lResult = 0;                  \
161     if (IsMsgHandled())           \
162       return TRUE;                \
163   }
164 
165 // void OnEnable(BOOL bEnable)
166 #define CR_MSG_WM_ENABLE(func) \
167   if (uMsg == WM_ENABLE) {     \
168     SetMsgHandled(TRUE);       \
169     func((BOOL)wParam);        \
170     lResult = 0;               \
171     if (IsMsgHandled())        \
172       return TRUE;             \
173   }
174 
175 // void OnPaint(CDCHandle dc)
176 #define CR_MSG_WM_PAINT(func) \
177   if (uMsg == WM_PAINT) {     \
178     SetMsgHandled(TRUE);      \
179     func((HDC)wParam);        \
180     lResult = 0;              \
181     if (IsMsgHandled())       \
182       return TRUE;            \
183   }
184 
185 // void OnClose()
186 #define CR_MSG_WM_CLOSE(func) \
187   if (uMsg == WM_CLOSE) {     \
188     SetMsgHandled(TRUE);      \
189     func();                   \
190     lResult = 0;              \
191     if (IsMsgHandled())       \
192       return TRUE;            \
193   }
194 
195 // BOOL OnQueryEndSession(UINT nSource, UINT uLogOff)
196 #define CR_MSG_WM_QUERYENDSESSION(func)                  \
197   if (uMsg == WM_QUERYENDSESSION) {                      \
198     SetMsgHandled(TRUE);                                 \
199     lResult = (LRESULT)func((UINT)wParam, (UINT)lParam); \
200     if (IsMsgHandled())                                  \
201       return TRUE;                                       \
202   }
203 
204 // BOOL OnQueryOpen()
205 #define CR_MSG_WM_QUERYOPEN(func) \
206   if (uMsg == WM_QUERYOPEN) {     \
207     SetMsgHandled(TRUE);          \
208     lResult = (LRESULT)func();    \
209     if (IsMsgHandled())           \
210       return TRUE;                \
211   }
212 
213 // BOOL OnEraseBkgnd(CDCHandle dc)
214 #define CR_MSG_WM_ERASEBKGND(func)        \
215   if (uMsg == WM_ERASEBKGND) {            \
216     SetMsgHandled(TRUE);                  \
217     lResult = (LRESULT)func((HDC)wParam); \
218     if (IsMsgHandled())                   \
219       return TRUE;                        \
220   }
221 
222 // void OnSysColorChange()
223 #define CR_MSG_WM_SYSCOLORCHANGE(func) \
224   if (uMsg == WM_SYSCOLORCHANGE) {     \
225     SetMsgHandled(TRUE);               \
226     func();                            \
227     lResult = 0;                       \
228     if (IsMsgHandled())                \
229       return TRUE;                     \
230   }
231 
232 // void OnEndSession(BOOL bEnding, UINT uLogOff)
233 #define CR_MSG_WM_ENDSESSION(func)    \
234   if (uMsg == WM_ENDSESSION) {        \
235     SetMsgHandled(TRUE);              \
236     func((BOOL)wParam, (UINT)lParam); \
237     lResult = 0;                      \
238     if (IsMsgHandled())               \
239       return TRUE;                    \
240   }
241 
242 // void OnShowWindow(BOOL bShow, UINT nStatus)
243 #define CR_MSG_WM_SHOWWINDOW(func)   \
244   if (uMsg == WM_SHOWWINDOW) {       \
245     SetMsgHandled(TRUE);             \
246     func((BOOL)wParam, (int)lParam); \
247     lResult = 0;                     \
248     if (IsMsgHandled())              \
249       return TRUE;                   \
250   }
251 
252 // HBRUSH OnCtlColorEdit(CDCHandle dc, CEdit edit)
253 #define CR_MSG_WM_CTLCOLOREDIT(func)                    \
254   if (uMsg == WM_CTLCOLOREDIT) {                        \
255     SetMsgHandled(TRUE);                                \
256     lResult = (LRESULT)func((HDC)wParam, (HWND)lParam); \
257     if (IsMsgHandled())                                 \
258       return TRUE;                                      \
259   }
260 
261 // HBRUSH OnCtlColorListBox(CDCHandle dc, CListBox listBox)
262 #define CR_MSG_WM_CTLCOLORLISTBOX(func)                 \
263   if (uMsg == WM_CTLCOLORLISTBOX) {                     \
264     SetMsgHandled(TRUE);                                \
265     lResult = (LRESULT)func((HDC)wParam, (HWND)lParam); \
266     if (IsMsgHandled())                                 \
267       return TRUE;                                      \
268   }
269 
270 // HBRUSH OnCtlColorBtn(CDCHandle dc, CButton button)
271 #define CR_MSG_WM_CTLCOLORBTN(func)                     \
272   if (uMsg == WM_CTLCOLORBTN) {                         \
273     SetMsgHandled(TRUE);                                \
274     lResult = (LRESULT)func((HDC)wParam, (HWND)lParam); \
275     if (IsMsgHandled())                                 \
276       return TRUE;                                      \
277   }
278 
279 // HBRUSH OnCtlColorDlg(CDCHandle dc, CWindow wnd)
280 #define CR_MSG_WM_CTLCOLORDLG(func)                     \
281   if (uMsg == WM_CTLCOLORDLG) {                         \
282     SetMsgHandled(TRUE);                                \
283     lResult = (LRESULT)func((HDC)wParam, (HWND)lParam); \
284     if (IsMsgHandled())                                 \
285       return TRUE;                                      \
286   }
287 
288 // HBRUSH OnCtlColorScrollBar(CDCHandle dc, CScrollBar scrollBar)
289 #define CR_MSG_WM_CTLCOLORSCROLLBAR(func)               \
290   if (uMsg == WM_CTLCOLORSCROLLBAR) {                   \
291     SetMsgHandled(TRUE);                                \
292     lResult = (LRESULT)func((HDC)wParam, (HWND)lParam); \
293     if (IsMsgHandled())                                 \
294       return TRUE;                                      \
295   }
296 
297 // HBRUSH OnCtlColorStatic(CDCHandle dc, CStatic wndStatic)
298 #define CR_MSG_WM_CTLCOLORSTATIC(func)                  \
299   if (uMsg == WM_CTLCOLORSTATIC) {                      \
300     SetMsgHandled(TRUE);                                \
301     lResult = (LRESULT)func((HDC)wParam, (HWND)lParam); \
302     if (IsMsgHandled())                                 \
303       return TRUE;                                      \
304   }
305 
306 // void OnSettingChange(UINT uFlags, LPCTSTR lpszSection)
307 #define CR_MSG_WM_SETTINGCHANGE(func)    \
308   if (uMsg == WM_SETTINGCHANGE) {        \
309     SetMsgHandled(TRUE);                 \
310     func((UINT)wParam, (LPCTSTR)lParam); \
311     lResult = 0;                         \
312     if (IsMsgHandled())                  \
313       return TRUE;                       \
314   }
315 
316 // void OnDevModeChange(LPCTSTR lpDeviceName)
317 #define CR_MSG_WM_DEVMODECHANGE(func) \
318   if (uMsg == WM_DEVMODECHANGE) {     \
319     SetMsgHandled(TRUE);              \
320     func((LPCTSTR)lParam);            \
321     lResult = 0;                      \
322     if (IsMsgHandled())               \
323       return TRUE;                    \
324   }
325 
326 // void OnActivateApp(BOOL bActive, DWORD dwThreadID)
327 #define CR_MSG_WM_ACTIVATEAPP(func)    \
328   if (uMsg == WM_ACTIVATEAPP) {        \
329     SetMsgHandled(TRUE);               \
330     func((BOOL)wParam, (DWORD)lParam); \
331     lResult = 0;                       \
332     if (IsMsgHandled())                \
333       return TRUE;                     \
334   }
335 
336 // void OnFontChange()
337 #define CR_MSG_WM_FONTCHANGE(func) \
338   if (uMsg == WM_FONTCHANGE) {     \
339     SetMsgHandled(TRUE);           \
340     func();                        \
341     lResult = 0;                   \
342     if (IsMsgHandled())            \
343       return TRUE;                 \
344   }
345 
346 // void OnTimeChange()
347 #define CR_MSG_WM_TIMECHANGE(func) \
348   if (uMsg == WM_TIMECHANGE) {     \
349     SetMsgHandled(TRUE);           \
350     func();                        \
351     lResult = 0;                   \
352     if (IsMsgHandled())            \
353       return TRUE;                 \
354   }
355 
356 // void OnCancelMode()
357 #define CR_MSG_WM_CANCELMODE(func) \
358   if (uMsg == WM_CANCELMODE) {     \
359     SetMsgHandled(TRUE);           \
360     func();                        \
361     lResult = 0;                   \
362     if (IsMsgHandled())            \
363       return TRUE;                 \
364   }
365 
366 // BOOL OnSetCursor(CWindow wnd, UINT nHitTest, UINT message)
367 #define CR_MSG_WM_SETCURSOR(func)                                  \
368   if (uMsg == WM_SETCURSOR) {                                      \
369     SetMsgHandled(TRUE);                                           \
370     lResult = (LRESULT)func(                                       \
371         (HWND)wParam, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam)); \
372     if (IsMsgHandled())                                            \
373       return TRUE;                                                 \
374   }
375 
376 // int OnMouseActivate(CWindow wndTopLevel, UINT nHitTest, UINT message)
377 #define CR_MSG_WM_MOUSEACTIVATE(func)                              \
378   if (uMsg == WM_MOUSEACTIVATE) {                                  \
379     SetMsgHandled(TRUE);                                           \
380     lResult = (LRESULT)func(                                       \
381         (HWND)wParam, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam)); \
382     if (IsMsgHandled())                                            \
383       return TRUE;                                                 \
384   }
385 
386 // void OnChildActivate()
387 #define CR_MSG_WM_CHILDACTIVATE(func) \
388   if (uMsg == WM_CHILDACTIVATE) {     \
389     SetMsgHandled(TRUE);              \
390     func();                           \
391     lResult = 0;                      \
392     if (IsMsgHandled())               \
393       return TRUE;                    \
394   }
395 
396 // void OnGetMinMaxInfo(LPMINMAXINFO lpMMI)
397 #define CR_MSG_WM_GETMINMAXINFO(func) \
398   if (uMsg == WM_GETMINMAXINFO) {     \
399     SetMsgHandled(TRUE);              \
400     func((LPMINMAXINFO)lParam);       \
401     lResult = 0;                      \
402     if (IsMsgHandled())               \
403       return TRUE;                    \
404   }
405 
406 // void OnIconEraseBkgnd(CDCHandle dc)
407 #define CR_MSG_WM_ICONERASEBKGND(func) \
408   if (uMsg == WM_ICONERASEBKGND) {     \
409     SetMsgHandled(TRUE);               \
410     func((HDC)wParam);                 \
411     lResult = 0;                       \
412     if (IsMsgHandled())                \
413       return TRUE;                     \
414   }
415 
416 // void OnSpoolerStatus(UINT nStatus, UINT nJobs)
417 #define CR_MSG_WM_SPOOLERSTATUS(func)         \
418   if (uMsg == WM_SPOOLERSTATUS) {             \
419     SetMsgHandled(TRUE);                      \
420     func((UINT)wParam, (UINT)LOWORD(lParam)); \
421     lResult = 0;                              \
422     if (IsMsgHandled())                       \
423       return TRUE;                            \
424   }
425 
426 // void OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
427 #define CR_MSG_WM_DRAWITEM(func)                  \
428   if (uMsg == WM_DRAWITEM) {                      \
429     SetMsgHandled(TRUE);                          \
430     func((UINT)wParam, (LPDRAWITEMSTRUCT)lParam); \
431     lResult = TRUE;                               \
432     if (IsMsgHandled())                           \
433       return TRUE;                                \
434   }
435 
436 // void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
437 #define CR_MSG_WM_MEASUREITEM(func)                  \
438   if (uMsg == WM_MEASUREITEM) {                      \
439     SetMsgHandled(TRUE);                             \
440     func((UINT)wParam, (LPMEASUREITEMSTRUCT)lParam); \
441     lResult = TRUE;                                  \
442     if (IsMsgHandled())                              \
443       return TRUE;                                   \
444   }
445 
446 // void OnDeleteItem(int nIDCtl, LPDELETEITEMSTRUCT lpDeleteItemStruct)
447 #define CR_MSG_WM_DELETEITEM(func)                  \
448   if (uMsg == WM_DELETEITEM) {                      \
449     SetMsgHandled(TRUE);                            \
450     func((UINT)wParam, (LPDELETEITEMSTRUCT)lParam); \
451     lResult = TRUE;                                 \
452     if (IsMsgHandled())                             \
453       return TRUE;                                  \
454   }
455 
456 // int OnCharToItem(UINT nChar, UINT nIndex, CListBox listBox)
457 #define CR_MSG_WM_CHARTOITEM(func)                                 \
458   if (uMsg == WM_CHARTOITEM) {                                     \
459     SetMsgHandled(TRUE);                                           \
460     lResult = (LRESULT)func(                                       \
461         (UINT)LOWORD(wParam), (UINT)HIWORD(wParam), (HWND)lParam); \
462     if (IsMsgHandled())                                            \
463       return TRUE;                                                 \
464   }
465 
466 // int OnVKeyToItem(UINT nKey, UINT nIndex, CListBox listBox)
467 #define CR_MSG_WM_VKEYTOITEM(func)                                 \
468   if (uMsg == WM_VKEYTOITEM) {                                     \
469     SetMsgHandled(TRUE);                                           \
470     lResult = (LRESULT)func(                                       \
471         (UINT)LOWORD(wParam), (UINT)HIWORD(wParam), (HWND)lParam); \
472     if (IsMsgHandled())                                            \
473       return TRUE;                                                 \
474   }
475 
476 // HCURSOR OnQueryDragIcon()
477 #define CR_MSG_WM_QUERYDRAGICON(func) \
478   if (uMsg == WM_QUERYDRAGICON) {     \
479     SetMsgHandled(TRUE);              \
480     lResult = (LRESULT)func();        \
481     if (IsMsgHandled())               \
482       return TRUE;                    \
483   }
484 
485 // int OnCompareItem(int nIDCtl, LPCOMPAREITEMSTRUCT lpCompareItemStruct)
486 #define CR_MSG_WM_COMPAREITEM(func)                                     \
487   if (uMsg == WM_COMPAREITEM) {                                         \
488     SetMsgHandled(TRUE);                                                \
489     lResult = (LRESULT)func((UINT)wParam, (LPCOMPAREITEMSTRUCT)lParam); \
490     if (IsMsgHandled())                                                 \
491       return TRUE;                                                      \
492   }
493 
494 // void OnCompacting(UINT nCpuTime)
495 #define CR_MSG_WM_COMPACTING(func) \
496   if (uMsg == WM_COMPACTING) {     \
497     SetMsgHandled(TRUE);           \
498     func((UINT)wParam);            \
499     lResult = 0;                   \
500     if (IsMsgHandled())            \
501       return TRUE;                 \
502   }
503 
504 // BOOL OnNcCreate(LPCREATESTRUCT lpCreateStruct)
505 #define CR_MSG_WM_NCCREATE(func)                     \
506   if (uMsg == WM_NCCREATE) {                         \
507     SetMsgHandled(TRUE);                             \
508     lResult = (LRESULT)func((LPCREATESTRUCT)lParam); \
509     if (IsMsgHandled())                              \
510       return TRUE;                                   \
511   }
512 
513 // void OnNcDestroy()
514 #define CR_MSG_WM_NCDESTROY(func) \
515   if (uMsg == WM_NCDESTROY) {     \
516     SetMsgHandled(TRUE);          \
517     func();                       \
518     lResult = 0;                  \
519     if (IsMsgHandled())           \
520       return TRUE;                \
521   }
522 
523 // LRESULT OnNcCalcSize(BOOL bCalcValidRects, LPARAM lParam)
524 #define CR_MSG_WM_NCCALCSIZE(func)        \
525   if (uMsg == WM_NCCALCSIZE) {            \
526     SetMsgHandled(TRUE);                  \
527     lResult = func((BOOL)wParam, lParam); \
528     if (IsMsgHandled())                   \
529       return TRUE;                        \
530   }
531 
532 // UINT OnNcHitTest(gfx::Point point)
533 #define CR_MSG_WM_NCHITTEST(func)                                      \
534   if (uMsg == WM_NCHITTEST) {                                          \
535     SetMsgHandled(TRUE);                                               \
536     lResult = (LRESULT)func(                                           \
537         gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
538     if (IsMsgHandled())                                                \
539       return TRUE;                                                     \
540   }
541 
542 // void OnNcPaint(CRgn rgn)
543 #define CR_MSG_WM_NCPAINT(func) \
544   if (uMsg == WM_NCPAINT) {     \
545     SetMsgHandled(TRUE);        \
546     func((HRGN)wParam);         \
547     lResult = 0;                \
548     if (IsMsgHandled())         \
549       return TRUE;              \
550   }
551 
552 // BOOL OnNcActivate(BOOL bActive)
553 #define CR_MSG_WM_NCACTIVATE(func)         \
554   if (uMsg == WM_NCACTIVATE) {             \
555     SetMsgHandled(TRUE);                   \
556     lResult = (LRESULT)func((BOOL)wParam); \
557     if (IsMsgHandled())                    \
558       return TRUE;                         \
559   }
560 
561 // UINT OnGetDlgCode(LPMSG lpMsg)
562 #define CR_MSG_WM_GETDLGCODE(func)          \
563   if (uMsg == WM_GETDLGCODE) {              \
564     SetMsgHandled(TRUE);                    \
565     lResult = (LRESULT)func((LPMSG)lParam); \
566     if (IsMsgHandled())                     \
567       return TRUE;                          \
568   }
569 
570 // void OnNcMouseMove(UINT nHitTest, gfx::Point point)
571 #define CR_MSG_WM_NCMOUSEMOVE(func)                                     \
572   if (uMsg == WM_NCMOUSEMOVE) {                                         \
573     SetMsgHandled(TRUE);                                                \
574     func((UINT)wParam,                                                  \
575          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
576     lResult = 0;                                                        \
577     if (IsMsgHandled())                                                 \
578       return TRUE;                                                      \
579   }
580 
581 // void OnNcLButtonDown(UINT nHitTest, gfx::Point point)
582 #define CR_MSG_WM_NCLBUTTONDOWN(func)                                   \
583   if (uMsg == WM_NCLBUTTONDOWN) {                                       \
584     SetMsgHandled(TRUE);                                                \
585     func((UINT)wParam,                                                  \
586          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
587     lResult = 0;                                                        \
588     if (IsMsgHandled())                                                 \
589       return TRUE;                                                      \
590   }
591 
592 // void OnNcLButtonUp(UINT nHitTest, gfx::Point point)
593 #define CR_MSG_WM_NCLBUTTONUP(func)                                     \
594   if (uMsg == WM_NCLBUTTONUP) {                                         \
595     SetMsgHandled(TRUE);                                                \
596     func((UINT)wParam,                                                  \
597          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
598     lResult = 0;                                                        \
599     if (IsMsgHandled())                                                 \
600       return TRUE;                                                      \
601   }
602 
603 // void OnNcLButtonDblClk(UINT nHitTest, gfx::Point point)
604 #define CR_MSG_WM_NCLBUTTONDBLCLK(func)                                 \
605   if (uMsg == WM_NCLBUTTONDBLCLK) {                                     \
606     SetMsgHandled(TRUE);                                                \
607     func((UINT)wParam,                                                  \
608          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
609     lResult = 0;                                                        \
610     if (IsMsgHandled())                                                 \
611       return TRUE;                                                      \
612   }
613 
614 // void OnNcRButtonDown(UINT nHitTest, gfx::Point point)
615 #define CR_MSG_WM_NCRBUTTONDOWN(func)                                   \
616   if (uMsg == WM_NCRBUTTONDOWN) {                                       \
617     SetMsgHandled(TRUE);                                                \
618     func((UINT)wParam,                                                  \
619          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
620     lResult = 0;                                                        \
621     if (IsMsgHandled())                                                 \
622       return TRUE;                                                      \
623   }
624 
625 // void OnNcRButtonUp(UINT nHitTest, gfx::Point point)
626 #define CR_MSG_WM_NCRBUTTONUP(func)                                     \
627   if (uMsg == WM_NCRBUTTONUP) {                                         \
628     SetMsgHandled(TRUE);                                                \
629     func((UINT)wParam,                                                  \
630          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
631     lResult = 0;                                                        \
632     if (IsMsgHandled())                                                 \
633       return TRUE;                                                      \
634   }
635 
636 // void OnNcRButtonDblClk(UINT nHitTest, CPoint point)
637 #define CR_MSG_WM_NCRBUTTONDBLCLK(func)                                 \
638   if (uMsg == WM_NCRBUTTONDBLCLK) {                                     \
639     SetMsgHandled(TRUE);                                                \
640     func((UINT)wParam,                                                  \
641          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
642     lResult = 0;                                                        \
643     if (IsMsgHandled())                                                 \
644       return TRUE;                                                      \
645   }
646 
647 // void OnNcMButtonDown(UINT nHitTest, CPoint point)
648 #define CR_MSG_WM_NCMBUTTONDOWN(func)                                   \
649   if (uMsg == WM_NCMBUTTONDOWN) {                                       \
650     SetMsgHandled(TRUE);                                                \
651     func((UINT)wParam,                                                  \
652          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
653     lResult = 0;                                                        \
654     if (IsMsgHandled())                                                 \
655       return TRUE;                                                      \
656   }
657 
658 // void OnNcMButtonUp(UINT nHitTest, CPoint point)
659 #define CR_MSG_WM_NCMBUTTONUP(func)                                     \
660   if (uMsg == WM_NCMBUTTONUP) {                                         \
661     SetMsgHandled(TRUE);                                                \
662     func((UINT)wParam,                                                  \
663          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
664     lResult = 0;                                                        \
665     if (IsMsgHandled())                                                 \
666       return TRUE;                                                      \
667   }
668 
669 // void OnNcMButtonDblClk(UINT nHitTest, CPoint point)
670 #define CR_MSG_WM_NCMBUTTONDBLCLK(func)                                 \
671   if (uMsg == WM_NCMBUTTONDBLCLK) {                                     \
672     SetMsgHandled(TRUE);                                                \
673     func((UINT)wParam,                                                  \
674          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
675     lResult = 0;                                                        \
676     if (IsMsgHandled())                                                 \
677       return TRUE;                                                      \
678   }
679 
680 // void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
681 #define CR_MSG_WM_KEYDOWN(func)                \
682   if (uMsg == WM_KEYDOWN) {                    \
683     SetMsgHandled(TRUE);                       \
684     func((TCHAR)wParam,                        \
685          (UINT)lParam & 0xFFFF,                \
686          (UINT)((lParam & 0xFFFF0000) >> 16)); \
687     lResult = 0;                               \
688     if (IsMsgHandled())                        \
689       return TRUE;                             \
690   }
691 
692 // void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
693 #define CR_MSG_WM_KEYUP(func)                  \
694   if (uMsg == WM_KEYUP) {                      \
695     SetMsgHandled(TRUE);                       \
696     func((TCHAR)wParam,                        \
697          (UINT)lParam & 0xFFFF,                \
698          (UINT)((lParam & 0xFFFF0000) >> 16)); \
699     lResult = 0;                               \
700     if (IsMsgHandled())                        \
701       return TRUE;                             \
702   }
703 
704 // void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
705 #define CR_MSG_WM_CHAR(func)                   \
706   if (uMsg == WM_CHAR) {                       \
707     SetMsgHandled(TRUE);                       \
708     func((TCHAR)wParam,                        \
709          (UINT)lParam & 0xFFFF,                \
710          (UINT)((lParam & 0xFFFF0000) >> 16)); \
711     lResult = 0;                               \
712     if (IsMsgHandled())                        \
713       return TRUE;                             \
714   }
715 
716 // void OnDeadChar(UINT nChar, UINT nRepCnt, UINT nFlags)
717 #define CR_MSG_WM_DEADCHAR(func)               \
718   if (uMsg == WM_DEADCHAR) {                   \
719     SetMsgHandled(TRUE);                       \
720     func((TCHAR)wParam,                        \
721          (UINT)lParam & 0xFFFF,                \
722          (UINT)((lParam & 0xFFFF0000) >> 16)); \
723     lResult = 0;                               \
724     if (IsMsgHandled())                        \
725       return TRUE;                             \
726   }
727 
728 // void OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
729 #define CR_MSG_WM_SYSKEYDOWN(func)             \
730   if (uMsg == WM_SYSKEYDOWN) {                 \
731     SetMsgHandled(TRUE);                       \
732     func((TCHAR)wParam,                        \
733          (UINT)lParam & 0xFFFF,                \
734          (UINT)((lParam & 0xFFFF0000) >> 16)); \
735     lResult = 0;                               \
736     if (IsMsgHandled())                        \
737       return TRUE;                             \
738   }
739 
740 // void OnSysKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
741 #define CR_MSG_WM_SYSKEYUP(func)               \
742   if (uMsg == WM_SYSKEYUP) {                   \
743     SetMsgHandled(TRUE);                       \
744     func((TCHAR)wParam,                        \
745          (UINT)lParam & 0xFFFF,                \
746          (UINT)((lParam & 0xFFFF0000) >> 16)); \
747     lResult = 0;                               \
748     if (IsMsgHandled())                        \
749       return TRUE;                             \
750   }
751 
752 // void OnSysChar(UINT nChar, UINT nRepCnt, UINT nFlags)
753 #define CR_MSG_WM_SYSCHAR(func)                \
754   if (uMsg == WM_SYSCHAR) {                    \
755     SetMsgHandled(TRUE);                       \
756     func((TCHAR)wParam,                        \
757          (UINT)lParam & 0xFFFF,                \
758          (UINT)((lParam & 0xFFFF0000) >> 16)); \
759     lResult = 0;                               \
760     if (IsMsgHandled())                        \
761       return TRUE;                             \
762   }
763 
764 // void OnSysDeadChar(UINT nChar, UINT nRepCnt, UINT nFlags)
765 #define CR_MSG_WM_SYSDEADCHAR(func)            \
766   if (uMsg == WM_SYSDEADCHAR) {                \
767     SetMsgHandled(TRUE);                       \
768     func((TCHAR)wParam,                        \
769          (UINT)lParam & 0xFFFF,                \
770          (UINT)((lParam & 0xFFFF0000) >> 16)); \
771     lResult = 0;                               \
772     if (IsMsgHandled())                        \
773       return TRUE;                             \
774   }
775 
776 // void OnSysCommand(UINT nID, LPARAM lParam)
777 #define CR_MSG_WM_SYSCOMMAND(func)                                      \
778   if (uMsg == WM_SYSCOMMAND) {                                          \
779     SetMsgHandled(TRUE);                                                \
780     func((UINT)wParam,                                                  \
781          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
782     lResult = 0;                                                        \
783     if (IsMsgHandled())                                                 \
784       return TRUE;                                                      \
785   }
786 
787 // void OnTCard(UINT idAction, DWORD dwActionData)
788 #define CR_MSG_WM_TCARD(func)          \
789   if (uMsg == WM_TCARD) {              \
790     SetMsgHandled(TRUE);               \
791     func((UINT)wParam, (DWORD)lParam); \
792     lResult = 0;                       \
793     if (IsMsgHandled())                \
794       return TRUE;                     \
795   }
796 
797 // void OnTimer(UINT_PTR nIDEvent)
798 #define CR_MSG_WM_TIMER(func) \
799   if (uMsg == WM_TIMER) {     \
800     SetMsgHandled(TRUE);      \
801     func((UINT_PTR)wParam);   \
802     lResult = 0;              \
803     if (IsMsgHandled())       \
804       return TRUE;            \
805   }
806 
807 // void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar pScrollBar)
808 #define CR_MSG_WM_HSCROLL(func)                                     \
809   if (uMsg == WM_HSCROLL) {                                         \
810     SetMsgHandled(TRUE);                                            \
811     func((int)LOWORD(wParam), (short)HIWORD(wParam), (HWND)lParam); \
812     lResult = 0;                                                    \
813     if (IsMsgHandled())                                             \
814       return TRUE;                                                  \
815   }
816 
817 // void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar pScrollBar)
818 #define CR_MSG_WM_VSCROLL(func)                                     \
819   if (uMsg == WM_VSCROLL) {                                         \
820     SetMsgHandled(TRUE);                                            \
821     func((int)LOWORD(wParam), (short)HIWORD(wParam), (HWND)lParam); \
822     lResult = 0;                                                    \
823     if (IsMsgHandled())                                             \
824       return TRUE;                                                  \
825   }
826 
827 // void OnInitMenu(CMenu menu)
828 #define CR_MSG_WM_INITMENU(func) \
829   if (uMsg == WM_INITMENU) {     \
830     SetMsgHandled(TRUE);         \
831     func((HMENU)wParam);         \
832     lResult = 0;                 \
833     if (IsMsgHandled())          \
834       return TRUE;               \
835   }
836 
837 // void OnInitMenuPopup(CMenu menuPopup, UINT nIndex, BOOL bSysMenu)
838 #define CR_MSG_WM_INITMENUPOPUP(func)                                \
839   if (uMsg == WM_INITMENUPOPUP) {                                    \
840     SetMsgHandled(TRUE);                                             \
841     func((HMENU)wParam, (UINT)LOWORD(lParam), (BOOL)HIWORD(lParam)); \
842     lResult = 0;                                                     \
843     if (IsMsgHandled())                                              \
844       return TRUE;                                                   \
845   }
846 
847 // void OnMenuSelect(UINT nItemID, UINT nFlags, CMenu menu)
848 #define CR_MSG_WM_MENUSELECT(func)                                   \
849   if (uMsg == WM_MENUSELECT) {                                       \
850     SetMsgHandled(TRUE);                                             \
851     func((UINT)LOWORD(wParam), (UINT)HIWORD(wParam), (HMENU)lParam); \
852     lResult = 0;                                                     \
853     if (IsMsgHandled())                                              \
854       return TRUE;                                                   \
855   }
856 
857 // LRESULT OnMenuChar(UINT nChar, UINT nFlags, CMenu menu)
858 #define CR_MSG_WM_MENUCHAR(func)                                          \
859   if (uMsg == WM_MENUCHAR) {                                              \
860     SetMsgHandled(TRUE);                                                  \
861     lResult =                                                             \
862         func((TCHAR)LOWORD(wParam), (UINT)HIWORD(wParam), (HMENU)lParam); \
863     if (IsMsgHandled())                                                   \
864       return TRUE;                                                        \
865   }
866 
867 // LRESULT OnNotify(int idCtrl, LPNMHDR pnmh)
868 #define CR_MSG_WM_NOTIFY(func)                    \
869   if (uMsg == WM_NOTIFY) {                        \
870     SetMsgHandled(TRUE);                          \
871     lResult = func((int)wParam, (LPNMHDR)lParam); \
872     if (IsMsgHandled())                           \
873       return TRUE;                                \
874   }
875 
876 // void OnEnterIdle(UINT nWhy, CWindow wndWho)
877 #define CR_MSG_WM_ENTERIDLE(func)     \
878   if (uMsg == WM_ENTERIDLE) {         \
879     SetMsgHandled(TRUE);              \
880     func((UINT)wParam, (HWND)lParam); \
881     lResult = 0;                      \
882     if (IsMsgHandled())               \
883       return TRUE;                    \
884   }
885 
886 // void OnMouseMove(UINT nFlags, CPoint point)
887 #define CR_MSG_WM_MOUSEMOVE(func)                                       \
888   if (uMsg == WM_MOUSEMOVE) {                                           \
889     SetMsgHandled(TRUE);                                                \
890     func((UINT)wParam,                                                  \
891          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
892     lResult = 0;                                                        \
893     if (IsMsgHandled())                                                 \
894       return TRUE;                                                      \
895   }
896 
897 // BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
898 #define CR_MSG_WM_MOUSEWHEEL(func)                                     \
899   if (uMsg == WM_MOUSEWHEEL) {                                         \
900     SetMsgHandled(TRUE);                                               \
901     lResult = (LRESULT)func(                                           \
902         (UINT)LOWORD(wParam),                                          \
903         (short)HIWORD(wParam),                                         \
904         gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
905     if (IsMsgHandled())                                                \
906       return TRUE;                                                     \
907   }
908 
909 // void OnLButtonDown(UINT nFlags, CPoint point)
910 #define CR_MSG_WM_LBUTTONDOWN(func)                                     \
911   if (uMsg == WM_LBUTTONDOWN) {                                         \
912     SetMsgHandled(TRUE);                                                \
913     func((UINT)wParam,                                                  \
914          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
915     lResult = 0;                                                        \
916     if (IsMsgHandled())                                                 \
917       return TRUE;                                                      \
918   }
919 
920 // void OnLButtonUp(UINT nFlags, CPoint point)
921 #define CR_MSG_WM_LBUTTONUP(func)                                       \
922   if (uMsg == WM_LBUTTONUP) {                                           \
923     SetMsgHandled(TRUE);                                                \
924     func((UINT)wParam,                                                  \
925          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
926     lResult = 0;                                                        \
927     if (IsMsgHandled())                                                 \
928       return TRUE;                                                      \
929   }
930 
931 // void OnLButtonDblClk(UINT nFlags, CPoint point)
932 #define CR_MSG_WM_LBUTTONDBLCLK(func)                                   \
933   if (uMsg == WM_LBUTTONDBLCLK) {                                       \
934     SetMsgHandled(TRUE);                                                \
935     func((UINT)wParam,                                                  \
936          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
937     lResult = 0;                                                        \
938     if (IsMsgHandled())                                                 \
939       return TRUE;                                                      \
940   }
941 
942 // void OnRButtonDown(UINT nFlags, CPoint point)
943 #define CR_MSG_WM_RBUTTONDOWN(func)                                     \
944   if (uMsg == WM_RBUTTONDOWN) {                                         \
945     SetMsgHandled(TRUE);                                                \
946     func((UINT)wParam,                                                  \
947          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
948     lResult = 0;                                                        \
949     if (IsMsgHandled())                                                 \
950       return TRUE;                                                      \
951   }
952 
953 // void OnRButtonUp(UINT nFlags, CPoint point)
954 #define CR_MSG_WM_RBUTTONUP(func)                                       \
955   if (uMsg == WM_RBUTTONUP) {                                           \
956     SetMsgHandled(TRUE);                                                \
957     func((UINT)wParam,                                                  \
958          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
959     lResult = 0;                                                        \
960     if (IsMsgHandled())                                                 \
961       return TRUE;                                                      \
962   }
963 
964 // void OnRButtonDblClk(UINT nFlags, CPoint point)
965 #define CR_MSG_WM_RBUTTONDBLCLK(func)                                   \
966   if (uMsg == WM_RBUTTONDBLCLK) {                                       \
967     SetMsgHandled(TRUE);                                                \
968     func((UINT)wParam,                                                  \
969          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
970     lResult = 0;                                                        \
971     if (IsMsgHandled())                                                 \
972       return TRUE;                                                      \
973   }
974 
975 // void OnMButtonDown(UINT nFlags, CPoint point)
976 #define CR_MSG_WM_MBUTTONDOWN(func)                                     \
977   if (uMsg == WM_MBUTTONDOWN) {                                         \
978     SetMsgHandled(TRUE);                                                \
979     func((UINT)wParam,                                                  \
980          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
981     lResult = 0;                                                        \
982     if (IsMsgHandled())                                                 \
983       return TRUE;                                                      \
984   }
985 
986 // void OnMButtonUp(UINT nFlags, CPoint point)
987 #define CR_MSG_WM_MBUTTONUP(func)                                       \
988   if (uMsg == WM_MBUTTONUP) {                                           \
989     SetMsgHandled(TRUE);                                                \
990     func((UINT)wParam,                                                  \
991          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
992     lResult = 0;                                                        \
993     if (IsMsgHandled())                                                 \
994       return TRUE;                                                      \
995   }
996 
997 // void OnMButtonDblClk(UINT nFlags, CPoint point)
998 #define CR_MSG_WM_MBUTTONDBLCLK(func)                                   \
999   if (uMsg == WM_MBUTTONDBLCLK) {                                       \
1000     SetMsgHandled(TRUE);                                                \
1001     func((UINT)wParam,                                                  \
1002          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
1003     lResult = 0;                                                        \
1004     if (IsMsgHandled())                                                 \
1005       return TRUE;                                                      \
1006   }
1007 
1008 // void OnParentNotify(UINT message, UINT nChildID, LPARAM lParam)
1009 #define CR_MSG_WM_PARENTNOTIFY(func)                          \
1010   if (uMsg == WM_PARENTNOTIFY) {                              \
1011     SetMsgHandled(TRUE);                                      \
1012     func((UINT)LOWORD(wParam), (UINT)HIWORD(wParam), lParam); \
1013     lResult = 0;                                              \
1014     if (IsMsgHandled())                                       \
1015       return TRUE;                                            \
1016   }
1017 
1018 // void OnMDIActivate(CWindow wndActivate, CWindow wndDeactivate)
1019 #define CR_MSG_WM_MDIACTIVATE(func)   \
1020   if (uMsg == WM_MDIACTIVATE) {       \
1021     SetMsgHandled(TRUE);              \
1022     func((HWND)wParam, (HWND)lParam); \
1023     lResult = 0;                      \
1024     if (IsMsgHandled())               \
1025       return TRUE;                    \
1026   }
1027 
1028 // void OnRenderFormat(UINT nFormat)
1029 #define CR_MSG_WM_RENDERFORMAT(func) \
1030   if (uMsg == WM_RENDERFORMAT) {     \
1031     SetMsgHandled(TRUE);             \
1032     func((UINT)wParam);              \
1033     lResult = 0;                     \
1034     if (IsMsgHandled())              \
1035       return TRUE;                   \
1036   }
1037 
1038 // void OnRenderAllFormats()
1039 #define CR_MSG_WM_RENDERALLFORMATS(func) \
1040   if (uMsg == WM_RENDERALLFORMATS) {     \
1041     SetMsgHandled(TRUE);                 \
1042     func();                              \
1043     lResult = 0;                         \
1044     if (IsMsgHandled())                  \
1045       return TRUE;                       \
1046   }
1047 
1048 // void OnDestroyClipboard()
1049 #define CR_MSG_WM_DESTROYCLIPBOARD(func) \
1050   if (uMsg == WM_DESTROYCLIPBOARD) {     \
1051     SetMsgHandled(TRUE);                 \
1052     func();                              \
1053     lResult = 0;                         \
1054     if (IsMsgHandled())                  \
1055       return TRUE;                       \
1056   }
1057 
1058 // void OnDrawClipboard()
1059 #define CR_MSG_WM_DRAWCLIPBOARD(func) \
1060   if (uMsg == WM_DRAWCLIPBOARD) {     \
1061     SetMsgHandled(TRUE);              \
1062     func();                           \
1063     lResult = 0;                      \
1064     if (IsMsgHandled())               \
1065       return TRUE;                    \
1066   }
1067 
1068 // void OnPaintClipboard(CWindow wndViewer, const LPPAINTSTRUCT lpPaintStruct)
1069 #define CR_MSG_WM_PAINTCLIPBOARD(func)                                      \
1070   if (uMsg == WM_PAINTCLIPBOARD) {                                          \
1071     SetMsgHandled(TRUE);                                                    \
1072     func((HWND)wParam, (const LPPAINTSTRUCT)::GlobalLock((HGLOBAL)lParam)); \
1073     ::GlobalUnlock((HGLOBAL)lParam);                                        \
1074     lResult = 0;                                                            \
1075     if (IsMsgHandled())                                                     \
1076       return TRUE;                                                          \
1077   }
1078 
1079 // void OnVScrollClipboard(CWindow wndViewer, UINT nSBCode, UINT nPos)
1080 #define CR_MSG_WM_VSCROLLCLIPBOARD(func)                            \
1081   if (uMsg == WM_VSCROLLCLIPBOARD) {                                \
1082     SetMsgHandled(TRUE);                                            \
1083     func((HWND)wParam, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam)); \
1084     lResult = 0;                                                    \
1085     if (IsMsgHandled())                                             \
1086       return TRUE;                                                  \
1087   }
1088 
1089 // void OnContextMenu(CWindow wnd, CPoint point)
1090 #define CR_MSG_WM_CONTEXTMENU(func)                                     \
1091   if (uMsg == WM_CONTEXTMENU) {                                         \
1092     SetMsgHandled(TRUE);                                                \
1093     func((HWND)wParam,                                                  \
1094          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
1095     lResult = 0;                                                        \
1096     if (IsMsgHandled())                                                 \
1097       return TRUE;                                                      \
1098   }
1099 
1100 // void OnSizeClipboard(CWindow wndViewer, const LPRECT lpRect)
1101 #define CR_MSG_WM_SIZECLIPBOARD(func)                                \
1102   if (uMsg == WM_SIZECLIPBOARD) {                                    \
1103     SetMsgHandled(TRUE);                                             \
1104     func((HWND)wParam, (const LPRECT)::GlobalLock((HGLOBAL)lParam)); \
1105     ::GlobalUnlock((HGLOBAL)lParam);                                 \
1106     lResult = 0;                                                     \
1107     if (IsMsgHandled())                                              \
1108       return TRUE;                                                   \
1109   }
1110 
1111 // void OnAskCbFormatName(UINT nMaxCount, LPTSTR lpszString)
1112 #define CR_MSG_WM_ASKCBFORMATNAME(func)  \
1113   if (uMsg == WM_ASKCBFORMATNAME) {      \
1114     SetMsgHandled(TRUE);                 \
1115     func((DWORD)wParam, (LPTSTR)lParam); \
1116     lResult = 0;                         \
1117     if (IsMsgHandled())                  \
1118       return TRUE;                       \
1119   }
1120 
1121 // void OnChangeCbChain(CWindow wndRemove, CWindow wndAfter)
1122 #define CR_MSG_WM_CHANGECBCHAIN(func) \
1123   if (uMsg == WM_CHANGECBCHAIN) {     \
1124     SetMsgHandled(TRUE);              \
1125     func((HWND)wParam, (HWND)lParam); \
1126     lResult = 0;                      \
1127     if (IsMsgHandled())               \
1128       return TRUE;                    \
1129   }
1130 
1131 // void OnHScrollClipboard(CWindow wndViewer, UINT nSBCode, UINT nPos)
1132 #define CR_MSG_WM_HSCROLLCLIPBOARD(func)                            \
1133   if (uMsg == WM_HSCROLLCLIPBOARD) {                                \
1134     SetMsgHandled(TRUE);                                            \
1135     func((HWND)wParam, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam)); \
1136     lResult = 0;                                                    \
1137     if (IsMsgHandled())                                             \
1138       return TRUE;                                                  \
1139   }
1140 
1141 // BOOL OnQueryNewPalette()
1142 #define CR_MSG_WM_QUERYNEWPALETTE(func) \
1143   if (uMsg == WM_QUERYNEWPALETTE) {     \
1144     SetMsgHandled(TRUE);                \
1145     lResult = (LRESULT)func();          \
1146     if (IsMsgHandled())                 \
1147       return TRUE;                      \
1148   }
1149 
1150 // void OnPaletteChanged(CWindow wndFocus)
1151 #define CR_MSG_WM_PALETTECHANGED(func) \
1152   if (uMsg == WM_PALETTECHANGED) {     \
1153     SetMsgHandled(TRUE);               \
1154     func((HWND)wParam);                \
1155     lResult = 0;                       \
1156     if (IsMsgHandled())                \
1157       return TRUE;                     \
1158   }
1159 
1160 // void OnPaletteIsChanging(CWindow wndPalChg)
1161 #define CR_MSG_WM_PALETTEISCHANGING(func) \
1162   if (uMsg == WM_PALETTEISCHANGING) {     \
1163     SetMsgHandled(TRUE);                  \
1164     func((HWND)wParam);                   \
1165     lResult = 0;                          \
1166     if (IsMsgHandled())                   \
1167       return TRUE;                        \
1168   }
1169 
1170 // void OnDropFiles(HDROP hDropInfo)
1171 #define CR_MSG_WM_DROPFILES(func) \
1172   if (uMsg == WM_DROPFILES) {     \
1173     SetMsgHandled(TRUE);          \
1174     func((HDROP)wParam);          \
1175     lResult = 0;                  \
1176     if (IsMsgHandled())           \
1177       return TRUE;                \
1178   }
1179 
1180 // void OnWindowPosChanging(LPWINDOWPOS lpWndPos)
1181 #define CR_MSG_WM_WINDOWPOSCHANGING(func) \
1182   if (uMsg == WM_WINDOWPOSCHANGING) {     \
1183     SetMsgHandled(TRUE);                  \
1184     func((LPWINDOWPOS)lParam);            \
1185     lResult = 0;                          \
1186     if (IsMsgHandled())                   \
1187       return TRUE;                        \
1188   }
1189 
1190 // void OnWindowPosChanged(LPWINDOWPOS lpWndPos)
1191 #define CR_MSG_WM_WINDOWPOSCHANGED(func) \
1192   if (uMsg == WM_WINDOWPOSCHANGED) {     \
1193     SetMsgHandled(TRUE);                 \
1194     func((LPWINDOWPOS)lParam);           \
1195     lResult = 0;                         \
1196     if (IsMsgHandled())                  \
1197       return TRUE;                       \
1198   }
1199 
1200 // void OnExitMenuLoop(BOOL fIsTrackPopupMenu)
1201 #define CR_MSG_WM_EXITMENULOOP(func) \
1202   if (uMsg == WM_EXITMENULOOP) {     \
1203     SetMsgHandled(TRUE);             \
1204     func((BOOL)wParam);              \
1205     lResult = 0;                     \
1206     if (IsMsgHandled())              \
1207       return TRUE;                   \
1208   }
1209 
1210 // void OnEnterMenuLoop(BOOL fIsTrackPopupMenu)
1211 #define CR_MSG_WM_ENTERMENULOOP(func) \
1212   if (uMsg == WM_ENTERMENULOOP) {     \
1213     SetMsgHandled(TRUE);              \
1214     func((BOOL)wParam);               \
1215     lResult = 0;                      \
1216     if (IsMsgHandled())               \
1217       return TRUE;                    \
1218   }
1219 
1220 // void OnStyleChanged(int nStyleType, LPSTYLESTRUCT lpStyleStruct)
1221 #define CR_MSG_WM_STYLECHANGED(func)           \
1222   if (uMsg == WM_STYLECHANGED) {               \
1223     SetMsgHandled(TRUE);                       \
1224     func((UINT)wParam, (LPSTYLESTRUCT)lParam); \
1225     lResult = 0;                               \
1226     if (IsMsgHandled())                        \
1227       return TRUE;                             \
1228   }
1229 
1230 // void OnStyleChanging(int nStyleType, LPSTYLESTRUCT lpStyleStruct)
1231 #define CR_MSG_WM_STYLECHANGING(func)          \
1232   if (uMsg == WM_STYLECHANGING) {              \
1233     SetMsgHandled(TRUE);                       \
1234     func((UINT)wParam, (LPSTYLESTRUCT)lParam); \
1235     lResult = 0;                               \
1236     if (IsMsgHandled())                        \
1237       return TRUE;                             \
1238   }
1239 
1240 // void OnSizing(UINT fwSide, LPRECT pRect)
1241 #define CR_MSG_WM_SIZING(func)          \
1242   if (uMsg == WM_SIZING) {              \
1243     SetMsgHandled(TRUE);                \
1244     func((UINT)wParam, (LPRECT)lParam); \
1245     lResult = TRUE;                     \
1246     if (IsMsgHandled())                 \
1247       return TRUE;                      \
1248   }
1249 
1250 // void OnMoving(UINT fwSide, LPRECT pRect)
1251 #define CR_MSG_WM_MOVING(func)          \
1252   if (uMsg == WM_MOVING) {              \
1253     SetMsgHandled(TRUE);                \
1254     func((UINT)wParam, (LPRECT)lParam); \
1255     lResult = TRUE;                     \
1256     if (IsMsgHandled())                 \
1257       return TRUE;                      \
1258   }
1259 
1260 // void OnCaptureChanged(CWindow wnd)
1261 #define CR_MSG_WM_CAPTURECHANGED(func) \
1262   if (uMsg == WM_CAPTURECHANGED) {     \
1263     SetMsgHandled(TRUE);               \
1264     func((HWND)lParam);                \
1265     lResult = 0;                       \
1266     if (IsMsgHandled())                \
1267       return TRUE;                     \
1268   }
1269 
1270 // BOOL OnDeviceChange(UINT nEventType, DWORD dwData)
1271 #define CR_MSG_WM_DEVICECHANGE(func)                      \
1272   if (uMsg == WM_DEVICECHANGE) {                          \
1273     SetMsgHandled(TRUE);                                  \
1274     lResult = (LRESULT)func((UINT)wParam, (DWORD)lParam); \
1275     if (IsMsgHandled())                                   \
1276       return TRUE;                                        \
1277   }
1278 
1279 // void OnCommand(UINT uNotifyCode, int nID, CWindow wndCtl)
1280 #define CR_MSG_WM_COMMAND(func)                                    \
1281   if (uMsg == WM_COMMAND) {                                        \
1282     SetMsgHandled(TRUE);                                           \
1283     func((UINT)HIWORD(wParam), (int)LOWORD(wParam), (HWND)lParam); \
1284     lResult = 0;                                                   \
1285     if (IsMsgHandled())                                            \
1286       return TRUE;                                                 \
1287   }
1288 
1289 // void OnDisplayChange(UINT uBitsPerPixel, gfx::Size sizeScreen)
1290 #define CR_MSG_WM_DISPLAYCHANGE(func)                                  \
1291   if (uMsg == WM_DISPLAYCHANGE) {                                      \
1292     SetMsgHandled(TRUE);                                               \
1293     func((UINT)wParam,                                                 \
1294          gfx::Size(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
1295     lResult = 0;                                                       \
1296     if (IsMsgHandled())                                                \
1297       return TRUE;                                                     \
1298   }
1299 
1300 // void OnEnterSizeMove()
1301 #define CR_MSG_WM_ENTERSIZEMOVE(func) \
1302   if (uMsg == WM_ENTERSIZEMOVE) {     \
1303     SetMsgHandled(TRUE);              \
1304     func();                           \
1305     lResult = 0;                      \
1306     if (IsMsgHandled())               \
1307       return TRUE;                    \
1308   }
1309 
1310 // void OnExitSizeMove()
1311 #define CR_MSG_WM_EXITSIZEMOVE(func) \
1312   if (uMsg == WM_EXITSIZEMOVE) {     \
1313     SetMsgHandled(TRUE);             \
1314     func();                          \
1315     lResult = 0;                     \
1316     if (IsMsgHandled())              \
1317       return TRUE;                   \
1318   }
1319 
1320 // HFONT OnGetFont()
1321 #define CR_MSG_WM_GETFONT(func) \
1322   if (uMsg == WM_GETFONT) {     \
1323     SetMsgHandled(TRUE);        \
1324     lResult = (LRESULT)func();  \
1325     if (IsMsgHandled())         \
1326       return TRUE;              \
1327   }
1328 
1329 // LRESULT OnGetHotKey()
1330 #define CR_MSG_WM_GETHOTKEY(func) \
1331   if (uMsg == WM_GETHOTKEY) {     \
1332     SetMsgHandled(TRUE);          \
1333     lResult = func();             \
1334     if (IsMsgHandled())           \
1335       return TRUE;                \
1336   }
1337 
1338 // HICON OnGetIcon()
1339 #define CR_MSG_WM_GETICON(func)            \
1340   if (uMsg == WM_GETICON) {                \
1341     SetMsgHandled(TRUE);                   \
1342     lResult = (LRESULT)func((UINT)wParam); \
1343     if (IsMsgHandled())                    \
1344       return TRUE;                         \
1345   }
1346 
1347 // int OnGetText(int cchTextMax, LPTSTR lpszText)
1348 #define CR_MSG_WM_GETTEXT(func)                           \
1349   if (uMsg == WM_GETTEXT) {                               \
1350     SetMsgHandled(TRUE);                                  \
1351     lResult = (LRESULT)func((int)wParam, (LPTSTR)lParam); \
1352     if (IsMsgHandled())                                   \
1353       return TRUE;                                        \
1354   }
1355 
1356 // int OnGetTextLength()
1357 #define CR_MSG_WM_GETTEXTLENGTH(func) \
1358   if (uMsg == WM_GETTEXTLENGTH) {     \
1359     SetMsgHandled(TRUE);              \
1360     lResult = (LRESULT)func();        \
1361     if (IsMsgHandled())               \
1362       return TRUE;                    \
1363   }
1364 
1365 // void OnHelp(LPHELPINFO lpHelpInfo)
1366 #define CR_MSG_WM_HELP(func)  \
1367   if (uMsg == WM_HELP) {      \
1368     SetMsgHandled(TRUE);      \
1369     func((LPHELPINFO)lParam); \
1370     lResult = TRUE;           \
1371     if (IsMsgHandled())       \
1372       return TRUE;            \
1373   }
1374 
1375 // void OnHotKey(int nHotKeyID, UINT uModifiers, UINT uVirtKey)
1376 #define CR_MSG_WM_HOTKEY(func)                                     \
1377   if (uMsg == WM_HOTKEY) {                                         \
1378     SetMsgHandled(TRUE);                                           \
1379     func((int)wParam, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam)); \
1380     lResult = 0;                                                   \
1381     if (IsMsgHandled())                                            \
1382       return TRUE;                                                 \
1383   }
1384 
1385 // void OnInputLangChange(DWORD dwCharSet, HKL hKbdLayout)
1386 #define CR_MSG_WM_INPUTLANGCHANGE(func) \
1387   if (uMsg == WM_INPUTLANGCHANGE) {     \
1388     SetMsgHandled(TRUE);                \
1389     func((DWORD)wParam, (HKL)lParam);   \
1390     lResult = TRUE;                     \
1391     if (IsMsgHandled())                 \
1392       return TRUE;                      \
1393   }
1394 
1395 // void OnInputLangChangeRequest(BOOL bSysCharSet, HKL hKbdLayout)
1396 #define CR_MSG_WM_INPUTLANGCHANGEREQUEST(func) \
1397   if (uMsg == WM_INPUTLANGCHANGEREQUEST) {     \
1398     SetMsgHandled(TRUE);                       \
1399     func((BOOL)wParam, (HKL)lParam);           \
1400     lResult = 0;                               \
1401     if (IsMsgHandled())                        \
1402       return TRUE;                             \
1403   }
1404 
1405 // void OnNextDlgCtl(BOOL bHandle, WPARAM wCtlFocus)
1406 #define CR_MSG_WM_NEXTDLGCTL(func)      \
1407   if (uMsg == WM_NEXTDLGCTL) {          \
1408     SetMsgHandled(TRUE);                \
1409     func((BOOL)LOWORD(lParam), wParam); \
1410     lResult = 0;                        \
1411     if (IsMsgHandled())                 \
1412       return TRUE;                      \
1413   }
1414 
1415 // void OnNextMenu(int nVirtKey, LPMDINEXTMENU lpMdiNextMenu)
1416 #define CR_MSG_WM_NEXTMENU(func)              \
1417   if (uMsg == WM_NEXTMENU) {                  \
1418     SetMsgHandled(TRUE);                      \
1419     func((int)wParam, (LPMDINEXTMENU)lParam); \
1420     lResult = 0;                              \
1421     if (IsMsgHandled())                       \
1422       return TRUE;                            \
1423   }
1424 
1425 // int OnNotifyFormat(CWindow wndFrom, int nCommand)
1426 #define CR_MSG_WM_NOTIFYFORMAT(func)                    \
1427   if (uMsg == WM_NOTIFYFORMAT) {                        \
1428     SetMsgHandled(TRUE);                                \
1429     lResult = (LRESULT)func((HWND)wParam, (int)lParam); \
1430     if (IsMsgHandled())                                 \
1431       return TRUE;                                      \
1432   }
1433 
1434 // BOOL OnPowerBroadcast(DWORD dwPowerEvent, DWORD dwData)
1435 #define CR_MSG_WM_POWERBROADCAST(func)                     \
1436   if (uMsg == WM_POWERBROADCAST) {                         \
1437     SetMsgHandled(TRUE);                                   \
1438     lResult = (LRESULT)func((DWORD)wParam, (DWORD)lParam); \
1439     if (IsMsgHandled())                                    \
1440       return TRUE;                                         \
1441   }
1442 
1443 // void OnPrint(CDCHandle dc, UINT uFlags)
1444 #define CR_MSG_WM_PRINT(func)        \
1445   if (uMsg == WM_PRINT) {            \
1446     SetMsgHandled(TRUE);             \
1447     func((HDC)wParam, (UINT)lParam); \
1448     lResult = 0;                     \
1449     if (IsMsgHandled())              \
1450       return TRUE;                   \
1451   }
1452 
1453 // void OnPrintClient(CDCHandle dc, UINT uFlags)
1454 #define CR_MSG_WM_PRINTCLIENT(func)  \
1455   if (uMsg == WM_PRINTCLIENT) {      \
1456     SetMsgHandled(TRUE);             \
1457     func((HDC)wParam, (UINT)lParam); \
1458     lResult = 0;                     \
1459     if (IsMsgHandled())              \
1460       return TRUE;                   \
1461   }
1462 
1463 // void OnRasDialEvent(RASCONNSTATE rasconnstate, DWORD dwError)
1464 #define CR_MSG_WM_RASDIALEVENT(func)           \
1465   if (uMsg == WM_RASDIALEVENT) {               \
1466     SetMsgHandled(TRUE);                       \
1467     func((RASCONNSTATE)wParam, (DWORD)lParam); \
1468     lResult = TRUE;                            \
1469     if (IsMsgHandled())                        \
1470       return TRUE;                             \
1471   }
1472 
1473 // void OnSetFont(CFont font, BOOL bRedraw)
1474 #define CR_MSG_WM_SETFONT(func)                \
1475   if (uMsg == WM_SETFONT) {                    \
1476     SetMsgHandled(TRUE);                       \
1477     func((HFONT)wParam, (BOOL)LOWORD(lParam)); \
1478     lResult = 0;                               \
1479     if (IsMsgHandled())                        \
1480       return TRUE;                             \
1481   }
1482 
1483 // int OnSetHotKey(int nVirtKey, UINT uFlags)
1484 #define CR_MSG_WM_SETHOTKEY(func)                          \
1485   if (uMsg == WM_SETHOTKEY) {                              \
1486     SetMsgHandled(TRUE);                                   \
1487     lResult = (LRESULT)func((int)LOBYTE(LOWORD(wParam)),   \
1488                             (UINT)HIBYTE(LOWORD(wParam))); \
1489     if (IsMsgHandled())                                    \
1490       return TRUE;                                         \
1491   }
1492 
1493 // HICON OnSetIcon(UINT uType, HICON hIcon)
1494 #define CR_MSG_WM_SETICON(func)                           \
1495   if (uMsg == WM_SETICON) {                               \
1496     SetMsgHandled(TRUE);                                  \
1497     lResult = (LRESULT)func((UINT)wParam, (HICON)lParam); \
1498     if (IsMsgHandled())                                   \
1499       return TRUE;                                        \
1500   }
1501 
1502 // void OnSetRedraw(BOOL bRedraw)
1503 #define CR_MSG_WM_SETREDRAW(func) \
1504   if (uMsg == WM_SETREDRAW) {     \
1505     SetMsgHandled(TRUE);          \
1506     func((BOOL)wParam);           \
1507     lResult = 0;                  \
1508     if (IsMsgHandled())           \
1509       return TRUE;                \
1510   }
1511 
1512 // int OnSetText(LPCTSTR lpstrText)
1513 #define CR_MSG_WM_SETTEXT(func)               \
1514   if (uMsg == WM_SETTEXT) {                   \
1515     SetMsgHandled(TRUE);                      \
1516     lResult = (LRESULT)func((LPCTSTR)lParam); \
1517     if (IsMsgHandled())                       \
1518       return TRUE;                            \
1519   }
1520 
1521 // void OnUserChanged()
1522 #define CR_MSG_WM_USERCHANGED(func) \
1523   if (uMsg == WM_USERCHANGED) {     \
1524     SetMsgHandled(TRUE);            \
1525     func();                         \
1526     lResult = 0;                    \
1527     if (IsMsgHandled())             \
1528       return TRUE;                  \
1529   }
1530 
1531 ///////////////////////////////////////////////////////////////////////////////
1532 // New NT4 & NT5 messages
1533 
1534 #if (_WIN32_WINNT >= 0x0400)
1535 
1536 // void OnMouseHover(WPARAM wParam, CPoint ptPos)
1537 #define CR_MSG_WM_MOUSEHOVER(func)                                      \
1538   if (uMsg == WM_MOUSEHOVER) {                                          \
1539     SetMsgHandled(TRUE);                                                \
1540     func(wParam,                                                        \
1541          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
1542     lResult = 0;                                                        \
1543     if (IsMsgHandled())                                                 \
1544       return TRUE;                                                      \
1545   }
1546 
1547 // void OnMouseLeave()
1548 #define CR_MSG_WM_MOUSELEAVE(func) \
1549   if (uMsg == WM_MOUSELEAVE) {     \
1550     SetMsgHandled(TRUE);           \
1551     func();                        \
1552     lResult = 0;                   \
1553     if (IsMsgHandled())            \
1554       return TRUE;                 \
1555   }
1556 
1557 #endif /* _WIN32_WINNT >= 0x0400 */
1558 
1559 #if (WINVER >= 0x0500)
1560 
1561 // void OnMenuRButtonUp(WPARAM wParam, CMenu menu)
1562 #define CR_MSG_WM_MENURBUTTONUP(func) \
1563   if (uMsg == WM_MENURBUTTONUP) {     \
1564     SetMsgHandled(TRUE);              \
1565     func(wParam, (HMENU)lParam);      \
1566     lResult = 0;                      \
1567     if (IsMsgHandled())               \
1568       return TRUE;                    \
1569   }
1570 
1571 // LRESULT OnMenuDrag(WPARAM wParam, CMenu menu)
1572 #define CR_MSG_WM_MENUDRAG(func)           \
1573   if (uMsg == WM_MENUDRAG) {               \
1574     SetMsgHandled(TRUE);                   \
1575     lResult = func(wParam, (HMENU)lParam); \
1576     if (IsMsgHandled())                    \
1577       return TRUE;                         \
1578   }
1579 
1580 // LRESULT OnMenuGetObject(PMENUGETOBJECTINFO info)
1581 #define CR_MSG_WM_MENUGETOBJECT(func)           \
1582   if (uMsg == WM_MENUGETOBJECT) {               \
1583     SetMsgHandled(TRUE);                        \
1584     lResult = func((PMENUGETOBJECTINFO)lParam); \
1585     if (IsMsgHandled())                         \
1586       return TRUE;                              \
1587   }
1588 
1589 // void OnUnInitMenuPopup(UINT nID, CMenu menu)
1590 #define CR_MSG_WM_UNINITMENUPOPUP(func)        \
1591   if (uMsg == WM_UNINITMENUPOPUP) {            \
1592     SetMsgHandled(TRUE);                       \
1593     func((UINT)HIWORD(lParam), (HMENU)wParam); \
1594     lResult = 0;                               \
1595     if (IsMsgHandled())                        \
1596       return TRUE;                             \
1597   }
1598 
1599 // void OnMenuCommand(WPARAM nIndex, CMenu menu)
1600 #define CR_MSG_WM_MENUCOMMAND(func) \
1601   if (uMsg == WM_MENUCOMMAND) {     \
1602     SetMsgHandled(TRUE);            \
1603     func(wParam, (HMENU)lParam);    \
1604     lResult = 0;                    \
1605     if (IsMsgHandled())             \
1606       return TRUE;                  \
1607   }
1608 
1609 #endif /* WINVER >= 0x0500 */
1610 
1611 #if (_WIN32_WINNT >= 0x0500)
1612 
1613 // BOOL OnAppCommand(CWindow wndFocus, short cmd, WORD uDevice, int dwKeys)
1614 #define CR_MSG_WM_APPCOMMAND(func)                         \
1615   if (uMsg == WM_APPCOMMAND) {                             \
1616     SetMsgHandled(TRUE);                                   \
1617     lResult = (LRESULT)func((HWND)wParam,                  \
1618                             GET_APPCOMMAND_LPARAM(lParam), \
1619                             GET_DEVICE_LPARAM(lParam),     \
1620                             GET_KEYSTATE_LPARAM(lParam));  \
1621     if (IsMsgHandled())                                    \
1622       return TRUE;                                         \
1623   }
1624 
1625 // void OnNCXButtonDown(int fwButton, short nHittest, CPoint ptPos)
1626 #define CR_MSG_WM_NCXBUTTONDOWN(func)                                   \
1627   if (uMsg == WM_NCXBUTTONDOWN) {                                       \
1628     SetMsgHandled(TRUE);                                                \
1629     func(GET_XBUTTON_WPARAM(wParam),                                    \
1630          GET_NCHITTEST_WPARAM(wParam),                                  \
1631          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
1632     lResult = 0;                                                        \
1633     if (IsMsgHandled())                                                 \
1634       return TRUE;                                                      \
1635   }
1636 
1637 // void OnNCXButtonUp(int fwButton, short nHittest, CPoint ptPos)
1638 #define CR_MSG_WM_NCXBUTTONUP(func)                                     \
1639   if (uMsg == WM_NCXBUTTONUP) {                                         \
1640     SetMsgHandled(TRUE);                                                \
1641     func(GET_XBUTTON_WPARAM(wParam),                                    \
1642          GET_NCHITTEST_WPARAM(wParam),                                  \
1643          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
1644     lResult = 0;                                                        \
1645     if (IsMsgHandled())                                                 \
1646       return TRUE;                                                      \
1647   }
1648 
1649 // void OnNCXButtonDblClk(int fwButton, short nHittest, CPoint ptPos)
1650 #define CR_MSG_WM_NCXBUTTONDBLCLK(func)                                 \
1651   if (uMsg == WM_NCXBUTTONDBLCLK) {                                     \
1652     SetMsgHandled(TRUE);                                                \
1653     func(GET_XBUTTON_WPARAM(wParam),                                    \
1654          GET_NCHITTEST_WPARAM(wParam),                                  \
1655          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
1656     lResult = 0;                                                        \
1657     if (IsMsgHandled())                                                 \
1658       return TRUE;                                                      \
1659   }
1660 
1661 // void OnXButtonDown(int fwButton, int dwKeys, CPoint ptPos)
1662 #define CR_MSG_WM_XBUTTONDOWN(func)                                     \
1663   if (uMsg == WM_XBUTTONDOWN) {                                         \
1664     SetMsgHandled(TRUE);                                                \
1665     func(GET_XBUTTON_WPARAM(wParam),                                    \
1666          GET_KEYSTATE_WPARAM(wParam),                                   \
1667          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
1668     lResult = 0;                                                        \
1669     if (IsMsgHandled())                                                 \
1670       return TRUE;                                                      \
1671   }
1672 
1673 // void OnXButtonUp(int fwButton, int dwKeys, CPoint ptPos)
1674 #define CR_MSG_WM_XBUTTONUP(func)                                       \
1675   if (uMsg == WM_XBUTTONUP) {                                           \
1676     SetMsgHandled(TRUE);                                                \
1677     func(GET_XBUTTON_WPARAM(wParam),                                    \
1678          GET_KEYSTATE_WPARAM(wParam),                                   \
1679          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
1680     lResult = 0;                                                        \
1681     if (IsMsgHandled())                                                 \
1682       return TRUE;                                                      \
1683   }
1684 
1685 // void OnXButtonDblClk(int fwButton, int dwKeys, CPoint ptPos)
1686 #define CR_MSG_WM_XBUTTONDBLCLK(func)                                   \
1687   if (uMsg == WM_XBUTTONDBLCLK) {                                       \
1688     SetMsgHandled(TRUE);                                                \
1689     func(GET_XBUTTON_WPARAM(wParam),                                    \
1690          GET_KEYSTATE_WPARAM(wParam),                                   \
1691          gfx::Point(CR_GET_X_LPARAM(lParam), CR_GET_Y_LPARAM(lParam))); \
1692     lResult = 0;                                                        \
1693     if (IsMsgHandled())                                                 \
1694       return TRUE;                                                      \
1695   }
1696 
1697 // void OnChangeUIState(WORD nAction, WORD nState)
1698 #define CR_MSG_WM_CHANGEUISTATE(func)     \
1699   if (uMsg == WM_CHANGEUISTATE) {         \
1700     SetMsgHandled(TRUE);                  \
1701     func(LOWORD(wParam), HIWORD(wParam)); \
1702     lResult = 0;                          \
1703     if (IsMsgHandled())                   \
1704       return TRUE;                        \
1705   }
1706 
1707 // void OnUpdateUIState(WORD nAction, WORD nState)
1708 #define CR_MSG_WM_UPDATEUISTATE(func)     \
1709   if (uMsg == WM_UPDATEUISTATE) {         \
1710     SetMsgHandled(TRUE);                  \
1711     func(LOWORD(wParam), HIWORD(wParam)); \
1712     lResult = 0;                          \
1713     if (IsMsgHandled())                   \
1714       return TRUE;                        \
1715   }
1716 
1717 // LRESULT OnQueryUIState()
1718 #define CR_MSG_WM_QUERYUISTATE(func) \
1719   if (uMsg == WM_QUERYUISTATE) {     \
1720     SetMsgHandled(TRUE);             \
1721     lResult = func();                \
1722     if (IsMsgHandled())              \
1723       return TRUE;                   \
1724   }
1725 
1726 #endif  // (_WIN32_WINNT >= 0x0500)
1727 
1728 #if (_WIN32_WINNT >= 0x0501)
1729 
1730 // void OnInput(WPARAM RawInputCode, HRAWINPUT hRawInput)
1731 #define CR_MSG_WM_INPUT(func)                                  \
1732   if (uMsg == WM_INPUT) {                                      \
1733     SetMsgHandled(TRUE);                                       \
1734     func(GET_RAWINPUT_CODE_WPARAM(wParam), (HRAWINPUT)lParam); \
1735     lResult = 0;                                               \
1736     if (IsMsgHandled())                                        \
1737       return TRUE;                                             \
1738   }
1739 
1740 // void OnUniChar(TCHAR nChar, UINT nRepCnt, UINT nFlags)
1741 #define CR_MSG_WM_UNICHAR(func)                            \
1742   if (uMsg == WM_UNICHAR) {                                \
1743     SetMsgHandled(TRUE);                                   \
1744     func((TCHAR)wParam,                                    \
1745          (UINT)lParam & 0xFFFF,                            \
1746          (UINT)((lParam & 0xFFFF0000) >> 16));             \
1747     if (IsMsgHandled()) {                                  \
1748       lResult = (wParam == UNICODE_NOCHAR) ? TRUE : FALSE; \
1749       return TRUE;                                         \
1750     }                                                      \
1751   }
1752 
1753 // void OnWTSSessionChange(WPARAM nStatusCode, PWTSSESSION_NOTIFICATION
1754 // nSessionID)
1755 #define CR_MSG_WM_WTSSESSION_CHANGE(func)           \
1756   if (uMsg == WM_WTSSESSION_CHANGE) {               \
1757     SetMsgHandled(TRUE);                            \
1758     func(wParam, (PWTSSESSION_NOTIFICATION)lParam); \
1759     lResult = 0;                                    \
1760     if (IsMsgHandled())                             \
1761       return TRUE;                                  \
1762   }
1763 
1764 // OnThemeChanged()
1765 #define CR_MSG_WM_THEMECHANGED(func) \
1766   if (uMsg == WM_THEMECHANGED) {     \
1767     SetMsgHandled(TRUE);             \
1768     func();                          \
1769     lResult = 0;                     \
1770     if (IsMsgHandled())              \
1771       return TRUE;                   \
1772   }
1773 
1774 #endif /* _WIN32_WINNT >= 0x0501 */
1775 
1776 ///////////////////////////////////////////////////////////////////////////////
1777 // ATL defined messages
1778 
1779 // BOOL OnForwardMsg(LPMSG Msg, DWORD nUserData)
1780 #define CR_MSG_WM_FORWARDMSG(func)                         \
1781   if (uMsg == WM_FORWARDMSG) {                             \
1782     SetMsgHandled(TRUE);                                   \
1783     lResult = (LRESULT)func((LPMSG)lParam, (DWORD)wParam); \
1784     if (IsMsgHandled())                                    \
1785       return TRUE;                                         \
1786   }
1787 
1788 ///////////////////////////////////////////////////////////////////////////////
1789 // Dialog specific messages
1790 
1791 // LRESULT OnDMGetDefID()
1792 #define MSG_DM_GETDEFID(func) \
1793   if (uMsg == DM_GETDEFID) {  \
1794     SetMsgHandled(TRUE);      \
1795     lResult = func();         \
1796     if (IsMsgHandled())       \
1797       return TRUE;            \
1798   }
1799 
1800 // void OnDMSetDefID(UINT DefID)
1801 #define MSG_DM_SETDEFID(func) \
1802   if (uMsg == DM_SETDEFID) {  \
1803     SetMsgHandled(TRUE);      \
1804     func((UINT)wParam);       \
1805     lResult = TRUE;           \
1806     if (IsMsgHandled())       \
1807       return TRUE;            \
1808   }
1809 
1810 // void OnDMReposition()
1811 #define MSG_DM_REPOSITION(func) \
1812   if (uMsg == DM_REPOSITION) {  \
1813     SetMsgHandled(TRUE);        \
1814     func();                     \
1815     lResult = 0;                \
1816     if (IsMsgHandled())         \
1817       return TRUE;              \
1818   }
1819 
1820 ///////////////////////////////////////////////////////////////////////////////
1821 // Reflected messages
1822 
1823 // void OnReflectedCommand(UINT uNotifyCode, int nID, CWindow wndCtl)
1824 #define MSG_OCM_COMMAND(func)                                      \
1825   if (uMsg == OCM_COMMAND) {                                       \
1826     SetMsgHandled(TRUE);                                           \
1827     func((UINT)HIWORD(wParam), (int)LOWORD(wParam), (HWND)lParam); \
1828     lResult = 0;                                                   \
1829     if (IsMsgHandled())                                            \
1830       return TRUE;                                                 \
1831   }
1832 
1833 // LRESULT OnReflectedNotify(int idCtrl, LPNMHDR pnmh)
1834 #define MSG_OCM_NOTIFY(func)                      \
1835   if (uMsg == OCM_NOTIFY) {                       \
1836     SetMsgHandled(TRUE);                          \
1837     lResult = func((int)wParam, (LPNMHDR)lParam); \
1838     if (IsMsgHandled())                           \
1839       return TRUE;                                \
1840   }
1841 
1842 // void OnReflectedParentNotify(UINT message, UINT nChildID, LPARAM lParam)
1843 #define MSG_OCM_PARENTNOTIFY(func)                            \
1844   if (uMsg == OCM_PARENTNOTIFY) {                             \
1845     SetMsgHandled(TRUE);                                      \
1846     func((UINT)LOWORD(wParam), (UINT)HIWORD(wParam), lParam); \
1847     lResult = 0;                                              \
1848     if (IsMsgHandled())                                       \
1849       return TRUE;                                            \
1850   }
1851 
1852 // void OnReflectedDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
1853 #define MSG_OCM_DRAWITEM(func)                    \
1854   if (uMsg == OCM_DRAWITEM) {                     \
1855     SetMsgHandled(TRUE);                          \
1856     func((UINT)wParam, (LPDRAWITEMSTRUCT)lParam); \
1857     lResult = TRUE;                               \
1858     if (IsMsgHandled())                           \
1859       return TRUE;                                \
1860   }
1861 
1862 // void OnReflectedMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT
1863 // lpMeasureItemStruct)
1864 #define MSG_OCM_MEASUREITEM(func)                    \
1865   if (uMsg == OCM_MEASUREITEM) {                     \
1866     SetMsgHandled(TRUE);                             \
1867     func((UINT)wParam, (LPMEASUREITEMSTRUCT)lParam); \
1868     lResult = TRUE;                                  \
1869     if (IsMsgHandled())                              \
1870       return TRUE;                                   \
1871   }
1872 
1873 // int OnReflectedCompareItem(int nIDCtl, LPCOMPAREITEMSTRUCT
1874 // lpCompareItemStruct)
1875 #define MSG_OCM_COMPAREITEM(func)                                       \
1876   if (uMsg == OCM_COMPAREITEM) {                                        \
1877     SetMsgHandled(TRUE);                                                \
1878     lResult = (LRESULT)func((UINT)wParam, (LPCOMPAREITEMSTRUCT)lParam); \
1879     if (IsMsgHandled())                                                 \
1880       return TRUE;                                                      \
1881   }
1882 
1883 // void OnReflectedDeleteItem(int nIDCtl, LPDELETEITEMSTRUCT lpDeleteItemStruct)
1884 #define MSG_OCM_DELETEITEM(func)                    \
1885   if (uMsg == OCM_DELETEITEM) {                     \
1886     SetMsgHandled(TRUE);                            \
1887     func((UINT)wParam, (LPDELETEITEMSTRUCT)lParam); \
1888     lResult = TRUE;                                 \
1889     if (IsMsgHandled())                             \
1890       return TRUE;                                  \
1891   }
1892 
1893 // int OnReflectedVKeyToItem(UINT nKey, UINT nIndex, CListBox listBox)
1894 #define MSG_OCM_VKEYTOITEM(func)                                   \
1895   if (uMsg == OCM_VKEYTOITEM) {                                    \
1896     SetMsgHandled(TRUE);                                           \
1897     lResult = (LRESULT)func(                                       \
1898         (UINT)LOWORD(wParam), (UINT)HIWORD(wParam), (HWND)lParam); \
1899     if (IsMsgHandled())                                            \
1900       return TRUE;                                                 \
1901   }
1902 
1903 // int OnReflectedCharToItem(UINT nChar, UINT nIndex, CListBox listBox)
1904 #define MSG_OCM_CHARTOITEM(func)                                   \
1905   if (uMsg == OCM_CHARTOITEM) {                                    \
1906     SetMsgHandled(TRUE);                                           \
1907     lResult = (LRESULT)func(                                       \
1908         (UINT)LOWORD(wParam), (UINT)HIWORD(wParam), (HWND)lParam); \
1909     if (IsMsgHandled())                                            \
1910       return TRUE;                                                 \
1911   }
1912 
1913 // void OnReflectedHScroll(UINT nSBCode, UINT nPos, CScrollBar pScrollBar)
1914 #define MSG_OCM_HSCROLL(func)                                       \
1915   if (uMsg == OCM_HSCROLL) {                                        \
1916     SetMsgHandled(TRUE);                                            \
1917     func((int)LOWORD(wParam), (short)HIWORD(wParam), (HWND)lParam); \
1918     lResult = 0;                                                    \
1919     if (IsMsgHandled())                                             \
1920       return TRUE;                                                  \
1921   }
1922 
1923 // void OnReflectedVScroll(UINT nSBCode, UINT nPos, CScrollBar pScrollBar)
1924 #define MSG_OCM_VSCROLL(func)                                       \
1925   if (uMsg == OCM_VSCROLL) {                                        \
1926     SetMsgHandled(TRUE);                                            \
1927     func((int)LOWORD(wParam), (short)HIWORD(wParam), (HWND)lParam); \
1928     lResult = 0;                                                    \
1929     if (IsMsgHandled())                                             \
1930       return TRUE;                                                  \
1931   }
1932 
1933 // HBRUSH OnReflectedCtlColorEdit(CDCHandle dc, CEdit edit)
1934 #define MSG_OCM_CTLCOLOREDIT(func)                      \
1935   if (uMsg == OCM_CTLCOLOREDIT) {                       \
1936     SetMsgHandled(TRUE);                                \
1937     lResult = (LRESULT)func((HDC)wParam, (HWND)lParam); \
1938     if (IsMsgHandled())                                 \
1939       return TRUE;                                      \
1940   }
1941 
1942 // HBRUSH OnReflectedCtlColorListBox(CDCHandle dc, CListBox listBox)
1943 #define MSG_OCM_CTLCOLORLISTBOX(func)                   \
1944   if (uMsg == OCM_CTLCOLORLISTBOX) {                    \
1945     SetMsgHandled(TRUE);                                \
1946     lResult = (LRESULT)func((HDC)wParam, (HWND)lParam); \
1947     if (IsMsgHandled())                                 \
1948       return TRUE;                                      \
1949   }
1950 
1951 // HBRUSH OnReflectedCtlColorBtn(CDCHandle dc, CButton button)
1952 #define MSG_OCM_CTLCOLORBTN(func)                       \
1953   if (uMsg == OCM_CTLCOLORBTN) {                        \
1954     SetMsgHandled(TRUE);                                \
1955     lResult = (LRESULT)func((HDC)wParam, (HWND)lParam); \
1956     if (IsMsgHandled())                                 \
1957       return TRUE;                                      \
1958   }
1959 
1960 // HBRUSH OnReflectedCtlColorDlg(CDCHandle dc, CWindow wnd)
1961 #define MSG_OCM_CTLCOLORDLG(func)                       \
1962   if (uMsg == OCM_CTLCOLORDLG) {                        \
1963     SetMsgHandled(TRUE);                                \
1964     lResult = (LRESULT)func((HDC)wParam, (HWND)lParam); \
1965     if (IsMsgHandled())                                 \
1966       return TRUE;                                      \
1967   }
1968 
1969 // HBRUSH OnReflectedCtlColorScrollBar(CDCHandle dc, CScrollBar scrollBar)
1970 #define MSG_OCM_CTLCOLORSCROLLBAR(func)                 \
1971   if (uMsg == OCM_CTLCOLORSCROLLBAR) {                  \
1972     SetMsgHandled(TRUE);                                \
1973     lResult = (LRESULT)func((HDC)wParam, (HWND)lParam); \
1974     if (IsMsgHandled())                                 \
1975       return TRUE;                                      \
1976   }
1977 
1978 // HBRUSH OnReflectedCtlColorStatic(CDCHandle dc, CStatic wndStatic)
1979 #define MSG_OCM_CTLCOLORSTATIC(func)                    \
1980   if (uMsg == OCM_CTLCOLORSTATIC) {                     \
1981     SetMsgHandled(TRUE);                                \
1982     lResult = (LRESULT)func((HDC)wParam, (HWND)lParam); \
1983     if (IsMsgHandled())                                 \
1984       return TRUE;                                      \
1985   }
1986 
1987 ///////////////////////////////////////////////////////////////////////////////
1988 // Edit specific messages
1989 
1990 // void OnClear()
1991 #define CR_MSG_WM_CLEAR(func) \
1992   if (uMsg == WM_CLEAR) {     \
1993     SetMsgHandled(TRUE);      \
1994     func();                   \
1995     lResult = 0;              \
1996     if (IsMsgHandled())       \
1997       return TRUE;            \
1998   }
1999 
2000 // void OnCopy()
2001 #define CR_MSG_WM_COPY(func) \
2002   if (uMsg == WM_COPY) {     \
2003     SetMsgHandled(TRUE);     \
2004     func();                  \
2005     lResult = 0;             \
2006     if (IsMsgHandled())      \
2007       return TRUE;           \
2008   }
2009 
2010 // void OnCut()
2011 #define CR_MSG_WM_CUT(func) \
2012   if (uMsg == WM_CUT) {     \
2013     SetMsgHandled(TRUE);    \
2014     func();                 \
2015     lResult = 0;            \
2016     if (IsMsgHandled())     \
2017       return TRUE;          \
2018   }
2019 
2020 // void OnPaste()
2021 #define CR_MSG_WM_PASTE(func) \
2022   if (uMsg == WM_PASTE) {     \
2023     SetMsgHandled(TRUE);      \
2024     func();                   \
2025     lResult = 0;              \
2026     if (IsMsgHandled())       \
2027       return TRUE;            \
2028   }
2029 
2030 // void OnUndo()
2031 #define CR_MSG_WM_UNDO(func) \
2032   if (uMsg == WM_UNDO) {     \
2033     SetMsgHandled(TRUE);     \
2034     func();                  \
2035     lResult = 0;             \
2036     if (IsMsgHandled())      \
2037       return TRUE;           \
2038   }
2039 
2040 ///////////////////////////////////////////////////////////////////////////////
2041 // Generic message handlers
2042 
2043 // LRESULT OnMessageHandlerEX(UINT uMsg, WPARAM wParam, LPARAM lParam)
2044 #define CR_MESSAGE_HANDLER_EX(msg, func)  \
2045   if (uMsg == msg) {                      \
2046     SetMsgHandled(TRUE);                  \
2047     lResult = func(uMsg, wParam, lParam); \
2048     if (IsMsgHandled())                   \
2049       return TRUE;                        \
2050   }
2051 
2052 // LRESULT OnMessageRangeHandlerEX(UINT uMsg, WPARAM wParam, LPARAM lParam)
2053 #define CR_MESSAGE_RANGE_HANDLER_EX(msgFirst, msgLast, func) \
2054   if (uMsg >= msgFirst && uMsg <= msgLast) {                 \
2055     SetMsgHandled(TRUE);                                     \
2056     lResult = func(uMsg, wParam, lParam);                    \
2057     if (IsMsgHandled())                                      \
2058       return TRUE;                                           \
2059   }
2060 
2061 ///////////////////////////////////////////////////////////////////////////////
2062 // Commands and notifications
2063 
2064 // void OnCommandHandlerEX(UINT uNotifyCode, int nID, CWindow wndCtl)
2065 #define CR_COMMAND_HANDLER_EX(id, code, func)                                 \
2066   if (uMsg == WM_COMMAND && code == HIWORD(wParam) && id == LOWORD(wParam)) { \
2067     SetMsgHandled(TRUE);                                                      \
2068     func((UINT)HIWORD(wParam), (int)LOWORD(wParam), (HWND)lParam);            \
2069     lResult = 0;                                                              \
2070     if (IsMsgHandled())                                                       \
2071       return TRUE;                                                            \
2072   }
2073 
2074 // void OnCommandIDHandlerEX(UINT uNotifyCode, int nID, CWindow wndCtl)
2075 #define CR_COMMAND_ID_HANDLER_EX(id, func)                         \
2076   if (uMsg == WM_COMMAND && id == LOWORD(wParam)) {                \
2077     SetMsgHandled(TRUE);                                           \
2078     func((UINT)HIWORD(wParam), (int)LOWORD(wParam), (HWND)lParam); \
2079     lResult = 0;                                                   \
2080     if (IsMsgHandled())                                            \
2081       return TRUE;                                                 \
2082   }
2083 
2084 // void OnCommandCodeHandlerEX(UINT uNotifyCode, int nID, CWindow wndCtl)
2085 #define CR_COMMAND_CODE_HANDLER_EX(code, func)                     \
2086   if (uMsg == WM_COMMAND && code == HIWORD(wParam)) {              \
2087     SetMsgHandled(TRUE);                                           \
2088     func((UINT)HIWORD(wParam), (int)LOWORD(wParam), (HWND)lParam); \
2089     lResult = 0;                                                   \
2090     if (IsMsgHandled())                                            \
2091       return TRUE;                                                 \
2092   }
2093 
2094 // LRESULT OnNotifyHandlerEX(LPNMHDR pnmh)
2095 #define CR_NOTIFY_HANDLER_EX(id, cd, func)                  \
2096   if (uMsg == WM_NOTIFY && cd == ((LPNMHDR)lParam)->code && \
2097       id == ((LPNMHDR)lParam)->idFrom) {                    \
2098     SetMsgHandled(TRUE);                                    \
2099     lResult = func((LPNMHDR)lParam);                        \
2100     if (IsMsgHandled())                                     \
2101       return TRUE;                                          \
2102   }
2103 
2104 // LRESULT OnNotifyIDHandlerEX(LPNMHDR pnmh)
2105 #define CR_NOTIFY_ID_HANDLER_EX(id, func)                     \
2106   if (uMsg == WM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom) { \
2107     SetMsgHandled(TRUE);                                      \
2108     lResult = func((LPNMHDR)lParam);                          \
2109     if (IsMsgHandled())                                       \
2110       return TRUE;                                            \
2111   }
2112 
2113 // LRESULT OnNotifyCodeHandlerEX(LPNMHDR pnmh)
2114 #define CR_NOTIFY_CODE_HANDLER_EX(cd, func)                 \
2115   if (uMsg == WM_NOTIFY && cd == ((LPNMHDR)lParam)->code) { \
2116     SetMsgHandled(TRUE);                                    \
2117     lResult = func((LPNMHDR)lParam);                        \
2118     if (IsMsgHandled())                                     \
2119       return TRUE;                                          \
2120   }
2121 
2122 // void OnCommandRangeHandlerEX(UINT uNotifyCode, int nID, CWindow wndCtl)
2123 #define CR_COMMAND_RANGE_HANDLER_EX(idFirst, idLast, func)         \
2124   if (uMsg == WM_COMMAND && LOWORD(wParam) >= idFirst &&           \
2125       LOWORD(wParam) <= idLast) {                                  \
2126     SetMsgHandled(TRUE);                                           \
2127     func((UINT)HIWORD(wParam), (int)LOWORD(wParam), (HWND)lParam); \
2128     lResult = 0;                                                   \
2129     if (IsMsgHandled())                                            \
2130       return TRUE;                                                 \
2131   }
2132 
2133 // void OnCommandRangeCodeHandlerEX(UINT uNotifyCode, int nID, CWindow wndCtl)
2134 #define CR_COMMAND_RANGE_CODE_HANDLER_EX(idFirst, idLast, code, func) \
2135   if (uMsg == WM_COMMAND && code == HIWORD(wParam) &&                 \
2136       LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) {        \
2137     SetMsgHandled(TRUE);                                              \
2138     func((UINT)HIWORD(wParam), (int)LOWORD(wParam), (HWND)lParam);    \
2139     lResult = 0;                                                      \
2140     if (IsMsgHandled())                                               \
2141       return TRUE;                                                    \
2142   }
2143 
2144 // LRESULT OnNotifyRangeHandlerEX(LPNMHDR pnmh)
2145 #define CR_NOTIFY_RANGE_HANDLER_EX(idFirst, idLast, func)          \
2146   if (uMsg == WM_NOTIFY && ((LPNMHDR)lParam)->idFrom >= idFirst && \
2147       ((LPNMHDR)lParam)->idFrom <= idLast) {                       \
2148     SetMsgHandled(TRUE);                                           \
2149     lResult = func((LPNMHDR)lParam);                               \
2150     if (IsMsgHandled())                                            \
2151       return TRUE;                                                 \
2152   }
2153 
2154 // LRESULT OnNotifyRangeCodeHandlerEX(LPNMHDR pnmh)
2155 #define CR_NOTIFY_RANGE_CODE_HANDLER_EX(idFirst, idLast, cd, func) \
2156   if (uMsg == WM_NOTIFY && cd == ((LPNMHDR)lParam)->code &&        \
2157       ((LPNMHDR)lParam)->idFrom >= idFirst &&                      \
2158       ((LPNMHDR)lParam)->idFrom <= idLast) {                       \
2159     SetMsgHandled(TRUE);                                           \
2160     lResult = func((LPNMHDR)lParam);                               \
2161     if (IsMsgHandled())                                            \
2162       return TRUE;                                                 \
2163   }
2164 
2165 // LRESULT OnReflectedCommandHandlerEX(UINT uNotifyCode, int nID, CWindow
2166 // wndCtl)
2167 #define CR_REFLECTED_COMMAND_HANDLER_EX(id, code, func)                        \
2168   if (uMsg == OCM_COMMAND && code == HIWORD(wParam) && id == LOWORD(wParam)) { \
2169     SetMsgHandled(TRUE);                                                       \
2170     func((UINT)HIWORD(wParam), (int)LOWORD(wParam), (HWND)lParam);             \
2171     lResult = 0;                                                               \
2172     if (IsMsgHandled())                                                        \
2173       return TRUE;                                                             \
2174   }
2175 
2176 // LRESULT OnReflectedCommandIDHandlerEX(UINT uNotifyCode, int nID, CWindow
2177 // wndCtl)
2178 #define CR_REFLECTED_COMMAND_ID_HANDLER_EX(id, func)               \
2179   if (uMsg == OCM_COMMAND && id == LOWORD(wParam)) {               \
2180     SetMsgHandled(TRUE);                                           \
2181     func((UINT)HIWORD(wParam), (int)LOWORD(wParam), (HWND)lParam); \
2182     lResult = 0;                                                   \
2183     if (IsMsgHandled())                                            \
2184       return TRUE;                                                 \
2185   }
2186 
2187 // LRESULT OnReflectedCommandCodeHandlerEX(UINT uNotifyCode, int nID, CWindow
2188 // wndCtl)
2189 #define CR_REFLECTED_COMMAND_CODE_HANDLER_EX(code, func)           \
2190   if (uMsg == OCM_COMMAND && code == HIWORD(wParam)) {             \
2191     SetMsgHandled(TRUE);                                           \
2192     func((UINT)HIWORD(wParam), (int)LOWORD(wParam), (HWND)lParam); \
2193     lResult = 0;                                                   \
2194     if (IsMsgHandled())                                            \
2195       return TRUE;                                                 \
2196   }
2197 
2198 // LRESULT OnReflectedNotifyHandlerEX(LPNMHDR pnmh)
2199 #define CR_REFLECTED_NOTIFY_HANDLER_EX(id, cd, func)         \
2200   if (uMsg == OCM_NOTIFY && cd == ((LPNMHDR)lParam)->code && \
2201       id == ((LPNMHDR)lParam)->idFrom) {                     \
2202     SetMsgHandled(TRUE);                                     \
2203     lResult = func((LPNMHDR)lParam);                         \
2204     if (IsMsgHandled())                                      \
2205       return TRUE;                                           \
2206   }
2207 
2208 // LRESULT OnReflectedNotifyIDHandlerEX(LPNMHDR pnmh)
2209 #define CR_REFLECTED_NOTIFY_ID_HANDLER_EX(id, func)            \
2210   if (uMsg == OCM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom) { \
2211     SetMsgHandled(TRUE);                                       \
2212     lResult = func((LPNMHDR)lParam);                           \
2213     if (IsMsgHandled())                                        \
2214       return TRUE;                                             \
2215   }
2216 
2217 // LRESULT OnReflectedNotifyCodeHandlerEX(LPNMHDR pnmh)
2218 #define CR_REFLECTED_NOTIFY_CODE_HANDLER_EX(cd, func)        \
2219   if (uMsg == OCM_NOTIFY && cd == ((LPNMHDR)lParam)->code) { \
2220     SetMsgHandled(TRUE);                                     \
2221     lResult = func((LPNMHDR)lParam);                         \
2222     if (IsMsgHandled())                                      \
2223       return TRUE;                                           \
2224   }
2225 
2226 // void OnReflectedCommandRangeHandlerEX(UINT uNotifyCode, int nID, CWindow
2227 // wndCtl)
2228 #define CR_REFLECTED_COMMAND_RANGE_HANDLER_EX(idFirst, idLast, func) \
2229   if (uMsg == OCM_COMMAND && LOWORD(wParam) >= idFirst &&            \
2230       LOWORD(wParam) <= idLast) {                                    \
2231     SetMsgHandled(TRUE);                                             \
2232     func((UINT)HIWORD(wParam), (int)LOWORD(wParam), (HWND)lParam);   \
2233     lResult = 0;                                                     \
2234     if (IsMsgHandled())                                              \
2235       return TRUE;                                                   \
2236   }
2237 
2238 // void OnReflectedCommandRangeCodeHandlerEX(UINT uNotifyCode, int nID, CWindow
2239 // wndCtl)
2240 #define CR_REFLECTED_COMMAND_RANGE_CODE_HANDLER_EX(                \
2241     idFirst, idLast, code, func)                                   \
2242   if (uMsg == OCM_COMMAND && code == HIWORD(wParam) &&             \
2243       LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) {     \
2244     SetMsgHandled(TRUE);                                           \
2245     func((UINT)HIWORD(wParam), (int)LOWORD(wParam), (HWND)lParam); \
2246     lResult = 0;                                                   \
2247     if (IsMsgHandled())                                            \
2248       return TRUE;                                                 \
2249   }
2250 
2251 // LRESULT OnReflectedNotifyRangeHandlerEX(LPNMHDR pnmh)
2252 #define CR_REFLECTED_NOTIFY_RANGE_HANDLER_EX(idFirst, idLast, func) \
2253   if (uMsg == OCM_NOTIFY && ((LPNMHDR)lParam)->idFrom >= idFirst && \
2254       ((LPNMHDR)lParam)->idFrom <= idLast) {                        \
2255     SetMsgHandled(TRUE);                                            \
2256     lResult = func((LPNMHDR)lParam);                                \
2257     if (IsMsgHandled())                                             \
2258       return TRUE;                                                  \
2259   }
2260 
2261 // LRESULT OnReflectedNotifyRangeCodeHandlerEX(LPNMHDR pnmh)
2262 #define CR_REFLECTED_NOTIFY_RANGE_CODE_HANDLER_EX(idFirst, idLast, cd, func) \
2263   if (uMsg == OCM_NOTIFY && cd == ((LPNMHDR)lParam)->code &&                 \
2264       ((LPNMHDR)lParam)->idFrom >= idFirst &&                                \
2265       ((LPNMHDR)lParam)->idFrom <= idLast) {                                 \
2266     SetMsgHandled(TRUE);                                                     \
2267     lResult = func((LPNMHDR)lParam);                                         \
2268     if (IsMsgHandled())                                                      \
2269       return TRUE;                                                           \
2270   }
2271 
2272 #define CR_DEFLATE_RECT(rect, by)   \
2273   {                                 \
2274     (rect)->left += (by)->left;     \
2275     (rect)->top += (by)->top;       \
2276     (rect)->right -= (by)->right;   \
2277     (rect)->bottom -= (by)->bottom; \
2278   }
2279 
2280 #define CR_POINT_INITIALIZER_FROM_LPARAM(lparam) \
2281   { LOWORD(lparam), HIWORD(lparam) }
2282 
2283 #endif  // UI_GFX_WIN_MSG_UTIL_H_
2284