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