1 // Windows Template Library - WTL version 8.0
2 // Copyright (C) Microsoft Corporation. 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 // Microsoft Permissive License (Ms-PL) which can be found in the file
7 // Ms-PL.txt at the root of this distribution.
15 #error ATL requires C++ compilation (use a .cpp suffix)
19 #error atlwinx.h requires atlapp.h to be included first
22 #if (_ATL_VER >= 0x0700)
24 #endif // (_ATL_VER >= 0x0700)
27 ///////////////////////////////////////////////////////////////////////////////
28 // Classes in this file:
35 ///////////////////////////////////////////////////////////////////////////////
36 // Command Chaining Macros
38 #define CHAIN_COMMANDS(theChainClass) \
39 if(uMsg == WM_COMMAND) \
40 CHAIN_MSG_MAP(theChainClass)
42 #define CHAIN_COMMANDS_ALT(theChainClass, msgMapID) \
43 if(uMsg == WM_COMMAND) \
44 CHAIN_MSG_MAP_ALT(theChainClass, msgMapID)
46 #define CHAIN_COMMANDS_MEMBER(theChainMember) \
47 if(uMsg == WM_COMMAND) \
48 CHAIN_MSG_MAP_MEMBER(theChainMember)
50 #define CHAIN_COMMANDS_ALT_MEMBER(theChainMember, msgMapID) \
51 if(uMsg == WM_COMMAND) \
52 CHAIN_MSG_MAP_ALT_MEMBER(theChainMember, msgMapID)
55 ///////////////////////////////////////////////////////////////////////////////
56 // Macros for parent message map to selectively reflect control messages
58 // NOTE: ReflectNotifications is a member of ATL's CWindowImplRoot
59 // (and overridden in 2 cases - CContainedWindowT and CAxHostWindow)
60 // Since we can't modify ATL, we'll provide the needed additions
61 // in a separate function (that is not a member of CWindowImplRoot)
66 inline LRESULT
WtlReflectNotificationsFiltered(HWND hWndParent
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
,
67 UINT uMsgFilter
= WM_NULL
, UINT_PTR idFromFilter
= 0, HWND hWndChildFilter
= NULL
)
69 if((uMsgFilter
!= WM_NULL
) && (uMsgFilter
!= uMsg
))
71 // The notification message doesn't match the filter.
76 HWND hWndChild
= NULL
;
82 if(lParam
!= NULL
) // not from a menu
84 hWndChild
= (HWND
)lParam
;
85 idFrom
= (UINT_PTR
)LOWORD(wParam
);
89 hWndChild
= ((LPNMHDR
)lParam
)->hwndFrom
;
90 idFrom
= ((LPNMHDR
)lParam
)->idFrom
;
94 switch(LOWORD(wParam
))
98 hWndChild
= (HWND
)lParam
;
99 idFrom
= (UINT_PTR
)HIWORD(wParam
);
102 hWndChild
= ::GetDlgItem(hWndParent
, HIWORD(wParam
));
103 idFrom
= (UINT_PTR
)::GetDlgCtrlID(hWndChild
);
107 #endif // !_WIN32_WCE
109 if(wParam
) // not from a menu
111 hWndChild
= ((LPDRAWITEMSTRUCT
)lParam
)->hwndItem
;
112 idFrom
= (UINT_PTR
)wParam
;
116 if(wParam
) // not from a menu
118 hWndChild
= ::GetDlgItem(hWndParent
, ((LPMEASUREITEMSTRUCT
)lParam
)->CtlID
);
119 idFrom
= (UINT_PTR
)wParam
;
123 if(wParam
) // not from a menu
125 hWndChild
= ((LPCOMPAREITEMSTRUCT
)lParam
)->hwndItem
;
126 idFrom
= (UINT_PTR
)wParam
;
130 if(wParam
) // not from a menu
132 hWndChild
= ((LPDELETEITEMSTRUCT
)lParam
)->hwndItem
;
133 idFrom
= (UINT_PTR
)wParam
;
140 hWndChild
= (HWND
)lParam
;
141 idFrom
= (UINT_PTR
)::GetDlgCtrlID(hWndChild
);
145 case WM_CTLCOLOREDIT
:
146 case WM_CTLCOLORLISTBOX
:
147 case WM_CTLCOLORMSGBOX
:
148 case WM_CTLCOLORSCROLLBAR
:
149 case WM_CTLCOLORSTATIC
:
150 hWndChild
= (HWND
)lParam
;
151 idFrom
= (UINT_PTR
)::GetDlgCtrlID(hWndChild
);
157 if((hWndChild
== NULL
) ||
158 ((hWndChildFilter
!= NULL
) && (hWndChildFilter
!= hWndChild
)))
160 // Either hWndChild isn't valid, or
161 // hWndChild doesn't match the filter.
166 if((idFromFilter
!= 0) && (idFromFilter
!= idFrom
))
168 // The dialog control id doesn't match the filter.
173 ATLASSERT(::IsWindow(hWndChild
));
174 LRESULT lResult
= ::SendMessage(hWndChild
, OCM__BASE
+ uMsg
, wParam
, lParam
);
175 if((lResult
== 0) && (uMsg
>= WM_CTLCOLORMSGBOX
) && (uMsg
<= WM_CTLCOLORSTATIC
))
177 // Try to prevent problems with WM_CTLCOLOR* messages when
178 // the message wasn't really handled
187 // Try to prevent problems with WM_CTLCOLOR* messages when
188 // the message wasn't really handled
189 #define REFLECT_NOTIFICATIONS_EX() \
192 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
193 if((lResult == 0) && (uMsg >= WM_CTLCOLORMSGBOX) && (uMsg <= WM_CTLCOLORSTATIC)) \
199 #define REFLECT_NOTIFICATIONS_MSG_FILTERED(uMsgFilter) \
202 lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, 0, NULL); \
207 #define REFLECT_NOTIFICATIONS_ID_FILTERED(idFromFilter) \
210 lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, WM_NULL, idFromFilter, NULL); \
215 #define REFLECT_NOTIFICATIONS_HWND_FILTERED(hWndChildFilter) \
218 lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, WM_NULL, 0, hWndChildFilter); \
223 #define REFLECT_NOTIFICATIONS_MSG_ID_FILTERED(uMsgFilter, idFromFilter) \
226 lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, idFromFilter, NULL); \
231 #define REFLECT_NOTIFICATIONS_MSG_HWND_FILTERED(uMsgFilter, hWndChildFilter) \
234 lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, 0, hWndChildFilter); \
239 #define REFLECT_COMMAND(id, code) \
240 if(uMsg == WM_COMMAND && id == LOWORD(wParam) && code == HIWORD(wParam)) \
243 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
248 #define REFLECT_COMMAND_ID(id) \
249 if(uMsg == WM_COMMAND && id == LOWORD(wParam)) \
252 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
257 #define REFLECT_COMMAND_CODE(code) \
258 if(uMsg == WM_COMMAND && code == HIWORD(wParam)) \
261 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
266 #define REFLECT_COMMAND_RANGE(idFirst, idLast) \
267 if(uMsg == WM_COMMAND && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
270 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
275 #define REFLECT_COMMAND_RANGE_CODE(idFirst, idLast, code) \
276 if(uMsg == WM_COMMAND && code == HIWORD(wParam) && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
279 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
284 #define REFLECT_NOTIFY(id, cd) \
285 if(uMsg == WM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom && cd == ((LPNMHDR)lParam)->code) \
288 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
293 #define REFLECT_NOTIFY_ID(id) \
294 if(uMsg == WM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom) \
297 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
302 #define REFLECT_NOTIFY_CODE(cd) \
303 if(uMsg == WM_NOTIFY && cd == ((LPNMHDR)lParam)->code) \
306 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
311 #define REFLECT_NOTIFY_RANGE(idFirst, idLast) \
312 if(uMsg == WM_NOTIFY && ((LPNMHDR)lParam)->idFrom >= idFirst && ((LPNMHDR)lParam)->idFrom <= idLast) \
315 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
320 #define REFLECT_NOTIFY_RANGE_CODE(idFirst, idLast, cd) \
321 if(uMsg == WM_NOTIFY && cd == ((LPNMHDR)lParam)->code && ((LPNMHDR)lParam)->idFrom >= idFirst && ((LPNMHDR)lParam)->idFrom <= idLast) \
324 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
330 ///////////////////////////////////////////////////////////////////////////////
331 // Reflected message handler macros for message maps (for ATL 3.0)
333 #if (_ATL_VER < 0x0700)
335 #define REFLECTED_COMMAND_HANDLER(id, code, func) \
336 if(uMsg == OCM_COMMAND && id == LOWORD(wParam) && code == HIWORD(wParam)) \
339 lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
344 #define REFLECTED_COMMAND_ID_HANDLER(id, func) \
345 if(uMsg == OCM_COMMAND && id == LOWORD(wParam)) \
348 lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
353 #define REFLECTED_COMMAND_CODE_HANDLER(code, func) \
354 if(uMsg == OCM_COMMAND && code == HIWORD(wParam)) \
357 lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
362 #define REFLECTED_COMMAND_RANGE_HANDLER(idFirst, idLast, func) \
363 if(uMsg == OCM_COMMAND && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
366 lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
371 #define REFLECTED_COMMAND_RANGE_CODE_HANDLER(idFirst, idLast, code, func) \
372 if(uMsg == OCM_COMMAND && code == HIWORD(wParam) && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
375 lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
380 #define REFLECTED_NOTIFY_HANDLER(id, cd, func) \
381 if(uMsg == OCM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom && cd == ((LPNMHDR)lParam)->code) \
384 lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
389 #define REFLECTED_NOTIFY_ID_HANDLER(id, func) \
390 if(uMsg == OCM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom) \
393 lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
398 #define REFLECTED_NOTIFY_CODE_HANDLER(cd, func) \
399 if(uMsg == OCM_NOTIFY && cd == ((LPNMHDR)lParam)->code) \
402 lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
407 #define REFLECTED_NOTIFY_RANGE_HANDLER(idFirst, idLast, func) \
408 if(uMsg == OCM_NOTIFY && ((LPNMHDR)lParam)->idFrom >= idFirst && ((LPNMHDR)lParam)->idFrom <= idLast) \
411 lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
416 #define REFLECTED_NOTIFY_RANGE_CODE_HANDLER(idFirst, idLast, cd, func) \
417 if(uMsg == OCM_NOTIFY && cd == ((LPNMHDR)lParam)->code && ((LPNMHDR)lParam)->idFrom >= idFirst && ((LPNMHDR)lParam)->idFrom <= idLast) \
420 lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
425 #endif // (_ATL_VER < 0x0700)
428 ///////////////////////////////////////////////////////////////////////////////
429 // Dual argument helper classes (for ATL 3.0)
431 #if (_ATL_VER < 0x0700)
439 _U_RECT(LPRECT lpRect
) : m_lpRect(lpRect
)
441 _U_RECT(RECT
& rc
) : m_lpRect(&rc
)
449 _U_MENUorID(HMENU hMenu
) : m_hMenu(hMenu
)
451 _U_MENUorID(UINT nID
) : m_hMenu((HMENU
)LongToHandle(nID
))
459 _U_STRINGorID(LPCTSTR lpString
) : m_lpstr(lpString
)
461 _U_STRINGorID(UINT nID
) : m_lpstr(MAKEINTRESOURCE(nID
))
468 #endif // (_ATL_VER < 0x0700)
474 ///////////////////////////////////////////////////////////////////////////////
475 // Forward notifications support for message maps (for ATL 3.0)
477 #if (_ATL_VER < 0x0700)
479 // forward notifications support
480 #define FORWARD_NOTIFICATIONS() \
483 lResult = WTL::Atl3ForwardNotifications(m_hWnd, uMsg, wParam, lParam, bHandled); \
488 static LRESULT
Atl3ForwardNotifications(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
496 case WM_PARENTNOTIFY
:
497 #endif // !_WIN32_WCE
508 case WM_CTLCOLOREDIT
:
509 case WM_CTLCOLORLISTBOX
:
510 case WM_CTLCOLORMSGBOX
:
511 case WM_CTLCOLORSCROLLBAR
:
512 case WM_CTLCOLORSTATIC
:
513 lResult
= ::SendMessage(::GetParent(hWnd
), uMsg
, wParam
, lParam
);
522 #endif // (_ATL_VER < 0x0700)
526 #endif // __ATLWINX_H__