1 // Windows Template Library - WTL version 8.0
\r
2 // Copyright (C) Microsoft Corporation. All rights reserved.
\r
4 // This file is a part of the Windows Template Library.
\r
5 // The use and distribution terms for this software are covered by the
\r
6 // Common Public License 1.0 (http://opensource.org/osi3.0/licenses/cpl1.0.php)
\r
7 // which can be found in the file CPL.TXT at the root of this distribution.
\r
8 // By using this software in any fashion, you are agreeing to be bound by
\r
9 // the terms of this license. You must not remove this notice, or
\r
10 // any other, from this software.
\r
12 #ifndef __ATLWINX_H__
\r
13 #define __ATLWINX_H__
\r
18 #error ATL requires C++ compilation (use a .cpp suffix)
\r
21 #ifndef __ATLAPP_H__
\r
22 #error atlwinx.h requires atlapp.h to be included first
\r
25 #if (_ATL_VER >= 0x0700)
\r
27 #endif // (_ATL_VER >= 0x0700)
\r
30 ///////////////////////////////////////////////////////////////////////////////
\r
31 // Classes in this file:
\r
38 ///////////////////////////////////////////////////////////////////////////////
\r
39 // Command Chaining Macros
\r
41 #define CHAIN_COMMANDS(theChainClass) \
\r
42 if(uMsg == WM_COMMAND) \
\r
43 CHAIN_MSG_MAP(theChainClass)
\r
45 #define CHAIN_COMMANDS_ALT(theChainClass, msgMapID) \
\r
46 if(uMsg == WM_COMMAND) \
\r
47 CHAIN_MSG_MAP_ALT(theChainClass, msgMapID)
\r
49 #define CHAIN_COMMANDS_MEMBER(theChainMember) \
\r
50 if(uMsg == WM_COMMAND) \
\r
51 CHAIN_MSG_MAP_MEMBER(theChainMember)
\r
53 #define CHAIN_COMMANDS_ALT_MEMBER(theChainMember, msgMapID) \
\r
54 if(uMsg == WM_COMMAND) \
\r
55 CHAIN_MSG_MAP_ALT_MEMBER(theChainMember, msgMapID)
\r
58 ///////////////////////////////////////////////////////////////////////////////
\r
59 // Macros for parent message map to selectively reflect control messages
\r
61 // NOTE: ReflectNotifications is a member of ATL's CWindowImplRoot
\r
62 // (and overridden in 2 cases - CContainedWindowT and CAxHostWindow)
\r
63 // Since we can't modify ATL, we'll provide the needed additions
\r
64 // in a separate function (that is not a member of CWindowImplRoot)
\r
69 inline LRESULT WtlReflectNotificationsFiltered(HWND hWndParent, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled,
\r
70 UINT uMsgFilter = WM_NULL, UINT_PTR idFromFilter = 0, HWND hWndChildFilter = NULL)
\r
72 if((uMsgFilter != WM_NULL) && (uMsgFilter != uMsg))
\r
74 // The notification message doesn't match the filter.
\r
79 HWND hWndChild = NULL;
\r
80 UINT_PTR idFrom = 0;
\r
85 if(lParam != NULL) // not from a menu
\r
87 hWndChild = (HWND)lParam;
\r
88 idFrom = (UINT_PTR)LOWORD(wParam);
\r
92 hWndChild = ((LPNMHDR)lParam)->hwndFrom;
\r
93 idFrom = ((LPNMHDR)lParam)->idFrom;
\r
96 case WM_PARENTNOTIFY:
\r
97 switch(LOWORD(wParam))
\r
101 hWndChild = (HWND)lParam;
\r
102 idFrom = (UINT_PTR)HIWORD(wParam);
\r
105 hWndChild = ::GetDlgItem(hWndParent, HIWORD(wParam));
\r
106 idFrom = (UINT_PTR)::GetDlgCtrlID(hWndChild);
\r
110 #endif // !_WIN32_WCE
\r
112 if(wParam) // not from a menu
\r
114 hWndChild = ((LPDRAWITEMSTRUCT)lParam)->hwndItem;
\r
115 idFrom = (UINT_PTR)wParam;
\r
118 case WM_MEASUREITEM:
\r
119 if(wParam) // not from a menu
\r
121 hWndChild = ::GetDlgItem(hWndParent, ((LPMEASUREITEMSTRUCT)lParam)->CtlID);
\r
122 idFrom = (UINT_PTR)wParam;
\r
125 case WM_COMPAREITEM:
\r
126 if(wParam) // not from a menu
\r
128 hWndChild = ((LPCOMPAREITEMSTRUCT)lParam)->hwndItem;
\r
129 idFrom = (UINT_PTR)wParam;
\r
132 case WM_DELETEITEM:
\r
133 if(wParam) // not from a menu
\r
135 hWndChild = ((LPDELETEITEMSTRUCT)lParam)->hwndItem;
\r
136 idFrom = (UINT_PTR)wParam;
\r
139 case WM_VKEYTOITEM:
\r
140 case WM_CHARTOITEM:
\r
143 hWndChild = (HWND)lParam;
\r
144 idFrom = (UINT_PTR)::GetDlgCtrlID(hWndChild);
\r
146 case WM_CTLCOLORBTN:
\r
147 case WM_CTLCOLORDLG:
\r
148 case WM_CTLCOLOREDIT:
\r
149 case WM_CTLCOLORLISTBOX:
\r
150 case WM_CTLCOLORMSGBOX:
\r
151 case WM_CTLCOLORSCROLLBAR:
\r
152 case WM_CTLCOLORSTATIC:
\r
153 hWndChild = (HWND)lParam;
\r
154 idFrom = (UINT_PTR)::GetDlgCtrlID(hWndChild);
\r
160 if((hWndChild == NULL) ||
\r
161 ((hWndChildFilter != NULL) && (hWndChildFilter != hWndChild)))
\r
163 // Either hWndChild isn't valid, or
\r
164 // hWndChild doesn't match the filter.
\r
169 if((idFromFilter != 0) && (idFromFilter != idFrom))
\r
171 // The dialog control id doesn't match the filter.
\r
176 ATLASSERT(::IsWindow(hWndChild));
\r
177 LRESULT lResult = ::SendMessage(hWndChild, OCM__BASE + uMsg, wParam, lParam);
\r
178 if((lResult == 0) && (uMsg >= WM_CTLCOLORMSGBOX) && (uMsg <= WM_CTLCOLORSTATIC))
\r
180 // Try to prevent problems with WM_CTLCOLOR* messages when
\r
181 // the message wasn't really handled
\r
188 }; // namespace WTL
\r
190 // Try to prevent problems with WM_CTLCOLOR* messages when
\r
191 // the message wasn't really handled
\r
192 #define REFLECT_NOTIFICATIONS_EX() \
\r
195 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
\r
196 if((lResult == 0) && (uMsg >= WM_CTLCOLORMSGBOX) && (uMsg <= WM_CTLCOLORSTATIC)) \
\r
197 bHandled = FALSE; \
\r
202 #define REFLECT_NOTIFICATIONS_MSG_FILTERED(uMsgFilter) \
\r
205 lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, 0, NULL); \
\r
210 #define REFLECT_NOTIFICATIONS_ID_FILTERED(idFromFilter) \
\r
213 lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, WM_NULL, idFromFilter, NULL); \
\r
218 #define REFLECT_NOTIFICATIONS_HWND_FILTERED(hWndChildFilter) \
\r
221 lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, WM_NULL, 0, hWndChildFilter); \
\r
226 #define REFLECT_NOTIFICATIONS_MSG_ID_FILTERED(uMsgFilter, idFromFilter) \
\r
229 lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, idFromFilter, NULL); \
\r
234 #define REFLECT_NOTIFICATIONS_MSG_HWND_FILTERED(uMsgFilter, hWndChildFilter) \
\r
237 lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, 0, hWndChildFilter); \
\r
242 #define REFLECT_COMMAND(id, code) \
\r
243 if(uMsg == WM_COMMAND && id == LOWORD(wParam) && code == HIWORD(wParam)) \
\r
246 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
\r
251 #define REFLECT_COMMAND_ID(id) \
\r
252 if(uMsg == WM_COMMAND && id == LOWORD(wParam)) \
\r
255 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
\r
260 #define REFLECT_COMMAND_CODE(code) \
\r
261 if(uMsg == WM_COMMAND && code == HIWORD(wParam)) \
\r
264 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
\r
269 #define REFLECT_COMMAND_RANGE(idFirst, idLast) \
\r
270 if(uMsg == WM_COMMAND && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
\r
273 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
\r
278 #define REFLECT_COMMAND_RANGE_CODE(idFirst, idLast, code) \
\r
279 if(uMsg == WM_COMMAND && code == HIWORD(wParam) && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
\r
282 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
\r
287 #define REFLECT_NOTIFY(id, cd) \
\r
288 if(uMsg == WM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom && cd == ((LPNMHDR)lParam)->code) \
\r
291 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
\r
296 #define REFLECT_NOTIFY_ID(id) \
\r
297 if(uMsg == WM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom) \
\r
300 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
\r
305 #define REFLECT_NOTIFY_CODE(cd) \
\r
306 if(uMsg == WM_NOTIFY && cd == ((LPNMHDR)lParam)->code) \
\r
309 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
\r
314 #define REFLECT_NOTIFY_RANGE(idFirst, idLast) \
\r
315 if(uMsg == WM_NOTIFY && ((LPNMHDR)lParam)->idFrom >= idFirst && ((LPNMHDR)lParam)->idFrom <= idLast) \
\r
318 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
\r
323 #define REFLECT_NOTIFY_RANGE_CODE(idFirst, idLast, cd) \
\r
324 if(uMsg == WM_NOTIFY && cd == ((LPNMHDR)lParam)->code && ((LPNMHDR)lParam)->idFrom >= idFirst && ((LPNMHDR)lParam)->idFrom <= idLast) \
\r
327 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
\r
333 ///////////////////////////////////////////////////////////////////////////////
\r
334 // Reflected message handler macros for message maps (for ATL 3.0)
\r
336 #if (_ATL_VER < 0x0700)
\r
338 #define REFLECTED_COMMAND_HANDLER(id, code, func) \
\r
339 if(uMsg == OCM_COMMAND && id == LOWORD(wParam) && code == HIWORD(wParam)) \
\r
342 lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
\r
347 #define REFLECTED_COMMAND_ID_HANDLER(id, func) \
\r
348 if(uMsg == OCM_COMMAND && id == LOWORD(wParam)) \
\r
351 lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
\r
356 #define REFLECTED_COMMAND_CODE_HANDLER(code, func) \
\r
357 if(uMsg == OCM_COMMAND && code == HIWORD(wParam)) \
\r
360 lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
\r
365 #define REFLECTED_COMMAND_RANGE_HANDLER(idFirst, idLast, func) \
\r
366 if(uMsg == OCM_COMMAND && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
\r
369 lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
\r
374 #define REFLECTED_COMMAND_RANGE_CODE_HANDLER(idFirst, idLast, code, func) \
\r
375 if(uMsg == OCM_COMMAND && code == HIWORD(wParam) && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
\r
378 lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
\r
383 #define REFLECTED_NOTIFY_HANDLER(id, cd, func) \
\r
384 if(uMsg == OCM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom && cd == ((LPNMHDR)lParam)->code) \
\r
387 lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
\r
392 #define REFLECTED_NOTIFY_ID_HANDLER(id, func) \
\r
393 if(uMsg == OCM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom) \
\r
396 lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
\r
401 #define REFLECTED_NOTIFY_CODE_HANDLER(cd, func) \
\r
402 if(uMsg == OCM_NOTIFY && cd == ((LPNMHDR)lParam)->code) \
\r
405 lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
\r
410 #define REFLECTED_NOTIFY_RANGE_HANDLER(idFirst, idLast, func) \
\r
411 if(uMsg == OCM_NOTIFY && ((LPNMHDR)lParam)->idFrom >= idFirst && ((LPNMHDR)lParam)->idFrom <= idLast) \
\r
414 lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
\r
419 #define REFLECTED_NOTIFY_RANGE_CODE_HANDLER(idFirst, idLast, cd, func) \
\r
420 if(uMsg == OCM_NOTIFY && cd == ((LPNMHDR)lParam)->code && ((LPNMHDR)lParam)->idFrom >= idFirst && ((LPNMHDR)lParam)->idFrom <= idLast) \
\r
423 lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
\r
428 #endif // (_ATL_VER < 0x0700)
\r
431 ///////////////////////////////////////////////////////////////////////////////
\r
432 // Dual argument helper classes (for ATL 3.0)
\r
434 #if (_ATL_VER < 0x0700)
\r
442 _U_RECT(LPRECT lpRect) : m_lpRect(lpRect)
\r
444 _U_RECT(RECT& rc) : m_lpRect(&rc)
\r
452 _U_MENUorID(HMENU hMenu) : m_hMenu(hMenu)
\r
454 _U_MENUorID(UINT nID) : m_hMenu((HMENU)LongToHandle(nID))
\r
459 class _U_STRINGorID
\r
462 _U_STRINGorID(LPCTSTR lpString) : m_lpstr(lpString)
\r
464 _U_STRINGorID(UINT nID) : m_lpstr(MAKEINTRESOURCE(nID))
\r
469 }; // namespace ATL
\r
471 #endif // (_ATL_VER < 0x0700)
\r
477 ///////////////////////////////////////////////////////////////////////////////
\r
478 // Forward notifications support for message maps (for ATL 3.0)
\r
480 #if (_ATL_VER < 0x0700)
\r
482 // forward notifications support
\r
483 #define FORWARD_NOTIFICATIONS() \
\r
486 lResult = WTL::Atl3ForwardNotifications(m_hWnd, uMsg, wParam, lParam, bHandled); \
\r
491 static LRESULT Atl3ForwardNotifications(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
\r
493 LRESULT lResult = 0;
\r
499 case WM_PARENTNOTIFY:
\r
500 #endif // !_WIN32_WCE
\r
502 case WM_MEASUREITEM:
\r
503 case WM_COMPAREITEM:
\r
504 case WM_DELETEITEM:
\r
505 case WM_VKEYTOITEM:
\r
506 case WM_CHARTOITEM:
\r
509 case WM_CTLCOLORBTN:
\r
510 case WM_CTLCOLORDLG:
\r
511 case WM_CTLCOLOREDIT:
\r
512 case WM_CTLCOLORLISTBOX:
\r
513 case WM_CTLCOLORMSGBOX:
\r
514 case WM_CTLCOLORSCROLLBAR:
\r
515 case WM_CTLCOLORSTATIC:
\r
516 lResult = ::SendMessage(::GetParent(hWnd), uMsg, wParam, lParam);
\r
525 #endif // (_ATL_VER < 0x0700)
\r
527 }; // namespace WTL
\r
529 #endif // __ATLWINX_H__
\r