crashrpt
atlwinx.h
1 // Windows Template Library - WTL version 8.1
2 // Copyright (C) Microsoft Corporation. All rights reserved.
3 //
4 // This file is a part of the Windows Template Library.
5 // The use and distribution terms for this software are covered by the
6 // Common Public License 1.0 (http://opensource.org/licenses/cpl1.0.php)
7 // which can be found in the file CPL.TXT at the root of this distribution.
8 // By using this software in any fashion, you are agreeing to be bound by
9 // the terms of this license. You must not remove this notice, or
10 // any other, from this software.
11 
12 #ifndef __ATLWINX_H__
13 #define __ATLWINX_H__
14 
15 #pragma once
16 
17 #ifndef __ATLAPP_H__
18  #error atlwinx.h requires atlapp.h to be included first
19 #endif
20 
21 #if (_ATL_VER >= 0x0700)
22  #include <atlwin.h>
23 #endif // (_ATL_VER >= 0x0700)
24 
25 
27 // Classes in this file:
28 //
29 // _U_RECT
30 // _U_MENUorID
31 // _U_STRINGorID
32 
33 
35 // Command Chaining Macros
36 
37 #define CHAIN_COMMANDS(theChainClass) \
38  if(uMsg == WM_COMMAND) \
39  CHAIN_MSG_MAP(theChainClass)
40 
41 #define CHAIN_COMMANDS_ALT(theChainClass, msgMapID) \
42  if(uMsg == WM_COMMAND) \
43  CHAIN_MSG_MAP_ALT(theChainClass, msgMapID)
44 
45 #define CHAIN_COMMANDS_MEMBER(theChainMember) \
46  if(uMsg == WM_COMMAND) \
47  CHAIN_MSG_MAP_MEMBER(theChainMember)
48 
49 #define CHAIN_COMMANDS_ALT_MEMBER(theChainMember, msgMapID) \
50  if(uMsg == WM_COMMAND) \
51  CHAIN_MSG_MAP_ALT_MEMBER(theChainMember, msgMapID)
52 
53 
55 // Macros for parent message map to selectively reflect control messages
56 
57 // NOTE: ReflectNotifications is a member of ATL's CWindowImplRoot
58 // (and overridden in 2 cases - CContainedWindowT and CAxHostWindow)
59 // Since we can't modify ATL, we'll provide the needed additions
60 // in a separate function (that is not a member of CWindowImplRoot)
61 
62 namespace WTL
63 {
64 
65 inline LRESULT WtlReflectNotificationsFiltered(HWND hWndParent, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled,
66  UINT uMsgFilter = WM_NULL, UINT_PTR idFromFilter = 0, HWND hWndChildFilter = NULL)
67 {
68  if((uMsgFilter != WM_NULL) && (uMsgFilter != uMsg))
69  {
70  // The notification message doesn't match the filter.
71  bHandled = FALSE;
72  return 1;
73  }
74 
75  HWND hWndChild = NULL;
76  UINT_PTR idFrom = 0;
77 
78  switch(uMsg)
79  {
80  case WM_COMMAND:
81  if(lParam != NULL) // not from a menu
82  {
83  hWndChild = (HWND)lParam;
84  idFrom = (UINT_PTR)LOWORD(wParam);
85  }
86  break;
87  case WM_NOTIFY:
88  hWndChild = ((LPNMHDR)lParam)->hwndFrom;
89  idFrom = ((LPNMHDR)lParam)->idFrom;
90  break;
91 #ifndef _WIN32_WCE
92  case WM_PARENTNOTIFY:
93  switch(LOWORD(wParam))
94  {
95  case WM_CREATE:
96  case WM_DESTROY:
97  hWndChild = (HWND)lParam;
98  idFrom = (UINT_PTR)HIWORD(wParam);
99  break;
100  default:
101  hWndChild = ::GetDlgItem(hWndParent, HIWORD(wParam));
102  idFrom = (UINT_PTR)::GetDlgCtrlID(hWndChild);
103  break;
104  }
105  break;
106 #endif // !_WIN32_WCE
107  case WM_DRAWITEM:
108  if(wParam) // not from a menu
109  {
110  hWndChild = ((LPDRAWITEMSTRUCT)lParam)->hwndItem;
111  idFrom = (UINT_PTR)wParam;
112  }
113  break;
114  case WM_MEASUREITEM:
115  if(wParam) // not from a menu
116  {
117  hWndChild = ::GetDlgItem(hWndParent, ((LPMEASUREITEMSTRUCT)lParam)->CtlID);
118  idFrom = (UINT_PTR)wParam;
119  }
120  break;
121  case WM_COMPAREITEM:
122  if(wParam) // not from a menu
123  {
124  hWndChild = ((LPCOMPAREITEMSTRUCT)lParam)->hwndItem;
125  idFrom = (UINT_PTR)wParam;
126  }
127  break;
128  case WM_DELETEITEM:
129  if(wParam) // not from a menu
130  {
131  hWndChild = ((LPDELETEITEMSTRUCT)lParam)->hwndItem;
132  idFrom = (UINT_PTR)wParam;
133  }
134  break;
135  case WM_VKEYTOITEM:
136  case WM_CHARTOITEM:
137  case WM_HSCROLL:
138  case WM_VSCROLL:
139  hWndChild = (HWND)lParam;
140  idFrom = (UINT_PTR)::GetDlgCtrlID(hWndChild);
141  break;
142  case WM_CTLCOLORBTN:
143  case WM_CTLCOLORDLG:
144  case WM_CTLCOLOREDIT:
145  case WM_CTLCOLORLISTBOX:
146  case WM_CTLCOLORMSGBOX:
147  case WM_CTLCOLORSCROLLBAR:
148  case WM_CTLCOLORSTATIC:
149  hWndChild = (HWND)lParam;
150  idFrom = (UINT_PTR)::GetDlgCtrlID(hWndChild);
151  break;
152  default:
153  break;
154  }
155 
156  if((hWndChild == NULL) ||
157  ((hWndChildFilter != NULL) && (hWndChildFilter != hWndChild)))
158  {
159  // Either hWndChild isn't valid, or
160  // hWndChild doesn't match the filter.
161  bHandled = FALSE;
162  return 1;
163  }
164 
165  if((idFromFilter != 0) && (idFromFilter != idFrom))
166  {
167  // The dialog control id doesn't match the filter.
168  bHandled = FALSE;
169  return 1;
170  }
171 
172  ATLASSERT(::IsWindow(hWndChild));
173  LRESULT lResult = ::SendMessage(hWndChild, OCM__BASE + uMsg, wParam, lParam);
174  if((lResult == 0) && (uMsg >= WM_CTLCOLORMSGBOX) && (uMsg <= WM_CTLCOLORSTATIC))
175  {
176  // Try to prevent problems with WM_CTLCOLOR* messages when
177  // the message wasn't really handled
178  bHandled = FALSE;
179  }
180 
181  return lResult;
182 }
183 
184 }; // namespace WTL
185 
186 // Try to prevent problems with WM_CTLCOLOR* messages when
187 // the message wasn't really handled
188 #define REFLECT_NOTIFICATIONS_EX() \
189 { \
190  bHandled = TRUE; \
191  lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
192  if((lResult == 0) && (uMsg >= WM_CTLCOLORMSGBOX) && (uMsg <= WM_CTLCOLORSTATIC)) \
193  bHandled = FALSE; \
194  if(bHandled) \
195  return TRUE; \
196 }
197 
198 #define REFLECT_NOTIFICATIONS_MSG_FILTERED(uMsgFilter) \
199  { \
200  bHandled = TRUE; \
201  lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, 0, NULL); \
202  if(bHandled) \
203  return TRUE; \
204  }
205 
206 #define REFLECT_NOTIFICATIONS_ID_FILTERED(idFromFilter) \
207  { \
208  bHandled = TRUE; \
209  lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, WM_NULL, idFromFilter, NULL); \
210  if(bHandled) \
211  return TRUE; \
212  }
213 
214 #define REFLECT_NOTIFICATIONS_HWND_FILTERED(hWndChildFilter) \
215  { \
216  bHandled = TRUE; \
217  lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, WM_NULL, 0, hWndChildFilter); \
218  if(bHandled) \
219  return TRUE; \
220  }
221 
222 #define REFLECT_NOTIFICATIONS_MSG_ID_FILTERED(uMsgFilter, idFromFilter) \
223  { \
224  bHandled = TRUE; \
225  lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, idFromFilter, NULL); \
226  if(bHandled) \
227  return TRUE; \
228  }
229 
230 #define REFLECT_NOTIFICATIONS_MSG_HWND_FILTERED(uMsgFilter, hWndChildFilter) \
231  { \
232  bHandled = TRUE; \
233  lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, 0, hWndChildFilter); \
234  if(bHandled) \
235  return TRUE; \
236  }
237 
238 #define REFLECT_COMMAND(id, code) \
239  if(uMsg == WM_COMMAND && id == LOWORD(wParam) && code == HIWORD(wParam)) \
240  { \
241  bHandled = TRUE; \
242  lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
243  if(bHandled) \
244  return TRUE; \
245  }
246 
247 #define REFLECT_COMMAND_ID(id) \
248  if(uMsg == WM_COMMAND && id == LOWORD(wParam)) \
249  { \
250  bHandled = TRUE; \
251  lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
252  if(bHandled) \
253  return TRUE; \
254  }
255 
256 #define REFLECT_COMMAND_CODE(code) \
257  if(uMsg == WM_COMMAND && code == HIWORD(wParam)) \
258  { \
259  bHandled = TRUE; \
260  lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
261  if(bHandled) \
262  return TRUE; \
263  }
264 
265 #define REFLECT_COMMAND_RANGE(idFirst, idLast) \
266  if(uMsg == WM_COMMAND && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
267  { \
268  bHandled = TRUE; \
269  lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
270  if(bHandled) \
271  return TRUE; \
272  }
273 
274 #define REFLECT_COMMAND_RANGE_CODE(idFirst, idLast, code) \
275  if(uMsg == WM_COMMAND && code == HIWORD(wParam) && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
276  { \
277  bHandled = TRUE; \
278  lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
279  if(bHandled) \
280  return TRUE; \
281  }
282 
283 #define REFLECT_NOTIFY(id, cd) \
284  if(uMsg == WM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom && cd == ((LPNMHDR)lParam)->code) \
285  { \
286  bHandled = TRUE; \
287  lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
288  if(bHandled) \
289  return TRUE; \
290  }
291 
292 #define REFLECT_NOTIFY_ID(id) \
293  if(uMsg == WM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom) \
294  { \
295  bHandled = TRUE; \
296  lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
297  if(bHandled) \
298  return TRUE; \
299  }
300 
301 #define REFLECT_NOTIFY_CODE(cd) \
302  if(uMsg == WM_NOTIFY && cd == ((LPNMHDR)lParam)->code) \
303  { \
304  bHandled = TRUE; \
305  lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
306  if(bHandled) \
307  return TRUE; \
308  }
309 
310 #define REFLECT_NOTIFY_RANGE(idFirst, idLast) \
311  if(uMsg == WM_NOTIFY && ((LPNMHDR)lParam)->idFrom >= idFirst && ((LPNMHDR)lParam)->idFrom <= idLast) \
312  { \
313  bHandled = TRUE; \
314  lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
315  if(bHandled) \
316  return TRUE; \
317  }
318 
319 #define REFLECT_NOTIFY_RANGE_CODE(idFirst, idLast, cd) \
320  if(uMsg == WM_NOTIFY && cd == ((LPNMHDR)lParam)->code && ((LPNMHDR)lParam)->idFrom >= idFirst && ((LPNMHDR)lParam)->idFrom <= idLast) \
321  { \
322  bHandled = TRUE; \
323  lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
324  if(bHandled) \
325  return TRUE; \
326  }
327 
328 
330 // Reflected message handler macros for message maps (for ATL 3.0)
331 
332 #if (_ATL_VER < 0x0700)
333 
334 #define REFLECTED_COMMAND_HANDLER(id, code, func) \
335  if(uMsg == OCM_COMMAND && id == LOWORD(wParam) && code == HIWORD(wParam)) \
336  { \
337  bHandled = TRUE; \
338  lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
339  if(bHandled) \
340  return TRUE; \
341  }
342 
343 #define REFLECTED_COMMAND_ID_HANDLER(id, func) \
344  if(uMsg == OCM_COMMAND && id == LOWORD(wParam)) \
345  { \
346  bHandled = TRUE; \
347  lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
348  if(bHandled) \
349  return TRUE; \
350  }
351 
352 #define REFLECTED_COMMAND_CODE_HANDLER(code, func) \
353  if(uMsg == OCM_COMMAND && code == HIWORD(wParam)) \
354  { \
355  bHandled = TRUE; \
356  lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
357  if(bHandled) \
358  return TRUE; \
359  }
360 
361 #define REFLECTED_COMMAND_RANGE_HANDLER(idFirst, idLast, func) \
362  if(uMsg == OCM_COMMAND && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
363  { \
364  bHandled = TRUE; \
365  lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
366  if(bHandled) \
367  return TRUE; \
368  }
369 
370 #define REFLECTED_COMMAND_RANGE_CODE_HANDLER(idFirst, idLast, code, func) \
371  if(uMsg == OCM_COMMAND && code == HIWORD(wParam) && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
372  { \
373  bHandled = TRUE; \
374  lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
375  if(bHandled) \
376  return TRUE; \
377  }
378 
379 #define REFLECTED_NOTIFY_HANDLER(id, cd, func) \
380  if(uMsg == OCM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom && cd == ((LPNMHDR)lParam)->code) \
381  { \
382  bHandled = TRUE; \
383  lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
384  if(bHandled) \
385  return TRUE; \
386  }
387 
388 #define REFLECTED_NOTIFY_ID_HANDLER(id, func) \
389  if(uMsg == OCM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom) \
390  { \
391  bHandled = TRUE; \
392  lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
393  if(bHandled) \
394  return TRUE; \
395  }
396 
397 #define REFLECTED_NOTIFY_CODE_HANDLER(cd, func) \
398  if(uMsg == OCM_NOTIFY && cd == ((LPNMHDR)lParam)->code) \
399  { \
400  bHandled = TRUE; \
401  lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
402  if(bHandled) \
403  return TRUE; \
404  }
405 
406 #define REFLECTED_NOTIFY_RANGE_HANDLER(idFirst, idLast, func) \
407  if(uMsg == OCM_NOTIFY && ((LPNMHDR)lParam)->idFrom >= idFirst && ((LPNMHDR)lParam)->idFrom <= idLast) \
408  { \
409  bHandled = TRUE; \
410  lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
411  if(bHandled) \
412  return TRUE; \
413  }
414 
415 #define REFLECTED_NOTIFY_RANGE_CODE_HANDLER(idFirst, idLast, cd, func) \
416  if(uMsg == OCM_NOTIFY && cd == ((LPNMHDR)lParam)->code && ((LPNMHDR)lParam)->idFrom >= idFirst && ((LPNMHDR)lParam)->idFrom <= idLast) \
417  { \
418  bHandled = TRUE; \
419  lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
420  if(bHandled) \
421  return TRUE; \
422  }
423 
424 #endif // (_ATL_VER < 0x0700)
425 
426 
428 // Dual argument helper classes (for ATL 3.0)
429 
430 #if (_ATL_VER < 0x0700)
431 
432 namespace ATL
433 {
434 
435 class _U_RECT
436 {
437 public:
438  _U_RECT(LPRECT lpRect) : m_lpRect(lpRect)
439  { }
440  _U_RECT(RECT& rc) : m_lpRect(&rc)
441  { }
442  LPRECT m_lpRect;
443 };
444 
446 {
447 public:
448  _U_MENUorID(HMENU hMenu) : m_hMenu(hMenu)
449  { }
450  _U_MENUorID(UINT nID) : m_hMenu((HMENU)LongToHandle(nID))
451  { }
452  HMENU m_hMenu;
453 };
454 
456 {
457 public:
458  _U_STRINGorID(LPCTSTR lpString) : m_lpstr(lpString)
459  { }
460  _U_STRINGorID(UINT nID) : m_lpstr(MAKEINTRESOURCE(nID))
461  { }
462  LPCTSTR m_lpstr;
463 };
464 
465 }; // namespace ATL
466 
467 #endif // (_ATL_VER < 0x0700)
468 
469 
470 namespace WTL
471 {
472 
474 // Forward notifications support for message maps (for ATL 3.0)
475 
476 #if (_ATL_VER < 0x0700)
477 
478 // forward notifications support
479 #define FORWARD_NOTIFICATIONS() \
480  { \
481  bHandled = TRUE; \
482  lResult = WTL::Atl3ForwardNotifications(m_hWnd, uMsg, wParam, lParam, bHandled); \
483  if(bHandled) \
484  return TRUE; \
485  }
486 
487 static LRESULT Atl3ForwardNotifications(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
488 {
489  LRESULT lResult = 0;
490  switch(uMsg)
491  {
492  case WM_COMMAND:
493  case WM_NOTIFY:
494 #ifndef _WIN32_WCE
495  case WM_PARENTNOTIFY:
496 #endif // !_WIN32_WCE
497  case WM_DRAWITEM:
498  case WM_MEASUREITEM:
499  case WM_COMPAREITEM:
500  case WM_DELETEITEM:
501  case WM_VKEYTOITEM:
502  case WM_CHARTOITEM:
503  case WM_HSCROLL:
504  case WM_VSCROLL:
505  case WM_CTLCOLORBTN:
506  case WM_CTLCOLORDLG:
507  case WM_CTLCOLOREDIT:
508  case WM_CTLCOLORLISTBOX:
509  case WM_CTLCOLORMSGBOX:
510  case WM_CTLCOLORSCROLLBAR:
511  case WM_CTLCOLORSTATIC:
512  lResult = ::SendMessage(::GetParent(hWnd), uMsg, wParam, lParam);
513  break;
514  default:
515  bHandled = FALSE;
516  break;
517  }
518  return lResult;
519 }
520 
521 #endif // (_ATL_VER < 0x0700)
522 
523 }; // namespace WTL
524 
525 #endif // __ATLWINX_H__
Definition: atlwinx.h:455
Definition: stdafx.h:41
Definition: atlwinx.h:445
Definition: atlapp.h:484
Definition: atlwinx.h:435