1 // Windows Template Library - WTL version 9.0
2 // Copyright (C) Microsoft Corporation, WTL Team. All rights reserved.
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.
18 #error atlwinx.h requires atlapp.h to be included first
21 #if (_ATL_VER >= 0x0700)
23 #endif // (_ATL_VER >= 0x0700)
26 ///////////////////////////////////////////////////////////////////////////////
27 // Classes in this file:
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)
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.
75 HWND hWndChild
= NULL
;
81 if(lParam
!= NULL
) // not from a menu
83 hWndChild
= (HWND
)lParam
;
84 idFrom
= (UINT_PTR
)LOWORD(wParam
);
88 hWndChild
= ((LPNMHDR
)lParam
)->hwndFrom
;
89 idFrom
= ((LPNMHDR
)lParam
)->idFrom
;
93 switch(LOWORD(wParam
))
97 hWndChild
= (HWND
)lParam
;
98 idFrom
= (UINT_PTR
)HIWORD(wParam
);
101 hWndChild
= ::GetDlgItem(hWndParent
, HIWORD(wParam
));
102 idFrom
= (UINT_PTR
)::GetDlgCtrlID(hWndChild
);
106 #endif // !_WIN32_WCE
108 if(wParam
) // not from a menu
110 hWndChild
= ((LPDRAWITEMSTRUCT
)lParam
)->hwndItem
;
111 idFrom
= (UINT_PTR
)wParam
;
115 if(wParam
) // not from a menu
117 hWndChild
= ::GetDlgItem(hWndParent
, ((LPMEASUREITEMSTRUCT
)lParam
)->CtlID
);
118 idFrom
= (UINT_PTR
)wParam
;
122 if(wParam
) // not from a menu
124 hWndChild
= ((LPCOMPAREITEMSTRUCT
)lParam
)->hwndItem
;
125 idFrom
= (UINT_PTR
)wParam
;
129 if(wParam
) // not from a menu
131 hWndChild
= ((LPDELETEITEMSTRUCT
)lParam
)->hwndItem
;
132 idFrom
= (UINT_PTR
)wParam
;
139 hWndChild
= (HWND
)lParam
;
140 idFrom
= (UINT_PTR
)::GetDlgCtrlID(hWndChild
);
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
);
156 if((hWndChild
== NULL
) ||
157 ((hWndChildFilter
!= NULL
) && (hWndChildFilter
!= hWndChild
)))
159 // Either hWndChild isn't valid, or
160 // hWndChild doesn't match the filter.
165 if((idFromFilter
!= 0) && (idFromFilter
!= idFrom
))
167 // The dialog control id doesn't match the filter.
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
186 // Try to prevent problems with WM_CTLCOLOR* messages when
187 // the message wasn't really handled
188 #define REFLECT_NOTIFICATIONS_EX() \
191 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
192 if((lResult == 0) && (uMsg >= WM_CTLCOLORMSGBOX) && (uMsg <= WM_CTLCOLORSTATIC)) \
198 #define REFLECT_NOTIFICATIONS_MSG_FILTERED(uMsgFilter) \
201 lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, 0, NULL); \
206 #define REFLECT_NOTIFICATIONS_ID_FILTERED(idFromFilter) \
209 lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, WM_NULL, idFromFilter, NULL); \
214 #define REFLECT_NOTIFICATIONS_HWND_FILTERED(hWndChildFilter) \
217 lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, WM_NULL, 0, hWndChildFilter); \
222 #define REFLECT_NOTIFICATIONS_MSG_ID_FILTERED(uMsgFilter, idFromFilter) \
225 lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, idFromFilter, NULL); \
230 #define REFLECT_NOTIFICATIONS_MSG_HWND_FILTERED(uMsgFilter, hWndChildFilter) \
233 lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, 0, hWndChildFilter); \
238 #define REFLECT_COMMAND(id, code) \
239 if(uMsg == WM_COMMAND && id == LOWORD(wParam) && code == HIWORD(wParam)) \
242 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
247 #define REFLECT_COMMAND_ID(id) \
248 if(uMsg == WM_COMMAND && id == LOWORD(wParam)) \
251 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
256 #define REFLECT_COMMAND_CODE(code) \
257 if(uMsg == WM_COMMAND && code == HIWORD(wParam)) \
260 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
265 #define REFLECT_COMMAND_RANGE(idFirst, idLast) \
266 if(uMsg == WM_COMMAND && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
269 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
274 #define REFLECT_COMMAND_RANGE_CODE(idFirst, idLast, code) \
275 if(uMsg == WM_COMMAND && code == HIWORD(wParam) && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
278 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
283 #define REFLECT_NOTIFY(id, cd) \
284 if(uMsg == WM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom && cd == ((LPNMHDR)lParam)->code) \
287 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
292 #define REFLECT_NOTIFY_ID(id) \
293 if(uMsg == WM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom) \
296 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
301 #define REFLECT_NOTIFY_CODE(cd) \
302 if(uMsg == WM_NOTIFY && cd == ((LPNMHDR)lParam)->code) \
305 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
310 #define REFLECT_NOTIFY_RANGE(idFirst, idLast) \
311 if(uMsg == WM_NOTIFY && ((LPNMHDR)lParam)->idFrom >= idFirst && ((LPNMHDR)lParam)->idFrom <= idLast) \
314 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
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) \
323 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
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)) \
338 lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
343 #define REFLECTED_COMMAND_ID_HANDLER(id, func) \
344 if(uMsg == OCM_COMMAND && id == LOWORD(wParam)) \
347 lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
352 #define REFLECTED_COMMAND_CODE_HANDLER(code, func) \
353 if(uMsg == OCM_COMMAND && code == HIWORD(wParam)) \
356 lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
361 #define REFLECTED_COMMAND_RANGE_HANDLER(idFirst, idLast, func) \
362 if(uMsg == OCM_COMMAND && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
365 lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
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) \
374 lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
379 #define REFLECTED_NOTIFY_HANDLER(id, cd, func) \
380 if(uMsg == OCM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom && cd == ((LPNMHDR)lParam)->code) \
383 lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
388 #define REFLECTED_NOTIFY_ID_HANDLER(id, func) \
389 if(uMsg == OCM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom) \
392 lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
397 #define REFLECTED_NOTIFY_CODE_HANDLER(cd, func) \
398 if(uMsg == OCM_NOTIFY && cd == ((LPNMHDR)lParam)->code) \
401 lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
406 #define REFLECTED_NOTIFY_RANGE_HANDLER(idFirst, idLast, func) \
407 if(uMsg == OCM_NOTIFY && ((LPNMHDR)lParam)->idFrom >= idFirst && ((LPNMHDR)lParam)->idFrom <= idLast) \
410 lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
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) \
419 lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
424 #endif // (_ATL_VER < 0x0700)
427 ///////////////////////////////////////////////////////////////////////////////
428 // Dual argument helper classes (for ATL 3.0)
430 #if (_ATL_VER < 0x0700)
438 _U_RECT(LPRECT lpRect
) : m_lpRect(lpRect
)
440 _U_RECT(RECT
& rc
) : m_lpRect(&rc
)
448 _U_MENUorID(HMENU hMenu
) : m_hMenu(hMenu
)
450 _U_MENUorID(UINT nID
) : m_hMenu((HMENU
)LongToHandle(nID
))
458 _U_STRINGorID(LPCTSTR lpString
) : m_lpstr(lpString
)
460 _U_STRINGorID(UINT nID
) : m_lpstr(MAKEINTRESOURCE(nID
))
467 #endif // (_ATL_VER < 0x0700)
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() \
482 lResult = WTL::Atl3ForwardNotifications(m_hWnd, uMsg, wParam, lParam, bHandled); \
487 static LRESULT
Atl3ForwardNotifications(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
495 case WM_PARENTNOTIFY
:
496 #endif // !_WIN32_WCE
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
);
521 #endif // (_ATL_VER < 0x0700)
525 #endif // __ATLWINX_H__