Sync DrDump crash handler with TortoiseSVN codebase
[TortoiseGit.git] / ext / CrashServer / external / WTL / Include / atlwinx.h
blob749dafb4a6803cbaa2d977373927465e1b3e88b8
1 // Windows Template Library - WTL version 9.0
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 // 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.
12 #ifndef __ATLWINX_H__
13 #define __ATLWINX_H__
15 #pragma once
17 #ifndef __ATLAPP_H__
18 #error atlwinx.h requires atlapp.h to be included first
19 #endif
21 #if (_ATL_VER >= 0x0700)
22 #include <atlwin.h>
23 #endif // (_ATL_VER >= 0x0700)
26 ///////////////////////////////////////////////////////////////////////////////
27 // Classes in this file:
29 // _U_RECT
30 // _U_MENUorID
31 // _U_STRINGorID
34 ///////////////////////////////////////////////////////////////////////////////
35 // Command Chaining Macros
37 #define CHAIN_COMMANDS(theChainClass) \
38 if(uMsg == WM_COMMAND) \
39 CHAIN_MSG_MAP(theChainClass)
41 #define CHAIN_COMMANDS_ALT(theChainClass, msgMapID) \
42 if(uMsg == WM_COMMAND) \
43 CHAIN_MSG_MAP_ALT(theChainClass, msgMapID)
45 #define CHAIN_COMMANDS_MEMBER(theChainMember) \
46 if(uMsg == WM_COMMAND) \
47 CHAIN_MSG_MAP_MEMBER(theChainMember)
49 #define CHAIN_COMMANDS_ALT_MEMBER(theChainMember, msgMapID) \
50 if(uMsg == WM_COMMAND) \
51 CHAIN_MSG_MAP_ALT_MEMBER(theChainMember, msgMapID)
54 ///////////////////////////////////////////////////////////////////////////////
55 // Macros for parent message map to selectively reflect control messages
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)
62 namespace WTL
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)
68 if((uMsgFilter != WM_NULL) && (uMsgFilter != uMsg))
70 // The notification message doesn't match the filter.
71 bHandled = FALSE;
72 return 1;
75 HWND hWndChild = NULL;
76 UINT_PTR idFrom = 0;
78 switch(uMsg)
80 case WM_COMMAND:
81 if(lParam != NULL) // not from a menu
83 hWndChild = (HWND)lParam;
84 idFrom = (UINT_PTR)LOWORD(wParam);
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))
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;
105 break;
106 #endif // !_WIN32_WCE
107 case WM_DRAWITEM:
108 if(wParam) // not from a menu
110 hWndChild = ((LPDRAWITEMSTRUCT)lParam)->hwndItem;
111 idFrom = (UINT_PTR)wParam;
113 break;
114 case WM_MEASUREITEM:
115 if(wParam) // not from a menu
117 hWndChild = ::GetDlgItem(hWndParent, ((LPMEASUREITEMSTRUCT)lParam)->CtlID);
118 idFrom = (UINT_PTR)wParam;
120 break;
121 case WM_COMPAREITEM:
122 if(wParam) // not from a menu
124 hWndChild = ((LPCOMPAREITEMSTRUCT)lParam)->hwndItem;
125 idFrom = (UINT_PTR)wParam;
127 break;
128 case WM_DELETEITEM:
129 if(wParam) // not from a menu
131 hWndChild = ((LPDELETEITEMSTRUCT)lParam)->hwndItem;
132 idFrom = (UINT_PTR)wParam;
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;
156 if((hWndChild == NULL) ||
157 ((hWndChildFilter != NULL) && (hWndChildFilter != hWndChild)))
159 // Either hWndChild isn't valid, or
160 // hWndChild doesn't match the filter.
161 bHandled = FALSE;
162 return 1;
165 if((idFromFilter != 0) && (idFromFilter != idFrom))
167 // The dialog control id doesn't match the filter.
168 bHandled = FALSE;
169 return 1;
172 ATLASSERT(::IsWindow(hWndChild));
173 LRESULT lResult = ::SendMessage(hWndChild, OCM__BASE + uMsg, wParam, lParam);
174 if((lResult == 0) && (uMsg >= WM_CTLCOLORMSGBOX) && (uMsg <= WM_CTLCOLORSTATIC))
176 // Try to prevent problems with WM_CTLCOLOR* messages when
177 // the message wasn't really handled
178 bHandled = FALSE;
181 return lResult;
184 }; // namespace WTL
186 // Try to prevent problems with WM_CTLCOLOR* messages when
187 // the message wasn't really handled
188 #define REFLECT_NOTIFICATIONS_EX() \
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; \
198 #define REFLECT_NOTIFICATIONS_MSG_FILTERED(uMsgFilter) \
200 bHandled = TRUE; \
201 lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, 0, NULL); \
202 if(bHandled) \
203 return TRUE; \
206 #define REFLECT_NOTIFICATIONS_ID_FILTERED(idFromFilter) \
208 bHandled = TRUE; \
209 lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, WM_NULL, idFromFilter, NULL); \
210 if(bHandled) \
211 return TRUE; \
214 #define REFLECT_NOTIFICATIONS_HWND_FILTERED(hWndChildFilter) \
216 bHandled = TRUE; \
217 lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, WM_NULL, 0, hWndChildFilter); \
218 if(bHandled) \
219 return TRUE; \
222 #define REFLECT_NOTIFICATIONS_MSG_ID_FILTERED(uMsgFilter, idFromFilter) \
224 bHandled = TRUE; \
225 lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, idFromFilter, NULL); \
226 if(bHandled) \
227 return TRUE; \
230 #define REFLECT_NOTIFICATIONS_MSG_HWND_FILTERED(uMsgFilter, hWndChildFilter) \
232 bHandled = TRUE; \
233 lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, 0, hWndChildFilter); \
234 if(bHandled) \
235 return TRUE; \
238 #define REFLECT_COMMAND(id, code) \
239 if(uMsg == WM_COMMAND && id == LOWORD(wParam) && code == HIWORD(wParam)) \
241 bHandled = TRUE; \
242 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
243 if(bHandled) \
244 return TRUE; \
247 #define REFLECT_COMMAND_ID(id) \
248 if(uMsg == WM_COMMAND && id == LOWORD(wParam)) \
250 bHandled = TRUE; \
251 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
252 if(bHandled) \
253 return TRUE; \
256 #define REFLECT_COMMAND_CODE(code) \
257 if(uMsg == WM_COMMAND && code == HIWORD(wParam)) \
259 bHandled = TRUE; \
260 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
261 if(bHandled) \
262 return TRUE; \
265 #define REFLECT_COMMAND_RANGE(idFirst, idLast) \
266 if(uMsg == WM_COMMAND && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
268 bHandled = TRUE; \
269 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
270 if(bHandled) \
271 return TRUE; \
274 #define REFLECT_COMMAND_RANGE_CODE(idFirst, idLast, code) \
275 if(uMsg == WM_COMMAND && code == HIWORD(wParam) && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
277 bHandled = TRUE; \
278 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
279 if(bHandled) \
280 return TRUE; \
283 #define REFLECT_NOTIFY(id, cd) \
284 if(uMsg == WM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom && cd == ((LPNMHDR)lParam)->code) \
286 bHandled = TRUE; \
287 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
288 if(bHandled) \
289 return TRUE; \
292 #define REFLECT_NOTIFY_ID(id) \
293 if(uMsg == WM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom) \
295 bHandled = TRUE; \
296 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
297 if(bHandled) \
298 return TRUE; \
301 #define REFLECT_NOTIFY_CODE(cd) \
302 if(uMsg == WM_NOTIFY && cd == ((LPNMHDR)lParam)->code) \
304 bHandled = TRUE; \
305 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
306 if(bHandled) \
307 return TRUE; \
310 #define REFLECT_NOTIFY_RANGE(idFirst, idLast) \
311 if(uMsg == WM_NOTIFY && ((LPNMHDR)lParam)->idFrom >= idFirst && ((LPNMHDR)lParam)->idFrom <= idLast) \
313 bHandled = TRUE; \
314 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
315 if(bHandled) \
316 return TRUE; \
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) \
322 bHandled = TRUE; \
323 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
324 if(bHandled) \
325 return TRUE; \
329 ///////////////////////////////////////////////////////////////////////////////
330 // Reflected message handler macros for message maps (for ATL 3.0)
332 #if (_ATL_VER < 0x0700)
334 #define REFLECTED_COMMAND_HANDLER(id, code, func) \
335 if(uMsg == OCM_COMMAND && id == LOWORD(wParam) && code == HIWORD(wParam)) \
337 bHandled = TRUE; \
338 lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
339 if(bHandled) \
340 return TRUE; \
343 #define REFLECTED_COMMAND_ID_HANDLER(id, func) \
344 if(uMsg == OCM_COMMAND && id == LOWORD(wParam)) \
346 bHandled = TRUE; \
347 lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
348 if(bHandled) \
349 return TRUE; \
352 #define REFLECTED_COMMAND_CODE_HANDLER(code, func) \
353 if(uMsg == OCM_COMMAND && code == HIWORD(wParam)) \
355 bHandled = TRUE; \
356 lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
357 if(bHandled) \
358 return TRUE; \
361 #define REFLECTED_COMMAND_RANGE_HANDLER(idFirst, idLast, func) \
362 if(uMsg == OCM_COMMAND && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
364 bHandled = TRUE; \
365 lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
366 if(bHandled) \
367 return TRUE; \
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) \
373 bHandled = TRUE; \
374 lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
375 if(bHandled) \
376 return TRUE; \
379 #define REFLECTED_NOTIFY_HANDLER(id, cd, func) \
380 if(uMsg == OCM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom && cd == ((LPNMHDR)lParam)->code) \
382 bHandled = TRUE; \
383 lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
384 if(bHandled) \
385 return TRUE; \
388 #define REFLECTED_NOTIFY_ID_HANDLER(id, func) \
389 if(uMsg == OCM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom) \
391 bHandled = TRUE; \
392 lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
393 if(bHandled) \
394 return TRUE; \
397 #define REFLECTED_NOTIFY_CODE_HANDLER(cd, func) \
398 if(uMsg == OCM_NOTIFY && cd == ((LPNMHDR)lParam)->code) \
400 bHandled = TRUE; \
401 lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
402 if(bHandled) \
403 return TRUE; \
406 #define REFLECTED_NOTIFY_RANGE_HANDLER(idFirst, idLast, func) \
407 if(uMsg == OCM_NOTIFY && ((LPNMHDR)lParam)->idFrom >= idFirst && ((LPNMHDR)lParam)->idFrom <= idLast) \
409 bHandled = TRUE; \
410 lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
411 if(bHandled) \
412 return TRUE; \
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) \
418 bHandled = TRUE; \
419 lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
420 if(bHandled) \
421 return TRUE; \
424 #endif // (_ATL_VER < 0x0700)
427 ///////////////////////////////////////////////////////////////////////////////
428 // Dual argument helper classes (for ATL 3.0)
430 #if (_ATL_VER < 0x0700)
432 namespace ATL
435 class _U_RECT
437 public:
438 _U_RECT(LPRECT lpRect) : m_lpRect(lpRect)
440 _U_RECT(RECT& rc) : m_lpRect(&rc)
442 LPRECT m_lpRect;
445 class _U_MENUorID
447 public:
448 _U_MENUorID(HMENU hMenu) : m_hMenu(hMenu)
450 _U_MENUorID(UINT nID) : m_hMenu((HMENU)LongToHandle(nID))
452 HMENU m_hMenu;
455 class _U_STRINGorID
457 public:
458 _U_STRINGorID(LPCTSTR lpString) : m_lpstr(lpString)
460 _U_STRINGorID(UINT nID) : m_lpstr(MAKEINTRESOURCE(nID))
462 LPCTSTR m_lpstr;
465 }; // namespace ATL
467 #endif // (_ATL_VER < 0x0700)
470 namespace WTL
473 ///////////////////////////////////////////////////////////////////////////////
474 // Forward notifications support for message maps (for ATL 3.0)
476 #if (_ATL_VER < 0x0700)
478 // forward notifications support
479 #define FORWARD_NOTIFICATIONS() \
481 bHandled = TRUE; \
482 lResult = WTL::Atl3ForwardNotifications(m_hWnd, uMsg, wParam, lParam, bHandled); \
483 if(bHandled) \
484 return TRUE; \
487 static LRESULT Atl3ForwardNotifications(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
489 LRESULT lResult = 0;
490 switch(uMsg)
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;
518 return lResult;
521 #endif // (_ATL_VER < 0x0700)
523 }; // namespace WTL
525 #endif // __ATLWINX_H__