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