• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtrubybathyscaphegamephpguicwindows翻訳pythonomegattwitterframeworkbtronarduinovb.net計画中(planning stage)directxpreviewertestゲームエンジンdom

Commit MetaInfo

Revisiondbe50635fbc145acfc695a9079d4d947967ecbc9 (tree)
Time2012-01-20 09:14:52
Authorunknown <qwerty2501@user...>
Commiterunknown

Log Message

2012/01/20 9:14:52

Change Summary

Incremental Difference

--- /dev/null
+++ b/include/WTL/Include/atlapp.h
@@ -0,0 +1,2035 @@
1+// Windows Template Library - WTL version 8.1
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+// 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.
11+
12+#ifndef __ATLAPP_H__
13+#define __ATLAPP_H__
14+
15+#pragma once
16+
17+#ifndef __cplusplus
18+ #error WTL requires C++ compilation (use a .cpp suffix)
19+#endif
20+
21+#ifndef __ATLBASE_H__
22+ #error atlapp.h requires atlbase.h to be included first
23+#endif
24+
25+#ifndef _WIN32_WCE
26+ #if (WINVER < 0x0400)
27+ #error WTL requires Windows version 4.0 or higher
28+ #endif
29+
30+ #if (_WIN32_IE < 0x0300)
31+ #error WTL requires IE version 3.0 or higher
32+ #endif
33+#endif
34+
35+#ifdef _ATL_NO_COMMODULE
36+ #error WTL requires that _ATL_NO_COMMODULE is not defined
37+#endif
38+
39+#if (_ATL_VER >= 0x0900) && defined(_ATL_MIN_CRT)
40+ #error _ATL_MIN_CRT is not supported with ATL 9.0 and higher
41+#endif
42+
43+#if defined(_WIN32_WCE) && defined(_ATL_MIN_CRT)
44+ #pragma message("Warning: WTL for Windows CE doesn't use _ATL_MIN_CRT")
45+#endif
46+
47+#include <limits.h>
48+#if !defined(_ATL_MIN_CRT) && defined(_MT) && !defined(_WIN32_WCE)
49+ #include <process.h> // for _beginthreadex
50+#endif
51+
52+#if (_ATL_VER < 0x0800) && !defined(_DEBUG)
53+ #include <stdio.h>
54+#endif
55+
56+#include <commctrl.h>
57+#ifndef _WIN32_WCE
58+ #pragma comment(lib, "comctl32.lib")
59+#endif
60+
61+#ifndef _WIN32_WCE
62+ #include "atlres.h"
63+#else // CE specific
64+ #include "atlresce.h"
65+#endif // _WIN32_WCE
66+
67+// We need to disable this warning because of template class arguments
68+#pragma warning(disable: 4127)
69+
70+#if (_ATL_VER >= 0x0900) && !defined(_SECURE_ATL)
71+ #define _SECURE_ATL 1
72+#endif
73+
74+
75+///////////////////////////////////////////////////////////////////////////////
76+// WTL version number
77+
78+#define _WTL_VER 0x0810
79+
80+
81+///////////////////////////////////////////////////////////////////////////////
82+// Classes in this file:
83+//
84+// CMessageFilter
85+// CIdleHandler
86+// CMessageLoop
87+//
88+// CAppModule
89+// CServerAppModule
90+//
91+// CRegKeyEx
92+//
93+// Global functions:
94+// AtlGetDefaultGuiFont()
95+// AtlCreateControlFont()
96+// AtlCreateBoldFont()
97+// AtlInitCommonControls()
98+
99+
100+///////////////////////////////////////////////////////////////////////////////
101+// Global support for Windows CE
102+
103+#ifdef _WIN32_WCE
104+
105+#ifndef SW_SHOWDEFAULT
106+ #define SW_SHOWDEFAULT SW_SHOWNORMAL
107+#endif // !SW_SHOWDEFAULT
108+
109+// These get's OR-ed in a constant and will have no effect.
110+// Defining them reduces the number of #ifdefs required for CE.
111+#define LR_DEFAULTSIZE 0
112+#define LR_LOADFROMFILE 0
113+
114+#ifndef SM_CXCURSOR
115+ #define SM_CXCURSOR 13
116+#endif
117+#ifndef SM_CYCURSOR
118+ #define SM_CYCURSOR 14
119+#endif
120+
121+inline BOOL IsMenu(HMENU hMenu)
122+{
123+ MENUITEMINFO mii = { sizeof(MENUITEMINFO) };
124+ ::SetLastError(0);
125+ BOOL bRet = ::GetMenuItemInfo(hMenu, 0, TRUE, &mii);
126+ if(!bRet)
127+ bRet = (::GetLastError() != ERROR_INVALID_MENU_HANDLE) ? TRUE : FALSE;
128+ return bRet;
129+}
130+
131+#if (_WIN32_WCE >= 410)
132+extern "C" void WINAPI ListView_SetItemSpacing(HWND hwndLV, int iHeight);
133+#endif // (_WIN32_WCE >= 410)
134+
135+inline int MulDiv(IN int nNumber, IN int nNumerator, IN int nDenominator)
136+{
137+ __int64 multiple = nNumber * nNumerator;
138+ return static_cast<int>(multiple / nDenominator);
139+}
140+
141+#if (_ATL_VER >= 0x0800)
142+
143+#ifndef _WTL_KEEP_WS_OVERLAPPEDWINDOW
144+ #ifdef WS_OVERLAPPEDWINDOW
145+ #undef WS_OVERLAPPEDWINDOW
146+ #define WS_OVERLAPPEDWINDOW 0
147+ #endif // WS_OVERLAPPEDWINDOW
148+#endif // !_WTL_KEEP_WS_OVERLAPPEDWINDOW
149+
150+#ifndef RDW_FRAME
151+ #define RDW_FRAME 0
152+#endif // !RDW_FRAME
153+
154+#ifndef WM_WINDOWPOSCHANGING
155+ #define WM_WINDOWPOSCHANGING 0
156+#endif // !WM_WINDOWPOSCHANGING
157+
158+#define FreeResource(x)
159+#define UnlockResource(x)
160+
161+namespace ATL
162+{
163+ inline HRESULT CComModule::RegisterClassObjects(DWORD /*dwClsContext*/, DWORD /*dwFlags*/) throw()
164+ { return E_NOTIMPL; }
165+ inline HRESULT CComModule::RevokeClassObjects() throw()
166+ { return E_NOTIMPL; }
167+}; // namespace ATL
168+
169+#ifndef lstrlenW
170+ #define lstrlenW (int)ATL::lstrlenW
171+#endif // lstrlenW
172+
173+inline int WINAPI lstrlenA(LPCSTR lpszString)
174+{ return ATL::lstrlenA(lpszString); }
175+
176+#ifdef lstrcpyn
177+ #undef lstrcpyn
178+ #define lstrcpyn ATL::lstrcpynW
179+#endif // lstrcpyn
180+
181+#ifndef SetWindowLongPtrW
182+ inline LONG_PTR tmp_SetWindowLongPtrW( HWND hWnd, int nIndex, LONG_PTR dwNewLong )
183+ {
184+ return( ::SetWindowLongW( hWnd, nIndex, LONG( dwNewLong ) ) );
185+ }
186+ #define SetWindowLongPtrW tmp_SetWindowLongPtrW
187+#endif
188+
189+#ifndef GetWindowLongPtrW
190+ inline LONG_PTR tmp_GetWindowLongPtrW( HWND hWnd, int nIndex )
191+ {
192+ return( ::GetWindowLongW( hWnd, nIndex ) );
193+ }
194+ #define GetWindowLongPtrW tmp_GetWindowLongPtrW
195+#endif
196+
197+#ifndef LongToPtr
198+ #define LongToPtr(x) ((void*)x)
199+#endif
200+
201+#ifndef PtrToInt
202+ #define PtrToInt( p ) ((INT)(INT_PTR) (p) )
203+#endif
204+
205+#else // !(_ATL_VER >= 0x0800)
206+
207+#ifdef lstrlenW
208+ #undef lstrlenW
209+ #define lstrlenW (int)::wcslen
210+#endif // lstrlenW
211+
212+#define lstrlenA (int)strlen
213+
214+#ifndef lstrcpyn
215+ inline LPTSTR lstrcpyn(LPTSTR lpstrDest, LPCTSTR lpstrSrc, int nLength)
216+ {
217+ if(lpstrDest == NULL || lpstrSrc == NULL || nLength <= 0)
218+ return NULL;
219+ int nLen = min(lstrlen(lpstrSrc), nLength - 1);
220+ LPTSTR lpstrRet = (LPTSTR)memcpy(lpstrDest, lpstrSrc, nLen * sizeof(TCHAR));
221+ lpstrDest[nLen] = 0;
222+ return lpstrRet;
223+ }
224+#endif // !lstrcpyn
225+
226+#ifndef lstrcpynW
227+ inline LPWSTR lstrcpynW(LPWSTR lpstrDest, LPCWSTR lpstrSrc, int nLength)
228+ {
229+ return lstrcpyn(lpstrDest, lpstrSrc, nLength); // WinCE is Unicode only
230+ }
231+#endif // !lstrcpynW
232+
233+#ifndef lstrcpynA
234+ inline LPSTR lstrcpynA(LPSTR lpstrDest, LPCSTR lpstrSrc, int nLength)
235+ {
236+ if(lpstrDest == NULL || lpstrSrc == NULL || nLength <= 0)
237+ return NULL;
238+ int nLen = min(lstrlenA(lpstrSrc), nLength - 1);
239+ LPSTR lpstrRet = (LPSTR)memcpy(lpstrDest, lpstrSrc, nLen * sizeof(char));
240+ lpstrDest[nLen] = 0;
241+ return lpstrRet;
242+ }
243+#endif // !lstrcpyn
244+
245+#ifdef TrackPopupMenu
246+ #undef TrackPopupMenu
247+#endif // TrackPopupMenu
248+
249+#define DECLARE_WND_CLASS_EX(WndClassName, style, bkgnd) \
250+static CWndClassInfo& GetWndClassInfo() \
251+{ \
252+ static CWndClassInfo wc = \
253+ { \
254+ { style, StartWindowProc, \
255+ 0, 0, NULL, NULL, NULL, (HBRUSH)(bkgnd + 1), NULL, WndClassName }, \
256+ NULL, NULL, IDC_ARROW, TRUE, 0, _T("") \
257+ }; \
258+ return wc; \
259+}
260+
261+#ifndef _MAX_FNAME
262+ #define _MAX_FNAME _MAX_PATH
263+#endif // _MAX_FNAME
264+
265+#if (_WIN32_WCE < 400)
266+ #define MAKEINTATOM(i) (LPTSTR)((ULONG_PTR)((WORD)(i)))
267+#endif // (_WIN32_WCE < 400)
268+
269+#if (_WIN32_WCE < 410)
270+ #define WHEEL_PAGESCROLL (UINT_MAX)
271+ #define WHEEL_DELTA 120
272+#endif // (_WIN32_WCE < 410)
273+
274+#ifdef DrawIcon
275+ #undef DrawIcon
276+#endif
277+
278+#ifndef VARCMP_LT
279+ #define VARCMP_LT 0
280+#endif
281+#ifndef VARCMP_EQ
282+ #define VARCMP_EQ 1
283+#endif
284+#ifndef VARCMP_GT
285+ #define VARCMP_GT 2
286+#endif
287+#ifndef VARCMP_NULL
288+ #define VARCMP_NULL 3
289+#endif
290+
291+#ifndef RDW_ALLCHILDREN
292+ #define RDW_ALLCHILDREN 0
293+#endif
294+
295+#endif // !(_ATL_VER >= 0x0800)
296+
297+#endif // _WIN32_WCE
298+
299+
300+///////////////////////////////////////////////////////////////////////////////
301+// Global support for using original VC++ 6.0 headers with WTL
302+
303+#ifndef _ATL_NO_OLD_HEADERS_WIN64
304+#if !defined(_WIN64) && (_ATL_VER < 0x0700)
305+
306+ #ifndef PSM_INSERTPAGE
307+ #define PSM_INSERTPAGE (WM_USER + 119)
308+ #endif // !PSM_INSERTPAGE
309+
310+ #ifndef GetClassLongPtr
311+ #define GetClassLongPtrA GetClassLongA
312+ #define GetClassLongPtrW GetClassLongW
313+ #ifdef UNICODE
314+ #define GetClassLongPtr GetClassLongPtrW
315+ #else
316+ #define GetClassLongPtr GetClassLongPtrA
317+ #endif // !UNICODE
318+ #endif // !GetClassLongPtr
319+
320+ #ifndef GCLP_HICONSM
321+ #define GCLP_HICONSM (-34)
322+ #endif // !GCLP_HICONSM
323+
324+ #ifndef GetWindowLongPtr
325+ #define GetWindowLongPtrA GetWindowLongA
326+ #define GetWindowLongPtrW GetWindowLongW
327+ #ifdef UNICODE
328+ #define GetWindowLongPtr GetWindowLongPtrW
329+ #else
330+ #define GetWindowLongPtr GetWindowLongPtrA
331+ #endif // !UNICODE
332+ #endif // !GetWindowLongPtr
333+
334+ #ifndef SetWindowLongPtr
335+ #define SetWindowLongPtrA SetWindowLongA
336+ #define SetWindowLongPtrW SetWindowLongW
337+ #ifdef UNICODE
338+ #define SetWindowLongPtr SetWindowLongPtrW
339+ #else
340+ #define SetWindowLongPtr SetWindowLongPtrA
341+ #endif // !UNICODE
342+ #endif // !SetWindowLongPtr
343+
344+ #ifndef GWLP_WNDPROC
345+ #define GWLP_WNDPROC (-4)
346+ #endif
347+ #ifndef GWLP_HINSTANCE
348+ #define GWLP_HINSTANCE (-6)
349+ #endif
350+ #ifndef GWLP_HWNDPARENT
351+ #define GWLP_HWNDPARENT (-8)
352+ #endif
353+ #ifndef GWLP_USERDATA
354+ #define GWLP_USERDATA (-21)
355+ #endif
356+ #ifndef GWLP_ID
357+ #define GWLP_ID (-12)
358+ #endif
359+
360+ #ifndef DWLP_MSGRESULT
361+ #define DWLP_MSGRESULT 0
362+ #endif
363+
364+ typedef long LONG_PTR;
365+ typedef unsigned long ULONG_PTR;
366+ typedef ULONG_PTR DWORD_PTR;
367+
368+ #ifndef HandleToUlong
369+ #define HandleToUlong( h ) ((ULONG)(ULONG_PTR)(h) )
370+ #endif
371+ #ifndef HandleToLong
372+ #define HandleToLong( h ) ((LONG)(LONG_PTR) (h) )
373+ #endif
374+ #ifndef LongToHandle
375+ #define LongToHandle( h) ((HANDLE)(LONG_PTR) (h))
376+ #endif
377+ #ifndef PtrToUlong
378+ #define PtrToUlong( p ) ((ULONG)(ULONG_PTR) (p) )
379+ #endif
380+ #ifndef PtrToLong
381+ #define PtrToLong( p ) ((LONG)(LONG_PTR) (p) )
382+ #endif
383+ #ifndef PtrToUint
384+ #define PtrToUint( p ) ((UINT)(UINT_PTR) (p) )
385+ #endif
386+ #ifndef PtrToInt
387+ #define PtrToInt( p ) ((INT)(INT_PTR) (p) )
388+ #endif
389+ #ifndef PtrToUshort
390+ #define PtrToUshort( p ) ((unsigned short)(ULONG_PTR)(p) )
391+ #endif
392+ #ifndef PtrToShort
393+ #define PtrToShort( p ) ((short)(LONG_PTR)(p) )
394+ #endif
395+ #ifndef IntToPtr
396+ #define IntToPtr( i ) ((VOID *)(INT_PTR)((int)i))
397+ #endif
398+ #ifndef UIntToPtr
399+ #define UIntToPtr( ui ) ((VOID *)(UINT_PTR)((unsigned int)ui))
400+ #endif
401+ #ifndef LongToPtr
402+ #define LongToPtr( l ) ((VOID *)(LONG_PTR)((long)l))
403+ #endif
404+ #ifndef ULongToPtr
405+ #define ULongToPtr( ul ) ((VOID *)(ULONG_PTR)((unsigned long)ul))
406+ #endif
407+
408+#endif // !defined(_WIN64) && (_ATL_VER < 0x0700)
409+#endif // !_ATL_NO_OLD_HEADERS_WIN64
410+
411+
412+///////////////////////////////////////////////////////////////////////////////
413+// Global support for SecureHelper functions
414+
415+#ifndef _TRUNCATE
416+ #define _TRUNCATE ((size_t)-1)
417+#endif
418+
419+#ifndef _ERRCODE_DEFINED
420+ #define _ERRCODE_DEFINED
421+ typedef int errno_t;
422+#endif
423+
424+#ifndef _SECURECRT_ERRCODE_VALUES_DEFINED
425+ #define _SECURECRT_ERRCODE_VALUES_DEFINED
426+ #define EINVAL 22
427+ #define STRUNCATE 80
428+#endif
429+
430+#ifndef _countof
431+ #define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0]))
432+#endif
433+
434+
435+///////////////////////////////////////////////////////////////////////////////
436+// Miscellaneous global support
437+
438+// define useful macros from winuser.h
439+#ifndef IS_INTRESOURCE
440+ #define IS_INTRESOURCE(_r) (((ULONG_PTR)(_r) >> 16) == 0)
441+#endif // IS_INTRESOURCE
442+
443+// protect template members from windowsx.h macros
444+#ifdef _INC_WINDOWSX
445+ #undef SubclassWindow
446+#endif // _INC_WINDOWSX
447+
448+// define useful macros from windowsx.h
449+#ifndef GET_X_LPARAM
450+ #define GET_X_LPARAM(lParam) ((int)(short)LOWORD(lParam))
451+#endif
452+#ifndef GET_Y_LPARAM
453+ #define GET_Y_LPARAM(lParam) ((int)(short)HIWORD(lParam))
454+#endif
455+
456+// Dummy structs for compiling with /CLR
457+#if (_MSC_VER >= 1300) && defined(_MANAGED)
458+ __if_not_exists(_IMAGELIST::_IMAGELIST) { struct _IMAGELIST { }; }
459+ __if_not_exists(_TREEITEM::_TREEITEM) { struct _TREEITEM { }; }
460+ __if_not_exists(_PSP::_PSP) { struct _PSP { }; }
461+#endif
462+
463+// Define ATLVERIFY macro for ATL3
464+#if (_ATL_VER < 0x0700)
465+ #ifndef ATLVERIFY
466+ #ifdef _DEBUG
467+ #define ATLVERIFY(expr) ATLASSERT(expr)
468+ #else
469+ #define ATLVERIFY(expr) (expr)
470+ #endif // DEBUG
471+ #endif // ATLVERIFY
472+#endif // (_ATL_VER < 0x0700)
473+
474+// Forward declaration for ATL3 fix
475+#if (_ATL_VER < 0x0700) && defined(_ATL_DLL) && !defined(_WIN32_WCE)
476+ namespace ATL { HRESULT AtlGetCommCtrlVersion(LPDWORD pdwMajor, LPDWORD pdwMinor); };
477+#endif
478+
479+
480+namespace WTL
481+{
482+
483+#if (_ATL_VER >= 0x0700)
484+ DECLARE_TRACE_CATEGORY(atlTraceUI);
485+ #ifdef _DEBUG
486+ __declspec(selectany) ATL::CTraceCategory atlTraceUI(_T("atlTraceUI"));
487+ #endif // _DEBUG
488+#else // !(_ATL_VER >= 0x0700)
489+ enum wtlTraceFlags
490+ {
491+ atlTraceUI = 0x10000000
492+ };
493+#endif // !(_ATL_VER >= 0x0700)
494+
495+// Windows version helper
496+inline bool AtlIsOldWindows()
497+{
498+ OSVERSIONINFO ovi = { 0 };
499+ ovi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
500+ BOOL bRet = ::GetVersionEx(&ovi);
501+ return (!bRet || !((ovi.dwMajorVersion >= 5) || (ovi.dwMajorVersion == 4 && ovi.dwMinorVersion >= 90)));
502+}
503+
504+// Default GUI font helper - "MS Shell Dlg" stock font
505+inline HFONT AtlGetDefaultGuiFont()
506+{
507+#ifndef _WIN32_WCE
508+ return (HFONT)::GetStockObject(DEFAULT_GUI_FONT);
509+#else // CE specific
510+ return (HFONT)::GetStockObject(SYSTEM_FONT);
511+#endif // _WIN32_WCE
512+}
513+
514+// Control font helper - default font for controls not in a dialog
515+// (NOTE: Caller owns the font, and should destroy it when it's no longer needed)
516+inline HFONT AtlCreateControlFont()
517+{
518+#ifndef _WIN32_WCE
519+ LOGFONT lf = { 0 };
520+ ATLVERIFY(::SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(LOGFONT), &lf, 0) != FALSE);
521+ HFONT hFont = ::CreateFontIndirect(&lf);
522+ ATLASSERT(hFont != NULL);
523+ return hFont;
524+#else // CE specific
525+ return (HFONT)::GetStockObject(SYSTEM_FONT);
526+#endif // _WIN32_WCE
527+}
528+
529+// Bold font helper
530+// (NOTE: Caller owns the font, and should destroy it when it's no longer needed)
531+inline HFONT AtlCreateBoldFont(HFONT hFont = NULL)
532+{
533+ LOGFONT lf = { 0 };
534+#ifndef _WIN32_WCE
535+ if(hFont == NULL)
536+ ATLVERIFY(::SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(LOGFONT), &lf, 0) != FALSE);
537+ else
538+ ATLVERIFY(::GetObject(hFont, sizeof(LOGFONT), &lf) == sizeof(LOGFONT));
539+#else // CE specific
540+ if(hFont == NULL)
541+ hFont = (HFONT)::GetStockObject(SYSTEM_FONT);
542+ ATLVERIFY(::GetObject(hFont, sizeof(LOGFONT), &lf) == sizeof(LOGFONT));
543+#endif // _WIN32_WCE
544+ lf.lfWeight = FW_BOLD;
545+ HFONT hFontBold = ::CreateFontIndirect(&lf);
546+ ATLASSERT(hFontBold != NULL);
547+ return hFontBold;
548+}
549+
550+// Common Controls initialization helper
551+inline BOOL AtlInitCommonControls(DWORD dwFlags)
552+{
553+ INITCOMMONCONTROLSEX iccx = { sizeof(INITCOMMONCONTROLSEX), dwFlags };
554+ BOOL bRet = ::InitCommonControlsEx(&iccx);
555+ ATLASSERT(bRet);
556+ return bRet;
557+}
558+
559+
560+///////////////////////////////////////////////////////////////////////////////
561+// RunTimeHelper - helper functions for Windows version and structure sizes
562+
563+// Not for Windows CE
564+#if defined(_WIN32_WCE) && !defined(_WTL_NO_RUNTIME_STRUCT_SIZE)
565+ #define _WTL_NO_RUNTIME_STRUCT_SIZE
566+#endif
567+
568+#ifndef _WTL_NO_RUNTIME_STRUCT_SIZE
569+
570+#ifndef _SIZEOF_STRUCT
571+ #define _SIZEOF_STRUCT(structname, member) (((int)((LPBYTE)(&((structname*)0)->member) - ((LPBYTE)((structname*)0)))) + sizeof(((structname*)0)->member))
572+#endif
573+
574+#if (_WIN32_WINNT >= 0x0600) && !defined(REBARBANDINFO_V6_SIZE)
575+ #define REBARBANDINFO_V6_SIZE _SIZEOF_STRUCT(REBARBANDINFO, cxHeader)
576+#endif // (_WIN32_WINNT >= 0x0600) && !defined(REBARBANDINFO_V6_SIZE)
577+
578+#if (_WIN32_WINNT >= 0x0600) && !defined(LVGROUP_V5_SIZE)
579+ #define LVGROUP_V5_SIZE _SIZEOF_STRUCT(LVGROUP, uAlign)
580+#endif // (_WIN32_WINNT >= 0x0600) && !defined(LVGROUP_V5_SIZE)
581+
582+#if (_WIN32_WINNT >= 0x0600) && !defined(LVTILEINFO_V5_SIZE)
583+ #define LVTILEINFO_V5_SIZE _SIZEOF_STRUCT(LVTILEINFO, puColumns)
584+#endif // (_WIN32_WINNT >= 0x0600) && !defined(LVTILEINFO_V5_SIZE)
585+
586+#if defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN) && !defined(MCHITTESTINFO_V1_SIZE)
587+ #define MCHITTESTINFO_V1_SIZE _SIZEOF_STRUCT(MCHITTESTINFO, st)
588+#endif // defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN) && !defined(MCHITTESTINFO_V1_SIZE)
589+
590+#if !defined(_WIN32_WCE) && (WINVER >= 0x0600) && !defined(NONCLIENTMETRICS_V1_SIZE)
591+ #define NONCLIENTMETRICS_V1_SIZE _SIZEOF_STRUCT(NONCLIENTMETRICS, lfMessageFont)
592+#endif // !defined(_WIN32_WCE) && (WINVER >= 0x0600) && !defined(NONCLIENTMETRICS_V1_SIZE)
593+
594+#endif // !_WTL_NO_RUNTIME_STRUCT_SIZE
595+
596+namespace RunTimeHelper
597+{
598+#ifndef _WIN32_WCE
599+ inline bool IsCommCtrl6()
600+ {
601+ DWORD dwMajor = 0, dwMinor = 0;
602+ HRESULT hRet = ATL::AtlGetCommCtrlVersion(&dwMajor, &dwMinor);
603+ return (SUCCEEDED(hRet) && (dwMajor >= 6));
604+ }
605+
606+ inline bool IsVista()
607+ {
608+ OSVERSIONINFO ovi = { sizeof(OSVERSIONINFO) };
609+ BOOL bRet = ::GetVersionEx(&ovi);
610+ return ((bRet != FALSE) && (ovi.dwMajorVersion >= 6));
611+ }
612+
613+ inline bool IsThemeAvailable()
614+ {
615+ bool bRet = false;
616+
617+ if(IsCommCtrl6())
618+ {
619+ HMODULE hThemeDLL = ::LoadLibrary(_T("uxtheme.dll"));
620+ if(hThemeDLL != NULL)
621+ {
622+ typedef BOOL (STDAPICALLTYPE *PFN_IsThemeActive)();
623+ PFN_IsThemeActive pfnIsThemeActive = (PFN_IsThemeActive)::GetProcAddress(hThemeDLL, "IsThemeActive");
624+ ATLASSERT(pfnIsThemeActive != NULL);
625+ bRet = (pfnIsThemeActive != NULL) && (pfnIsThemeActive() != FALSE);
626+ if(bRet)
627+ {
628+ typedef BOOL (STDAPICALLTYPE *PFN_IsAppThemed)();
629+ PFN_IsAppThemed pfnIsAppThemed = (PFN_IsAppThemed)::GetProcAddress(hThemeDLL, "IsAppThemed");
630+ ATLASSERT(pfnIsAppThemed != NULL);
631+ bRet = (pfnIsAppThemed != NULL) && (pfnIsAppThemed() != FALSE);
632+ }
633+
634+ ::FreeLibrary(hThemeDLL);
635+ }
636+ }
637+
638+ return bRet;
639+ }
640+
641+ inline bool IsWin7()
642+ {
643+ OSVERSIONINFO ovi = { sizeof(OSVERSIONINFO) };
644+ BOOL bRet = ::GetVersionEx(&ovi);
645+ return ((bRet != FALSE) && (ovi.dwMajorVersion == 6) && (ovi.dwMinorVersion >= 1));
646+ }
647+
648+ inline bool IsRibbonUIAvailable()
649+ {
650+ static INT iRibbonUI = -1;
651+
652+#if defined(NTDDI_WIN7) && (NTDDI_VERSION >= NTDDI_WIN7)
653+ if (iRibbonUI == -1)
654+ {
655+ HMODULE hRibbonDLL = ::LoadLibrary(_T("propsys.dll"));
656+ if (hRibbonDLL != NULL)
657+ {
658+ const GUID CLSID_UIRibbonFramework = { 0x926749fa, 0x2615, 0x4987, { 0x88, 0x45, 0xc3, 0x3e, 0x65, 0xf2, 0xb9, 0x57 } };
659+ // block - create instance
660+ {
661+ ATL::CComPtr<IUnknown> pIUIFramework;
662+ iRibbonUI = SUCCEEDED(pIUIFramework.CoCreateInstance(CLSID_UIRibbonFramework)) ? 1 : 0;
663+ }
664+ ::FreeLibrary(hRibbonDLL);
665+ }
666+ else
667+ {
668+ iRibbonUI = 0;
669+ }
670+ }
671+#endif // defined(NTDDI_WIN7) && (NTDDI_VERSION >= NTDDI_WIN7)
672+
673+ return (iRibbonUI == 1);
674+ }
675+
676+#endif // !_WIN32_WCE
677+
678+ inline int SizeOf_REBARBANDINFO()
679+ {
680+ int nSize = sizeof(REBARBANDINFO);
681+#if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
682+ if(!(IsVista() && IsCommCtrl6()))
683+ nSize = REBARBANDINFO_V6_SIZE;
684+#endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
685+ return nSize;
686+ }
687+
688+#if (_WIN32_WINNT >= 0x501)
689+ inline int SizeOf_LVGROUP()
690+ {
691+ int nSize = sizeof(LVGROUP);
692+#if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
693+ if(!IsVista())
694+ nSize = LVGROUP_V5_SIZE;
695+#endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
696+ return nSize;
697+ }
698+
699+ inline int SizeOf_LVTILEINFO()
700+ {
701+ int nSize = sizeof(LVTILEINFO);
702+#if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
703+ if(!IsVista())
704+ nSize = LVTILEINFO_V5_SIZE;
705+#endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
706+ return nSize;
707+ }
708+#endif // (_WIN32_WINNT >= 0x501)
709+
710+ inline int SizeOf_MCHITTESTINFO()
711+ {
712+ int nSize = sizeof(MCHITTESTINFO);
713+#if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
714+ if(!(IsVista() && IsCommCtrl6()))
715+ nSize = MCHITTESTINFO_V1_SIZE;
716+#endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
717+ return nSize;
718+ }
719+
720+#ifndef _WIN32_WCE
721+ inline int SizeOf_NONCLIENTMETRICS()
722+ {
723+ int nSize = sizeof(NONCLIENTMETRICS);
724+#if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (WINVER >= 0x0600)
725+ if(!IsVista())
726+ nSize = NONCLIENTMETRICS_V1_SIZE;
727+#endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (WINVER >= 0x0600)
728+ return nSize;
729+ }
730+#endif // !_WIN32_WCE
731+};
732+
733+
734+///////////////////////////////////////////////////////////////////////////////
735+// ModuleHelper - helper functions for ATL3 and ATL7 module classes
736+
737+namespace ModuleHelper
738+{
739+ inline HINSTANCE GetModuleInstance()
740+ {
741+#if (_ATL_VER >= 0x0700)
742+ return ATL::_AtlBaseModule.GetModuleInstance();
743+#else // !(_ATL_VER >= 0x0700)
744+ return ATL::_pModule->GetModuleInstance();
745+#endif // !(_ATL_VER >= 0x0700)
746+ }
747+
748+ inline HINSTANCE GetResourceInstance()
749+ {
750+#if (_ATL_VER >= 0x0700)
751+ return ATL::_AtlBaseModule.GetResourceInstance();
752+#else // !(_ATL_VER >= 0x0700)
753+ return ATL::_pModule->GetResourceInstance();
754+#endif // !(_ATL_VER >= 0x0700)
755+ }
756+
757+ inline void AddCreateWndData(ATL::_AtlCreateWndData* pData, void* pObject)
758+ {
759+#if (_ATL_VER >= 0x0700)
760+ ATL::_AtlWinModule.AddCreateWndData(pData, pObject);
761+#else // !(_ATL_VER >= 0x0700)
762+ ATL::_pModule->AddCreateWndData(pData, pObject);
763+#endif // !(_ATL_VER >= 0x0700)
764+ }
765+
766+ inline void* ExtractCreateWndData()
767+ {
768+#if (_ATL_VER >= 0x0700)
769+ return ATL::_AtlWinModule.ExtractCreateWndData();
770+#else // !(_ATL_VER >= 0x0700)
771+ return ATL::_pModule->ExtractCreateWndData();
772+#endif // !(_ATL_VER >= 0x0700)
773+ }
774+};
775+
776+
777+///////////////////////////////////////////////////////////////////////////////
778+// SecureHelper - helper functions for VS2005 secure CRT
779+
780+namespace SecureHelper
781+{
782+ inline void strcpyA_x(char* lpstrDest, size_t cchDest, const char* lpstrSrc)
783+ {
784+#if _SECURE_ATL
785+ ATL::Checked::strcpy_s(lpstrDest, cchDest, lpstrSrc);
786+#else
787+ if(cchDest > (size_t)lstrlenA(lpstrSrc))
788+ ATLVERIFY(lstrcpyA(lpstrDest, lpstrSrc) != NULL);
789+ else
790+ ATLASSERT(FALSE);
791+#endif
792+ }
793+
794+ inline void strcpyW_x(wchar_t* lpstrDest, size_t cchDest, const wchar_t* lpstrSrc)
795+ {
796+#if _SECURE_ATL
797+ ATL::Checked::wcscpy_s(lpstrDest, cchDest, lpstrSrc);
798+#else
799+ if(cchDest > (size_t)lstrlenW(lpstrSrc))
800+ ATLVERIFY(lstrcpyW(lpstrDest, lpstrSrc) != NULL);
801+ else
802+ ATLASSERT(FALSE);
803+#endif
804+ }
805+
806+ inline void strcpy_x(LPTSTR lpstrDest, size_t cchDest, LPCTSTR lpstrSrc)
807+ {
808+#ifdef _UNICODE
809+ strcpyW_x(lpstrDest, cchDest, lpstrSrc);
810+#else
811+ strcpyA_x(lpstrDest, cchDest, lpstrSrc);
812+#endif
813+ }
814+
815+ inline errno_t strncpyA_x(char* lpstrDest, size_t cchDest, const char* lpstrSrc, size_t cchCount)
816+ {
817+#if _SECURE_ATL
818+ return ATL::Checked::strncpy_s(lpstrDest, cchDest, lpstrSrc, cchCount);
819+#else
820+ errno_t nRet = 0;
821+ if(lpstrDest == NULL || cchDest == 0 || lpstrSrc == NULL)
822+ {
823+ nRet = EINVAL;
824+ }
825+ else if(cchCount == _TRUNCATE)
826+ {
827+ cchCount = min(cchDest - 1, size_t(lstrlenA(lpstrSrc)));
828+ nRet = STRUNCATE;
829+ }
830+ else if(cchDest <= cchCount)
831+ {
832+ lpstrDest[0] = 0;
833+ nRet = EINVAL;
834+ }
835+ if(nRet == 0 || nRet == STRUNCATE)
836+ nRet = (lstrcpynA(lpstrDest, lpstrSrc, (int)cchCount + 1) != NULL) ? nRet : EINVAL;
837+ ATLASSERT(nRet == 0 || nRet == STRUNCATE);
838+ return nRet;
839+#endif
840+ }
841+
842+ inline errno_t strncpyW_x(wchar_t* lpstrDest, size_t cchDest, const wchar_t* lpstrSrc, size_t cchCount)
843+ {
844+#if _SECURE_ATL
845+ return ATL::Checked::wcsncpy_s(lpstrDest, cchDest, lpstrSrc, cchCount);
846+#else
847+ errno_t nRet = 0;
848+ if(lpstrDest == NULL || cchDest == 0 || lpstrSrc == NULL)
849+ {
850+ nRet = EINVAL;
851+ }
852+ else if(cchCount == _TRUNCATE)
853+ {
854+ cchCount = min(cchDest - 1, size_t(lstrlenW(lpstrSrc)));
855+ nRet = STRUNCATE;
856+ }
857+ else if(cchDest <= cchCount)
858+ {
859+ lpstrDest[0] = 0;
860+ nRet = EINVAL;
861+ }
862+ if(nRet == 0 || nRet == STRUNCATE)
863+ nRet = (lstrcpynW(lpstrDest, lpstrSrc, (int)cchCount + 1) != NULL) ? nRet : EINVAL;
864+ ATLASSERT(nRet == 0 || nRet == STRUNCATE);
865+ return nRet;
866+#endif
867+ }
868+
869+ inline errno_t strncpy_x(LPTSTR lpstrDest, size_t cchDest, LPCTSTR lpstrSrc, size_t cchCount)
870+ {
871+#ifdef _UNICODE
872+ return strncpyW_x(lpstrDest, cchDest, lpstrSrc, cchCount);
873+#else
874+ return strncpyA_x(lpstrDest, cchDest, lpstrSrc, cchCount);
875+#endif
876+ }
877+
878+ inline void strcatA_x(char* lpstrDest, size_t cchDest, const char* lpstrSrc)
879+ {
880+#if _SECURE_ATL
881+ ATL::Checked::strcat_s(lpstrDest, cchDest, lpstrSrc);
882+#else
883+ if(cchDest > (size_t)lstrlenA(lpstrSrc))
884+ ATLVERIFY(lstrcatA(lpstrDest, lpstrSrc) != NULL);
885+ else
886+ ATLASSERT(FALSE);
887+#endif
888+ }
889+
890+ inline void strcatW_x(wchar_t* lpstrDest, size_t cchDest, const wchar_t* lpstrSrc)
891+ {
892+#if _SECURE_ATL
893+ ATL::Checked::wcscat_s(lpstrDest, cchDest, lpstrSrc);
894+#else
895+ if(cchDest > (size_t)lstrlenW(lpstrSrc))
896+ ATLVERIFY(lstrcatW(lpstrDest, lpstrSrc) != NULL);
897+ else
898+ ATLASSERT(FALSE);
899+#endif
900+ }
901+
902+ inline void strcat_x(LPTSTR lpstrDest, size_t cchDest, LPCTSTR lpstrSrc)
903+ {
904+#ifdef _UNICODE
905+ strcatW_x(lpstrDest, cchDest, lpstrSrc);
906+#else
907+ strcatA_x(lpstrDest, cchDest, lpstrSrc);
908+#endif
909+ }
910+
911+ inline void memcpy_x(void* pDest, size_t cbDest, const void* pSrc, size_t cbSrc)
912+ {
913+#if _SECURE_ATL
914+ ATL::Checked::memcpy_s(pDest, cbDest, pSrc, cbSrc);
915+#else
916+ if(cbDest >= cbSrc)
917+ memcpy(pDest, pSrc, cbSrc);
918+ else
919+ ATLASSERT(FALSE);
920+#endif
921+ }
922+
923+ inline void memmove_x(void* pDest, size_t cbDest, const void* pSrc, size_t cbSrc)
924+ {
925+#if _SECURE_ATL
926+ ATL::Checked::memmove_s(pDest, cbDest, pSrc, cbSrc);
927+#else
928+ if(cbDest >= cbSrc)
929+ memmove(pDest, pSrc, cbSrc);
930+ else
931+ ATLASSERT(FALSE);
932+#endif
933+ }
934+
935+ inline int vsprintf_x(LPTSTR lpstrBuff, size_t cchBuff, LPCTSTR lpstrFormat, va_list args)
936+ {
937+#if _SECURE_ATL && !defined(_ATL_MIN_CRT) && !defined(_WIN32_WCE)
938+ return _vstprintf_s(lpstrBuff, cchBuff, lpstrFormat, args);
939+#else
940+ cchBuff; // Avoid unused argument warning
941+#pragma warning(disable: 4996)
942+ return _vstprintf(lpstrBuff, lpstrFormat, args);
943+#pragma warning(default: 4996)
944+#endif
945+ }
946+
947+ inline int wvsprintf_x(LPTSTR lpstrBuff, size_t cchBuff, LPCTSTR lpstrFormat, va_list args)
948+ {
949+#if _SECURE_ATL && !defined(_ATL_MIN_CRT) && !defined(_WIN32_WCE)
950+ return _vstprintf_s(lpstrBuff, cchBuff, lpstrFormat, args);
951+#else
952+ cchBuff; // Avoid unused argument warning
953+ return ::wvsprintf(lpstrBuff, lpstrFormat, args);
954+#endif
955+ }
956+
957+ inline int sprintf_x(LPTSTR lpstrBuff, size_t cchBuff, LPCTSTR lpstrFormat, ...)
958+ {
959+ va_list args;
960+ va_start(args, lpstrFormat);
961+ int nRes = vsprintf_x(lpstrBuff, cchBuff, lpstrFormat, args);
962+ va_end(args);
963+ return nRes;
964+ }
965+
966+ inline int wsprintf_x(LPTSTR lpstrBuff, size_t cchBuff, LPCTSTR lpstrFormat, ...)
967+ {
968+ va_list args;
969+ va_start(args, lpstrFormat);
970+ int nRes = wvsprintf_x(lpstrBuff, cchBuff, lpstrFormat, args);
971+ va_end(args);
972+ return nRes;
973+ }
974+}; // namespace SecureHelper
975+
976+
977+///////////////////////////////////////////////////////////////////////////////
978+// CMessageFilter - Interface for message filter support
979+
980+class CMessageFilter
981+{
982+public:
983+ virtual BOOL PreTranslateMessage(MSG* pMsg) = 0;
984+};
985+
986+
987+///////////////////////////////////////////////////////////////////////////////
988+// CIdleHandler - Interface for idle processing
989+
990+class CIdleHandler
991+{
992+public:
993+ virtual BOOL OnIdle() = 0;
994+};
995+
996+#ifndef _ATL_NO_OLD_NAMES
997+ // for compatilibility with old names only
998+ typedef CIdleHandler CUpdateUIObject;
999+ #define DoUpdate OnIdle
1000+#endif // !_ATL_NO_OLD_NAMES
1001+
1002+
1003+///////////////////////////////////////////////////////////////////////////////
1004+// CMessageLoop - message loop implementation
1005+
1006+class CMessageLoop
1007+{
1008+public:
1009+ ATL::CSimpleArray<CMessageFilter*> m_aMsgFilter;
1010+ ATL::CSimpleArray<CIdleHandler*> m_aIdleHandler;
1011+ MSG m_msg;
1012+
1013+// Message filter operations
1014+ BOOL AddMessageFilter(CMessageFilter* pMessageFilter)
1015+ {
1016+ return m_aMsgFilter.Add(pMessageFilter);
1017+ }
1018+
1019+ BOOL RemoveMessageFilter(CMessageFilter* pMessageFilter)
1020+ {
1021+ return m_aMsgFilter.Remove(pMessageFilter);
1022+ }
1023+
1024+// Idle handler operations
1025+ BOOL AddIdleHandler(CIdleHandler* pIdleHandler)
1026+ {
1027+ return m_aIdleHandler.Add(pIdleHandler);
1028+ }
1029+
1030+ BOOL RemoveIdleHandler(CIdleHandler* pIdleHandler)
1031+ {
1032+ return m_aIdleHandler.Remove(pIdleHandler);
1033+ }
1034+
1035+#ifndef _ATL_NO_OLD_NAMES
1036+ // for compatilibility with old names only
1037+ BOOL AddUpdateUI(CIdleHandler* pIdleHandler)
1038+ {
1039+ ATLTRACE2(atlTraceUI, 0, _T("CUpdateUIObject and AddUpdateUI are deprecated. Please change your code to use CIdleHandler and OnIdle\n"));
1040+ return AddIdleHandler(pIdleHandler);
1041+ }
1042+
1043+ BOOL RemoveUpdateUI(CIdleHandler* pIdleHandler)
1044+ {
1045+ ATLTRACE2(atlTraceUI, 0, _T("CUpdateUIObject and RemoveUpdateUI are deprecated. Please change your code to use CIdleHandler and OnIdle\n"));
1046+ return RemoveIdleHandler(pIdleHandler);
1047+ }
1048+#endif // !_ATL_NO_OLD_NAMES
1049+
1050+// message loop
1051+ int Run()
1052+ {
1053+ BOOL bDoIdle = TRUE;
1054+ int nIdleCount = 0;
1055+ BOOL bRet;
1056+
1057+ for(;;)
1058+ {
1059+ while(bDoIdle && !::PeekMessage(&m_msg, NULL, 0, 0, PM_NOREMOVE))
1060+ {
1061+ if(!OnIdle(nIdleCount++))
1062+ bDoIdle = FALSE;
1063+ }
1064+
1065+ bRet = ::GetMessage(&m_msg, NULL, 0, 0);
1066+
1067+ if(bRet == -1)
1068+ {
1069+ ATLTRACE2(atlTraceUI, 0, _T("::GetMessage returned -1 (error)\n"));
1070+ continue; // error, don't process
1071+ }
1072+ else if(!bRet)
1073+ {
1074+ ATLTRACE2(atlTraceUI, 0, _T("CMessageLoop::Run - exiting\n"));
1075+ break; // WM_QUIT, exit message loop
1076+ }
1077+
1078+ if(!PreTranslateMessage(&m_msg))
1079+ {
1080+ ::TranslateMessage(&m_msg);
1081+ ::DispatchMessage(&m_msg);
1082+ }
1083+
1084+ if(IsIdleMessage(&m_msg))
1085+ {
1086+ bDoIdle = TRUE;
1087+ nIdleCount = 0;
1088+ }
1089+ }
1090+
1091+ return (int)m_msg.wParam;
1092+ }
1093+
1094+ static BOOL IsIdleMessage(MSG* pMsg)
1095+ {
1096+ // These messages should NOT cause idle processing
1097+ switch(pMsg->message)
1098+ {
1099+ case WM_MOUSEMOVE:
1100+#ifndef _WIN32_WCE
1101+ case WM_NCMOUSEMOVE:
1102+#endif // !_WIN32_WCE
1103+ case WM_PAINT:
1104+ case 0x0118: // WM_SYSTIMER (caret blink)
1105+ return FALSE;
1106+ }
1107+
1108+ return TRUE;
1109+ }
1110+
1111+// Overrideables
1112+ // Override to change message filtering
1113+ virtual BOOL PreTranslateMessage(MSG* pMsg)
1114+ {
1115+ // loop backwards
1116+ for(int i = m_aMsgFilter.GetSize() - 1; i >= 0; i--)
1117+ {
1118+ CMessageFilter* pMessageFilter = m_aMsgFilter[i];
1119+ if(pMessageFilter != NULL && pMessageFilter->PreTranslateMessage(pMsg))
1120+ return TRUE;
1121+ }
1122+ return FALSE; // not translated
1123+ }
1124+
1125+ // override to change idle processing
1126+ virtual BOOL OnIdle(int /*nIdleCount*/)
1127+ {
1128+ for(int i = 0; i < m_aIdleHandler.GetSize(); i++)
1129+ {
1130+ CIdleHandler* pIdleHandler = m_aIdleHandler[i];
1131+ if(pIdleHandler != NULL)
1132+ pIdleHandler->OnIdle();
1133+ }
1134+ return FALSE; // don't continue
1135+ }
1136+};
1137+
1138+
1139+///////////////////////////////////////////////////////////////////////////////
1140+// CStaticDataInitCriticalSectionLock and CWindowCreateCriticalSectionLock
1141+// internal classes to manage critical sections for both ATL3 and ATL7
1142+
1143+class CStaticDataInitCriticalSectionLock
1144+{
1145+public:
1146+#if (_ATL_VER >= 0x0700)
1147+ ATL::CComCritSecLock<ATL::CComCriticalSection> m_cslock;
1148+
1149+ CStaticDataInitCriticalSectionLock() : m_cslock(ATL::_pAtlModule->m_csStaticDataInitAndTypeInfo, false)
1150+ { }
1151+#endif // (_ATL_VER >= 0x0700)
1152+
1153+ HRESULT Lock()
1154+ {
1155+#if (_ATL_VER >= 0x0700)
1156+ return m_cslock.Lock();
1157+#else // !(_ATL_VER >= 0x0700)
1158+ ::EnterCriticalSection(&ATL::_pModule->m_csStaticDataInit);
1159+ return S_OK;
1160+#endif // !(_ATL_VER >= 0x0700)
1161+ }
1162+
1163+ void Unlock()
1164+ {
1165+#if (_ATL_VER >= 0x0700)
1166+ m_cslock.Unlock();
1167+#else // !(_ATL_VER >= 0x0700)
1168+ ::LeaveCriticalSection(&ATL::_pModule->m_csStaticDataInit);
1169+#endif // !(_ATL_VER >= 0x0700)
1170+ }
1171+};
1172+
1173+
1174+class CWindowCreateCriticalSectionLock
1175+{
1176+public:
1177+#if (_ATL_VER >= 0x0700)
1178+ ATL::CComCritSecLock<ATL::CComCriticalSection> m_cslock;
1179+
1180+ CWindowCreateCriticalSectionLock() : m_cslock(ATL::_AtlWinModule.m_csWindowCreate, false)
1181+ { }
1182+#endif // (_ATL_VER >= 0x0700)
1183+
1184+ HRESULT Lock()
1185+ {
1186+#if (_ATL_VER >= 0x0700)
1187+ return m_cslock.Lock();
1188+#else // !(_ATL_VER >= 0x0700)
1189+ ::EnterCriticalSection(&ATL::_pModule->m_csWindowCreate);
1190+ return S_OK;
1191+#endif // !(_ATL_VER >= 0x0700)
1192+ }
1193+
1194+ void Unlock()
1195+ {
1196+#if (_ATL_VER >= 0x0700)
1197+ m_cslock.Unlock();
1198+#else // !(_ATL_VER >= 0x0700)
1199+ ::LeaveCriticalSection(&ATL::_pModule->m_csWindowCreate);
1200+#endif // !(_ATL_VER >= 0x0700)
1201+ }
1202+};
1203+
1204+
1205+///////////////////////////////////////////////////////////////////////////////
1206+// CTempBuffer - helper class for stack allocations for ATL3
1207+
1208+#ifndef _WTL_STACK_ALLOC_THRESHOLD
1209+ #define _WTL_STACK_ALLOC_THRESHOLD 512
1210+#endif
1211+
1212+#if (_ATL_VER >= 0x0700)
1213+
1214+using ATL::CTempBuffer;
1215+
1216+#else // !(_ATL_VER >= 0x0700)
1217+
1218+#ifndef SIZE_MAX
1219+ #ifdef _WIN64
1220+ #define SIZE_MAX _UI64_MAX
1221+ #else
1222+ #define SIZE_MAX UINT_MAX
1223+ #endif
1224+#endif
1225+
1226+#pragma warning(disable: 4284) // warning for operator ->
1227+
1228+template<typename T, int t_nFixedBytes = 128>
1229+class CTempBuffer
1230+{
1231+public:
1232+ CTempBuffer() : m_p(NULL)
1233+ {
1234+ }
1235+
1236+ CTempBuffer(size_t nElements) : m_p(NULL)
1237+ {
1238+ Allocate(nElements);
1239+ }
1240+
1241+ ~CTempBuffer()
1242+ {
1243+ if(m_p != reinterpret_cast<T*>(m_abFixedBuffer))
1244+ free(m_p);
1245+ }
1246+
1247+ operator T*() const
1248+ {
1249+ return m_p;
1250+ }
1251+
1252+ T* operator ->() const
1253+ {
1254+ ATLASSERT(m_p != NULL);
1255+ return m_p;
1256+ }
1257+
1258+ T* Allocate(size_t nElements)
1259+ {
1260+ ATLASSERT(nElements <= (SIZE_MAX / sizeof(T)));
1261+ return AllocateBytes(nElements * sizeof(T));
1262+ }
1263+
1264+ T* AllocateBytes(size_t nBytes)
1265+ {
1266+ ATLASSERT(m_p == NULL);
1267+ if(nBytes > t_nFixedBytes)
1268+ m_p = static_cast<T*>(malloc(nBytes));
1269+ else
1270+ m_p = reinterpret_cast<T*>(m_abFixedBuffer);
1271+
1272+ return m_p;
1273+ }
1274+
1275+private:
1276+ T* m_p;
1277+ BYTE m_abFixedBuffer[t_nFixedBytes];
1278+};
1279+
1280+#pragma warning(default: 4284)
1281+
1282+#endif // !(_ATL_VER >= 0x0700)
1283+
1284+
1285+///////////////////////////////////////////////////////////////////////////////
1286+// CAppModule - module class for an application
1287+
1288+class CAppModule : public ATL::CComModule
1289+{
1290+public:
1291+ DWORD m_dwMainThreadID;
1292+ ATL::CSimpleMap<DWORD, CMessageLoop*>* m_pMsgLoopMap;
1293+ ATL::CSimpleArray<HWND>* m_pSettingChangeNotify;
1294+
1295+// Overrides of CComModule::Init and Term
1296+ HRESULT Init(ATL::_ATL_OBJMAP_ENTRY* pObjMap, HINSTANCE hInstance, const GUID* pLibID = NULL)
1297+ {
1298+ HRESULT hRet = CComModule::Init(pObjMap, hInstance, pLibID);
1299+ if(FAILED(hRet))
1300+ return hRet;
1301+
1302+ m_dwMainThreadID = ::GetCurrentThreadId();
1303+ typedef ATL::CSimpleMap<DWORD, CMessageLoop*> _mapClass;
1304+ m_pMsgLoopMap = NULL;
1305+ ATLTRY(m_pMsgLoopMap = new _mapClass);
1306+ if(m_pMsgLoopMap == NULL)
1307+ return E_OUTOFMEMORY;
1308+ m_pSettingChangeNotify = NULL;
1309+
1310+ return hRet;
1311+ }
1312+
1313+ void Term()
1314+ {
1315+ TermSettingChangeNotify();
1316+ delete m_pMsgLoopMap;
1317+ CComModule::Term();
1318+ }
1319+
1320+// Message loop map methods
1321+ BOOL AddMessageLoop(CMessageLoop* pMsgLoop)
1322+ {
1323+ CStaticDataInitCriticalSectionLock lock;
1324+ if(FAILED(lock.Lock()))
1325+ {
1326+ ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CAppModule::AddMessageLoop.\n"));
1327+ ATLASSERT(FALSE);
1328+ return FALSE;
1329+ }
1330+
1331+ ATLASSERT(pMsgLoop != NULL);
1332+ ATLASSERT(m_pMsgLoopMap->Lookup(::GetCurrentThreadId()) == NULL); // not in map yet
1333+
1334+ BOOL bRet = m_pMsgLoopMap->Add(::GetCurrentThreadId(), pMsgLoop);
1335+
1336+ lock.Unlock();
1337+
1338+ return bRet;
1339+ }
1340+
1341+ BOOL RemoveMessageLoop()
1342+ {
1343+ CStaticDataInitCriticalSectionLock lock;
1344+ if(FAILED(lock.Lock()))
1345+ {
1346+ ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CAppModule::RemoveMessageLoop.\n"));
1347+ ATLASSERT(FALSE);
1348+ return FALSE;
1349+ }
1350+
1351+ BOOL bRet = m_pMsgLoopMap->Remove(::GetCurrentThreadId());
1352+
1353+ lock.Unlock();
1354+
1355+ return bRet;
1356+ }
1357+
1358+ CMessageLoop* GetMessageLoop(DWORD dwThreadID = ::GetCurrentThreadId()) const
1359+ {
1360+ CStaticDataInitCriticalSectionLock lock;
1361+ if(FAILED(lock.Lock()))
1362+ {
1363+ ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CAppModule::GetMessageLoop.\n"));
1364+ ATLASSERT(FALSE);
1365+ return NULL;
1366+ }
1367+
1368+ CMessageLoop* pLoop = m_pMsgLoopMap->Lookup(dwThreadID);
1369+
1370+ lock.Unlock();
1371+
1372+ return pLoop;
1373+ }
1374+
1375+// Setting change notify methods
1376+ // Note: Call this from the main thread for MSDI apps
1377+ BOOL InitSettingChangeNotify(DLGPROC pfnDlgProc = _SettingChangeDlgProc)
1378+ {
1379+ CStaticDataInitCriticalSectionLock lock;
1380+ if(FAILED(lock.Lock()))
1381+ {
1382+ ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CAppModule::InitSettingChangeNotify.\n"));
1383+ ATLASSERT(FALSE);
1384+ return FALSE;
1385+ }
1386+
1387+ if(m_pSettingChangeNotify == NULL)
1388+ {
1389+ typedef ATL::CSimpleArray<HWND> _notifyClass;
1390+ ATLTRY(m_pSettingChangeNotify = new _notifyClass);
1391+ ATLASSERT(m_pSettingChangeNotify != NULL);
1392+ }
1393+
1394+ BOOL bRet = (m_pSettingChangeNotify != NULL);
1395+ if(bRet && m_pSettingChangeNotify->GetSize() == 0)
1396+ {
1397+ // init everything
1398+ _ATL_EMPTY_DLGTEMPLATE templ;
1399+ HWND hNtfWnd = ::CreateDialogIndirect(GetModuleInstance(), &templ, NULL, pfnDlgProc);
1400+ ATLASSERT(::IsWindow(hNtfWnd));
1401+ if(::IsWindow(hNtfWnd))
1402+ {
1403+// need conditional code because types don't match in winuser.h
1404+#ifdef _WIN64
1405+ ::SetWindowLongPtr(hNtfWnd, GWLP_USERDATA, (LONG_PTR)this);
1406+#else
1407+ ::SetWindowLongPtr(hNtfWnd, GWLP_USERDATA, PtrToLong(this));
1408+#endif
1409+ bRet = m_pSettingChangeNotify->Add(hNtfWnd);
1410+ }
1411+ else
1412+ {
1413+ bRet = FALSE;
1414+ }
1415+ }
1416+
1417+ lock.Unlock();
1418+
1419+ return bRet;
1420+ }
1421+
1422+ void TermSettingChangeNotify()
1423+ {
1424+ CStaticDataInitCriticalSectionLock lock;
1425+ if(FAILED(lock.Lock()))
1426+ {
1427+ ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CAppModule::TermSettingChangeNotify.\n"));
1428+ ATLASSERT(FALSE);
1429+ return;
1430+ }
1431+
1432+ if(m_pSettingChangeNotify != NULL && m_pSettingChangeNotify->GetSize() > 0)
1433+ ::DestroyWindow((*m_pSettingChangeNotify)[0]);
1434+ delete m_pSettingChangeNotify;
1435+ m_pSettingChangeNotify = NULL;
1436+
1437+ lock.Unlock();
1438+ }
1439+
1440+ BOOL AddSettingChangeNotify(HWND hWnd)
1441+ {
1442+ CStaticDataInitCriticalSectionLock lock;
1443+ if(FAILED(lock.Lock()))
1444+ {
1445+ ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CAppModule::AddSettingChangeNotify.\n"));
1446+ ATLASSERT(FALSE);
1447+ return FALSE;
1448+ }
1449+
1450+ ATLASSERT(::IsWindow(hWnd));
1451+ BOOL bRet = FALSE;
1452+ if(InitSettingChangeNotify() != FALSE)
1453+ bRet = m_pSettingChangeNotify->Add(hWnd);
1454+
1455+ lock.Unlock();
1456+
1457+ return bRet;
1458+ }
1459+
1460+ BOOL RemoveSettingChangeNotify(HWND hWnd)
1461+ {
1462+ CStaticDataInitCriticalSectionLock lock;
1463+ if(FAILED(lock.Lock()))
1464+ {
1465+ ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CAppModule::RemoveSettingChangeNotify.\n"));
1466+ ATLASSERT(FALSE);
1467+ return FALSE;
1468+ }
1469+
1470+ BOOL bRet = FALSE;
1471+ if(m_pSettingChangeNotify != NULL)
1472+ bRet = m_pSettingChangeNotify->Remove(hWnd);
1473+
1474+ lock.Unlock();
1475+
1476+ return bRet;
1477+ }
1478+
1479+// Implementation - setting change notify dialog template and dialog procedure
1480+ struct _ATL_EMPTY_DLGTEMPLATE : DLGTEMPLATE
1481+ {
1482+ _ATL_EMPTY_DLGTEMPLATE()
1483+ {
1484+ memset(this, 0, sizeof(_ATL_EMPTY_DLGTEMPLATE));
1485+ style = WS_POPUP;
1486+ }
1487+ WORD wMenu, wClass, wTitle;
1488+ };
1489+
1490+#ifdef _WIN64
1491+ static INT_PTR CALLBACK _SettingChangeDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1492+#else
1493+ static BOOL CALLBACK _SettingChangeDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1494+#endif
1495+ {
1496+ if(uMsg == WM_SETTINGCHANGE)
1497+ {
1498+// need conditional code because types don't match in winuser.h
1499+#ifdef _WIN64
1500+ CAppModule* pModule = (CAppModule*)::GetWindowLongPtr(hWnd, GWLP_USERDATA);
1501+#else
1502+ CAppModule* pModule = (CAppModule*)LongToPtr(::GetWindowLongPtr(hWnd, GWLP_USERDATA));
1503+#endif
1504+ ATLASSERT(pModule != NULL);
1505+ ATLASSERT(pModule->m_pSettingChangeNotify != NULL);
1506+ const UINT uTimeout = 1500; // ms
1507+ for(int i = 1; i < pModule->m_pSettingChangeNotify->GetSize(); i++)
1508+ {
1509+#if !defined(_WIN32_WCE)
1510+ ::SendMessageTimeout((*pModule->m_pSettingChangeNotify)[i], uMsg, wParam, lParam, SMTO_ABORTIFHUNG, uTimeout, NULL);
1511+#elif(_WIN32_WCE >= 400) // CE specific
1512+ ::SendMessageTimeout((*pModule->m_pSettingChangeNotify)[i], uMsg, wParam, lParam, SMTO_NORMAL, uTimeout, NULL);
1513+#else // _WIN32_WCE < 400 specific
1514+ uTimeout;
1515+ ::SendMessage((*pModule->m_pSettingChangeNotify)[i], uMsg, wParam, lParam);
1516+#endif
1517+ }
1518+ return TRUE;
1519+ }
1520+ return FALSE;
1521+ }
1522+};
1523+
1524+
1525+///////////////////////////////////////////////////////////////////////////////
1526+// CServerAppModule - module class for a COM server application
1527+
1528+class CServerAppModule : public CAppModule
1529+{
1530+public:
1531+ HANDLE m_hEventShutdown;
1532+ bool m_bActivity;
1533+ DWORD m_dwTimeOut;
1534+ DWORD m_dwPause;
1535+
1536+// Override of CAppModule::Init
1537+ HRESULT Init(ATL::_ATL_OBJMAP_ENTRY* pObjMap, HINSTANCE hInstance, const GUID* pLibID = NULL)
1538+ {
1539+ m_dwTimeOut = 5000;
1540+ m_dwPause = 1000;
1541+ return CAppModule::Init(pObjMap, hInstance, pLibID);
1542+ }
1543+
1544+ void Term()
1545+ {
1546+ if(m_hEventShutdown != NULL && ::CloseHandle(m_hEventShutdown))
1547+ m_hEventShutdown = NULL;
1548+ CAppModule::Term();
1549+ }
1550+
1551+// COM Server methods
1552+ LONG Unlock()
1553+ {
1554+ LONG lRet = CComModule::Unlock();
1555+ if(lRet == 0)
1556+ {
1557+ m_bActivity = true;
1558+ ::SetEvent(m_hEventShutdown); // tell monitor that we transitioned to zero
1559+ }
1560+ return lRet;
1561+ }
1562+
1563+ void MonitorShutdown()
1564+ {
1565+ for(;;)
1566+ {
1567+ ::WaitForSingleObject(m_hEventShutdown, INFINITE);
1568+ DWORD dwWait = 0;
1569+ do
1570+ {
1571+ m_bActivity = false;
1572+ dwWait = ::WaitForSingleObject(m_hEventShutdown, m_dwTimeOut);
1573+ }
1574+ while(dwWait == WAIT_OBJECT_0);
1575+ // timed out
1576+ if(!m_bActivity && m_nLockCnt == 0) // if no activity let's really bail
1577+ {
1578+#if ((_WIN32_WINNT >= 0x0400 ) || defined(_WIN32_DCOM)) && defined(_ATL_FREE_THREADED) && !defined(_WIN32_WCE)
1579+ ::CoSuspendClassObjects();
1580+ if(!m_bActivity && m_nLockCnt == 0)
1581+#endif
1582+ break;
1583+ }
1584+ }
1585+ // This handle should be valid now. If it isn't,
1586+ // check if _Module.Term was called first (it shouldn't)
1587+ if(::CloseHandle(m_hEventShutdown))
1588+ m_hEventShutdown = NULL;
1589+ ::PostThreadMessage(m_dwMainThreadID, WM_QUIT, 0, 0);
1590+ }
1591+
1592+ bool StartMonitor()
1593+ {
1594+ m_hEventShutdown = ::CreateEvent(NULL, false, false, NULL);
1595+ if(m_hEventShutdown == NULL)
1596+ return false;
1597+ DWORD dwThreadID = 0;
1598+#if !defined(_ATL_MIN_CRT) && defined(_MT) && !defined(_WIN32_WCE)
1599+ HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0, (UINT (WINAPI*)(void*))MonitorProc, this, 0, (UINT*)&dwThreadID);
1600+#else
1601+ HANDLE hThread = ::CreateThread(NULL, 0, MonitorProc, this, 0, &dwThreadID);
1602+#endif
1603+ bool bRet = (hThread != NULL);
1604+ if(bRet)
1605+ ::CloseHandle(hThread);
1606+ return bRet;
1607+ }
1608+
1609+ static DWORD WINAPI MonitorProc(void* pv)
1610+ {
1611+ CServerAppModule* p = (CServerAppModule*)pv;
1612+ p->MonitorShutdown();
1613+ return 0;
1614+ }
1615+
1616+#if (_ATL_VER < 0x0700)
1617+ // search for an occurence of string p2 in string p1
1618+ static LPCTSTR FindOneOf(LPCTSTR p1, LPCTSTR p2)
1619+ {
1620+ while(p1 != NULL && *p1 != NULL)
1621+ {
1622+ LPCTSTR p = p2;
1623+ while(p != NULL && *p != NULL)
1624+ {
1625+ if(*p1 == *p)
1626+ return ::CharNext(p1);
1627+ p = ::CharNext(p);
1628+ }
1629+ p1 = ::CharNext(p1);
1630+ }
1631+ return NULL;
1632+ }
1633+#endif // (_ATL_VER < 0x0700)
1634+};
1635+
1636+
1637+///////////////////////////////////////////////////////////////////////////////
1638+// CRegKeyEx - adds type-specific methods to ATL3 CRegKey
1639+
1640+#if (_ATL_VER < 0x0700)
1641+
1642+class CRegKeyEx : public ATL::CRegKey
1643+{
1644+public:
1645+// Constructors and operators
1646+ CRegKeyEx(HKEY hKey = NULL)
1647+ {
1648+ m_hKey = hKey;
1649+ }
1650+
1651+ CRegKeyEx(CRegKeyEx& key)
1652+ {
1653+ Attach(key.Detach());
1654+ }
1655+
1656+ CRegKeyEx& operator =(CRegKeyEx& key)
1657+ {
1658+ Close();
1659+ Attach(key.Detach());
1660+ return *this;
1661+ }
1662+
1663+// Methods
1664+ LONG SetValue(LPCTSTR pszValueName, DWORD dwType, const void* pValue, ULONG nBytes)
1665+ {
1666+ ATLASSERT(m_hKey != NULL);
1667+ return ::RegSetValueEx(m_hKey, pszValueName, NULL, dwType, static_cast<const BYTE*>(pValue), nBytes);
1668+ }
1669+
1670+ LONG SetGUIDValue(LPCTSTR pszValueName, REFGUID guidValue)
1671+ {
1672+ ATLASSERT(m_hKey != NULL);
1673+
1674+ OLECHAR szGUID[64] = { 0 };
1675+ ::StringFromGUID2(guidValue, szGUID, 64);
1676+
1677+ USES_CONVERSION;
1678+ LPCTSTR lpstr = OLE2CT(szGUID);
1679+#ifndef _UNICODE
1680+ if(lpstr == NULL)
1681+ return E_OUTOFMEMORY;
1682+#endif
1683+ return SetStringValue(pszValueName, lpstr);
1684+ }
1685+
1686+ LONG SetBinaryValue(LPCTSTR pszValueName, const void* pValue, ULONG nBytes)
1687+ {
1688+ ATLASSERT(m_hKey != NULL);
1689+ return ::RegSetValueEx(m_hKey, pszValueName, NULL, REG_BINARY, reinterpret_cast<const BYTE*>(pValue), nBytes);
1690+ }
1691+
1692+ LONG SetDWORDValue(LPCTSTR pszValueName, DWORD dwValue)
1693+ {
1694+ ATLASSERT(m_hKey != NULL);
1695+ return ::RegSetValueEx(m_hKey, pszValueName, NULL, REG_DWORD, reinterpret_cast<const BYTE*>(&dwValue), sizeof(DWORD));
1696+ }
1697+
1698+#ifndef _WIN32_WCE
1699+ LONG SetQWORDValue(LPCTSTR pszValueName, ULONGLONG qwValue)
1700+ {
1701+ ATLASSERT(m_hKey != NULL);
1702+ return ::RegSetValueEx(m_hKey, pszValueName, NULL, REG_QWORD, reinterpret_cast<const BYTE*>(&qwValue), sizeof(ULONGLONG));
1703+ }
1704+#endif
1705+
1706+ LONG SetStringValue(LPCTSTR pszValueName, LPCTSTR pszValue, DWORD dwType = REG_SZ)
1707+ {
1708+ ATLASSERT(m_hKey != NULL);
1709+ if(pszValue == NULL)
1710+ {
1711+ ATLASSERT(FALSE);
1712+ return ERROR_INVALID_DATA;
1713+ }
1714+ ATLASSERT((dwType == REG_SZ) || (dwType == REG_EXPAND_SZ));
1715+
1716+ return ::RegSetValueEx(m_hKey, pszValueName, NULL, dwType, reinterpret_cast<const BYTE*>(pszValue), (lstrlen(pszValue) + 1) * sizeof(TCHAR));
1717+ }
1718+
1719+ LONG SetMultiStringValue(LPCTSTR pszValueName, LPCTSTR pszValue)
1720+ {
1721+ ATLASSERT(m_hKey != NULL);
1722+ if(pszValue == NULL)
1723+ {
1724+ ATLASSERT(FALSE);
1725+ return ERROR_INVALID_DATA;
1726+ }
1727+
1728+ ULONG nBytes = 0;
1729+ ULONG nLength = 0;
1730+ LPCTSTR pszTemp = pszValue;
1731+ do
1732+ {
1733+ nLength = lstrlen(pszTemp) + 1;
1734+ pszTemp += nLength;
1735+ nBytes += nLength * sizeof(TCHAR);
1736+ } while (nLength != 1);
1737+
1738+ return ::RegSetValueEx(m_hKey, pszValueName, NULL, REG_MULTI_SZ, reinterpret_cast<const BYTE*>(pszValue), nBytes);
1739+ }
1740+
1741+ LONG QueryValue(LPCTSTR pszValueName, DWORD* pdwType, void* pData, ULONG* pnBytes)
1742+ {
1743+ ATLASSERT(m_hKey != NULL);
1744+ return ::RegQueryValueEx(m_hKey, pszValueName, NULL, pdwType, static_cast<LPBYTE>(pData), pnBytes);
1745+ }
1746+
1747+ LONG QueryGUIDValue(LPCTSTR pszValueName, GUID& guidValue)
1748+ {
1749+ ATLASSERT(m_hKey != NULL);
1750+
1751+ guidValue = GUID_NULL;
1752+
1753+ TCHAR szGUID[64] = { 0 };
1754+ ULONG nCount = 64;
1755+ LONG lRes = QueryStringValue(pszValueName, szGUID, &nCount);
1756+
1757+ if (lRes != ERROR_SUCCESS)
1758+ return lRes;
1759+
1760+ if(szGUID[0] != _T('{'))
1761+ return ERROR_INVALID_DATA;
1762+
1763+ USES_CONVERSION;
1764+ LPOLESTR lpstr = T2OLE(szGUID);
1765+#ifndef _UNICODE
1766+ if(lpstr == NULL)
1767+ return E_OUTOFMEMORY;
1768+#endif
1769+
1770+ HRESULT hr = ::CLSIDFromString(lpstr, &guidValue);
1771+ if (FAILED(hr))
1772+ return ERROR_INVALID_DATA;
1773+
1774+ return ERROR_SUCCESS;
1775+ }
1776+
1777+ LONG QueryBinaryValue(LPCTSTR pszValueName, void* pValue, ULONG* pnBytes)
1778+ {
1779+ ATLASSERT(pnBytes != NULL);
1780+ ATLASSERT(m_hKey != NULL);
1781+
1782+ DWORD dwType = 0;
1783+ LONG lRes = ::RegQueryValueEx(m_hKey, pszValueName, NULL, &dwType, reinterpret_cast<LPBYTE>(pValue), pnBytes);
1784+ if (lRes != ERROR_SUCCESS)
1785+ return lRes;
1786+ if (dwType != REG_BINARY)
1787+ return ERROR_INVALID_DATA;
1788+
1789+ return ERROR_SUCCESS;
1790+ }
1791+
1792+ LONG QueryDWORDValue(LPCTSTR pszValueName, DWORD& dwValue)
1793+ {
1794+ ATLASSERT(m_hKey != NULL);
1795+
1796+ ULONG nBytes = sizeof(DWORD);
1797+ DWORD dwType = 0;
1798+ LONG lRes = ::RegQueryValueEx(m_hKey, pszValueName, NULL, &dwType, reinterpret_cast<LPBYTE>(&dwValue), &nBytes);
1799+ if (lRes != ERROR_SUCCESS)
1800+ return lRes;
1801+ if (dwType != REG_DWORD)
1802+ return ERROR_INVALID_DATA;
1803+
1804+ return ERROR_SUCCESS;
1805+ }
1806+
1807+ LONG QueryQWORDValue(LPCTSTR pszValueName, ULONGLONG& qwValue)
1808+ {
1809+ ATLASSERT(m_hKey != NULL);
1810+
1811+ ULONG nBytes = sizeof(ULONGLONG);
1812+ DWORD dwType = 0;
1813+ LONG lRes = ::RegQueryValueEx(m_hKey, pszValueName, NULL, &dwType, reinterpret_cast<LPBYTE>(&qwValue), &nBytes);
1814+ if (lRes != ERROR_SUCCESS)
1815+ return lRes;
1816+ if (dwType != REG_QWORD)
1817+ return ERROR_INVALID_DATA;
1818+
1819+ return ERROR_SUCCESS;
1820+ }
1821+
1822+ LONG QueryStringValue(LPCTSTR pszValueName, LPTSTR pszValue, ULONG* pnChars)
1823+ {
1824+ ATLASSERT(m_hKey != NULL);
1825+ ATLASSERT(pnChars != NULL);
1826+
1827+ ULONG nBytes = (*pnChars) * sizeof(TCHAR);
1828+ DWORD dwType = 0;
1829+ *pnChars = 0;
1830+ LONG lRes = ::RegQueryValueEx(m_hKey, pszValueName, NULL, &dwType, reinterpret_cast<LPBYTE>(pszValue), &nBytes);
1831+
1832+ if (lRes != ERROR_SUCCESS)
1833+ {
1834+ return lRes;
1835+ }
1836+
1837+ if(dwType != REG_SZ && dwType != REG_EXPAND_SZ)
1838+ {
1839+ return ERROR_INVALID_DATA;
1840+ }
1841+
1842+ if (pszValue != NULL)
1843+ {
1844+ if(nBytes != 0)
1845+ {
1846+ if ((nBytes % sizeof(TCHAR) != 0) || (pszValue[nBytes / sizeof(TCHAR) -1] != 0))
1847+ return ERROR_INVALID_DATA;
1848+ }
1849+ else
1850+ {
1851+ pszValue[0] = _T('\0');
1852+ }
1853+ }
1854+
1855+ *pnChars = nBytes / sizeof(TCHAR);
1856+
1857+ return ERROR_SUCCESS;
1858+ }
1859+
1860+ LONG QueryMultiStringValue(LPCTSTR pszValueName, LPTSTR pszValue, ULONG* pnChars)
1861+ {
1862+ ATLASSERT(m_hKey != NULL);
1863+ ATLASSERT(pnChars != NULL);
1864+
1865+ if (pszValue != NULL && *pnChars < 2)
1866+ return ERROR_INSUFFICIENT_BUFFER;
1867+
1868+ ULONG nBytes = (*pnChars) * sizeof(TCHAR);
1869+ DWORD dwType = 0;
1870+ *pnChars = 0;
1871+ LONG lRes = ::RegQueryValueEx(m_hKey, pszValueName, NULL, &dwType, reinterpret_cast<LPBYTE>(pszValue), &nBytes);
1872+ if (lRes != ERROR_SUCCESS)
1873+ return lRes;
1874+ if (dwType != REG_MULTI_SZ)
1875+ return ERROR_INVALID_DATA;
1876+ if (pszValue != NULL && (nBytes % sizeof(TCHAR) != 0 || nBytes / sizeof(TCHAR) < 1 || pszValue[nBytes / sizeof(TCHAR) - 1] != 0 || ((nBytes / sizeof(TCHAR)) > 1 && pszValue[nBytes / sizeof(TCHAR) - 2] != 0)))
1877+ return ERROR_INVALID_DATA;
1878+
1879+ *pnChars = nBytes / sizeof(TCHAR);
1880+
1881+ return ERROR_SUCCESS;
1882+ }
1883+};
1884+
1885+#else // !(_ATL_VER < 0x0700)
1886+
1887+typedef ATL::CRegKey CRegKeyEx;
1888+
1889+#endif // !(_ATL_VER < 0x0700)
1890+
1891+
1892+///////////////////////////////////////////////////////////////////////////////
1893+// CString forward reference (enables CString use in atluser.h and atlgdi.h)
1894+
1895+#if defined(_WTL_FORWARD_DECLARE_CSTRING) && !defined(_WTL_USE_CSTRING)
1896+ #define _WTL_USE_CSTRING
1897+#endif // defined(_WTL_FORWARD_DECLARE_CSTRING) && !defined(_WTL_USE_CSTRING)
1898+
1899+#ifdef _WTL_USE_CSTRING
1900+ class CString; // forward declaration (include atlmisc.h for the whole class)
1901+#endif // _WTL_USE_CSTRING
1902+
1903+// CString namespace
1904+#ifndef _CSTRING_NS
1905+ #ifdef __ATLSTR_H__
1906+ #define _CSTRING_NS ATL
1907+ #else
1908+ #define _CSTRING_NS WTL
1909+ #endif
1910+#endif // _CSTRING_NS
1911+
1912+// Type classes namespace
1913+#ifndef _WTYPES_NS
1914+ #ifdef __ATLTYPES_H__
1915+ #define _WTYPES_NS
1916+ #else
1917+ #define _WTYPES_NS WTL
1918+ #endif
1919+#endif // _WTYPES_NS
1920+
1921+}; // namespace WTL
1922+
1923+
1924+///////////////////////////////////////////////////////////////////////////////
1925+// General DLL version helpers (excluded from atlbase.h if _ATL_DLL is defined)
1926+
1927+#if (_ATL_VER < 0x0700) && defined(_ATL_DLL) && !defined(_WIN32_WCE)
1928+
1929+namespace ATL
1930+{
1931+
1932+inline HRESULT AtlGetDllVersion(HINSTANCE hInstDLL, DLLVERSIONINFO* pDllVersionInfo)
1933+{
1934+ ATLASSERT(pDllVersionInfo != NULL);
1935+ if(pDllVersionInfo == NULL)
1936+ return E_INVALIDARG;
1937+
1938+ // We must get this function explicitly because some DLLs don't implement it.
1939+ DLLGETVERSIONPROC pfnDllGetVersion = (DLLGETVERSIONPROC)::GetProcAddress(hInstDLL, "DllGetVersion");
1940+ if(pfnDllGetVersion == NULL)
1941+ return E_NOTIMPL;
1942+
1943+ return (*pfnDllGetVersion)(pDllVersionInfo);
1944+}
1945+
1946+inline HRESULT AtlGetDllVersion(LPCTSTR lpstrDllName, DLLVERSIONINFO* pDllVersionInfo)
1947+{
1948+ HINSTANCE hInstDLL = ::LoadLibrary(lpstrDllName);
1949+ if(hInstDLL == NULL)
1950+ return E_FAIL;
1951+ HRESULT hRet = AtlGetDllVersion(hInstDLL, pDllVersionInfo);
1952+ ::FreeLibrary(hInstDLL);
1953+ return hRet;
1954+}
1955+
1956+// Common Control Versions:
1957+// Win95/WinNT 4.0 maj=4 min=00
1958+// IE 3.x maj=4 min=70
1959+// IE 4.0 maj=4 min=71
1960+inline HRESULT AtlGetCommCtrlVersion(LPDWORD pdwMajor, LPDWORD pdwMinor)
1961+{
1962+ ATLASSERT(pdwMajor != NULL && pdwMinor != NULL);
1963+ if(pdwMajor == NULL || pdwMinor == NULL)
1964+ return E_INVALIDARG;
1965+
1966+ DLLVERSIONINFO dvi;
1967+ ::ZeroMemory(&dvi, sizeof(dvi));
1968+ dvi.cbSize = sizeof(dvi);
1969+ HRESULT hRet = AtlGetDllVersion(_T("comctl32.dll"), &dvi);
1970+
1971+ if(SUCCEEDED(hRet))
1972+ {
1973+ *pdwMajor = dvi.dwMajorVersion;
1974+ *pdwMinor = dvi.dwMinorVersion;
1975+ }
1976+ else if(hRet == E_NOTIMPL)
1977+ {
1978+ // If DllGetVersion is not there, then the DLL is a version
1979+ // previous to the one shipped with IE 3.x
1980+ *pdwMajor = 4;
1981+ *pdwMinor = 0;
1982+ hRet = S_OK;
1983+ }
1984+
1985+ return hRet;
1986+}
1987+
1988+// Shell Versions:
1989+// Win95/WinNT 4.0 maj=4 min=00
1990+// IE 3.x, IE 4.0 without Web Integrated Desktop maj=4 min=00
1991+// IE 4.0 with Web Integrated Desktop maj=4 min=71
1992+// IE 4.01 with Web Integrated Desktop maj=4 min=72
1993+inline HRESULT AtlGetShellVersion(LPDWORD pdwMajor, LPDWORD pdwMinor)
1994+{
1995+ ATLASSERT(pdwMajor != NULL && pdwMinor != NULL);
1996+ if(pdwMajor == NULL || pdwMinor == NULL)
1997+ return E_INVALIDARG;
1998+
1999+ DLLVERSIONINFO dvi;
2000+ ::ZeroMemory(&dvi, sizeof(dvi));
2001+ dvi.cbSize = sizeof(dvi);
2002+ HRESULT hRet = AtlGetDllVersion(_T("shell32.dll"), &dvi);
2003+
2004+ if(SUCCEEDED(hRet))
2005+ {
2006+ *pdwMajor = dvi.dwMajorVersion;
2007+ *pdwMinor = dvi.dwMinorVersion;
2008+ }
2009+ else if(hRet == E_NOTIMPL)
2010+ {
2011+ // If DllGetVersion is not there, then the DLL is a version
2012+ // previous to the one shipped with IE 4.x
2013+ *pdwMajor = 4;
2014+ *pdwMinor = 0;
2015+ hRet = S_OK;
2016+ }
2017+
2018+ return hRet;
2019+}
2020+
2021+}; // namespace ATL
2022+
2023+#endif // (_ATL_VER < 0x0700) && defined(_ATL_DLL) && !defined(_WIN32_WCE)
2024+
2025+
2026+// These are always included
2027+#include "atlwinx.h"
2028+#include "atluser.h"
2029+#include "atlgdi.h"
2030+
2031+#ifndef _WTL_NO_AUTOMATIC_NAMESPACE
2032+using namespace WTL;
2033+#endif // !_WTL_NO_AUTOMATIC_NAMESPACE
2034+
2035+#endif // __ATLAPP_H__
--- /dev/null
+++ b/include/WTL/Include/atlcrack.h
@@ -0,0 +1,2384 @@
1+// Windows Template Library - WTL version 8.1
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+// 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.
11+
12+#ifndef __ATLCRACK_H__
13+#define __ATLCRACK_H__
14+
15+#pragma once
16+
17+#ifndef __ATLAPP_H__
18+ #error atlcrack.h requires atlapp.h to be included first
19+#endif
20+
21+
22+///////////////////////////////////////////////////////////////////////////////
23+// Message map macro for cracked handlers
24+
25+// Note about message maps with cracked handlers:
26+// For ATL 3.0, a message map using cracked handlers MUST use BEGIN_MSG_MAP_EX.
27+// For ATL 7.0 or higher, you can use BEGIN_MSG_MAP for CWindowImpl/CDialogImpl derived classes,
28+// but must use BEGIN_MSG_MAP_EX for classes that don't derive from CWindowImpl/CDialogImpl.
29+
30+#define BEGIN_MSG_MAP_EX(theClass) \
31+public: \
32+ BOOL m_bMsgHandled; \
33+ /* "handled" management for cracked handlers */ \
34+ BOOL IsMsgHandled() const \
35+ { \
36+ return m_bMsgHandled; \
37+ } \
38+ void SetMsgHandled(BOOL bHandled) \
39+ { \
40+ m_bMsgHandled = bHandled; \
41+ } \
42+ BOOL ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lResult, DWORD dwMsgMapID = 0) \
43+ { \
44+ BOOL bOldMsgHandled = m_bMsgHandled; \
45+ BOOL bRet = _ProcessWindowMessage(hWnd, uMsg, wParam, lParam, lResult, dwMsgMapID); \
46+ m_bMsgHandled = bOldMsgHandled; \
47+ return bRet; \
48+ } \
49+ BOOL _ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lResult, DWORD dwMsgMapID) \
50+ { \
51+ BOOL bHandled = TRUE; \
52+ hWnd; \
53+ uMsg; \
54+ wParam; \
55+ lParam; \
56+ lResult; \
57+ bHandled; \
58+ switch(dwMsgMapID) \
59+ { \
60+ case 0:
61+
62+
63+///////////////////////////////////////////////////////////////////////////////
64+// Standard Windows message macros
65+
66+// int OnCreate(LPCREATESTRUCT lpCreateStruct)
67+#define MSG_WM_CREATE(func) \
68+ if (uMsg == WM_CREATE) \
69+ { \
70+ SetMsgHandled(TRUE); \
71+ lResult = (LRESULT)func((LPCREATESTRUCT)lParam); \
72+ if(IsMsgHandled()) \
73+ return TRUE; \
74+ }
75+
76+// BOOL OnInitDialog(CWindow wndFocus, LPARAM lInitParam)
77+#define MSG_WM_INITDIALOG(func) \
78+ if (uMsg == WM_INITDIALOG) \
79+ { \
80+ SetMsgHandled(TRUE); \
81+ lResult = (LRESULT)func((HWND)wParam, lParam); \
82+ if(IsMsgHandled()) \
83+ return TRUE; \
84+ }
85+
86+// BOOL OnCopyData(CWindow wnd, PCOPYDATASTRUCT pCopyDataStruct)
87+#define MSG_WM_COPYDATA(func) \
88+ if (uMsg == WM_COPYDATA) \
89+ { \
90+ SetMsgHandled(TRUE); \
91+ lResult = (LRESULT)func((HWND)wParam, (PCOPYDATASTRUCT)lParam); \
92+ if(IsMsgHandled()) \
93+ return TRUE; \
94+ }
95+
96+// void OnDestroy()
97+#define MSG_WM_DESTROY(func) \
98+ if (uMsg == WM_DESTROY) \
99+ { \
100+ SetMsgHandled(TRUE); \
101+ func(); \
102+ lResult = 0; \
103+ if(IsMsgHandled()) \
104+ return TRUE; \
105+ }
106+
107+// void OnMove(CPoint ptPos)
108+#define MSG_WM_MOVE(func) \
109+ if (uMsg == WM_MOVE) \
110+ { \
111+ SetMsgHandled(TRUE); \
112+ func(_WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
113+ lResult = 0; \
114+ if(IsMsgHandled()) \
115+ return TRUE; \
116+ }
117+
118+// void OnSize(UINT nType, CSize size)
119+#define MSG_WM_SIZE(func) \
120+ if (uMsg == WM_SIZE) \
121+ { \
122+ SetMsgHandled(TRUE); \
123+ func((UINT)wParam, _WTYPES_NS::CSize(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
124+ lResult = 0; \
125+ if(IsMsgHandled()) \
126+ return TRUE; \
127+ }
128+
129+// void OnActivate(UINT nState, BOOL bMinimized, CWindow wndOther)
130+#define MSG_WM_ACTIVATE(func) \
131+ if (uMsg == WM_ACTIVATE) \
132+ { \
133+ SetMsgHandled(TRUE); \
134+ func((UINT)LOWORD(wParam), (BOOL)HIWORD(wParam), (HWND)lParam); \
135+ lResult = 0; \
136+ if(IsMsgHandled()) \
137+ return TRUE; \
138+ }
139+
140+// void OnSetFocus(CWindow wndOld)
141+#define MSG_WM_SETFOCUS(func) \
142+ if (uMsg == WM_SETFOCUS) \
143+ { \
144+ SetMsgHandled(TRUE); \
145+ func((HWND)wParam); \
146+ lResult = 0; \
147+ if(IsMsgHandled()) \
148+ return TRUE; \
149+ }
150+
151+// void OnKillFocus(CWindow wndFocus)
152+#define MSG_WM_KILLFOCUS(func) \
153+ if (uMsg == WM_KILLFOCUS) \
154+ { \
155+ SetMsgHandled(TRUE); \
156+ func((HWND)wParam); \
157+ lResult = 0; \
158+ if(IsMsgHandled()) \
159+ return TRUE; \
160+ }
161+
162+// void OnEnable(BOOL bEnable)
163+#define MSG_WM_ENABLE(func) \
164+ if (uMsg == WM_ENABLE) \
165+ { \
166+ SetMsgHandled(TRUE); \
167+ func((BOOL)wParam); \
168+ lResult = 0; \
169+ if(IsMsgHandled()) \
170+ return TRUE; \
171+ }
172+
173+// void OnPaint(CDCHandle dc)
174+#define MSG_WM_PAINT(func) \
175+ if (uMsg == WM_PAINT) \
176+ { \
177+ SetMsgHandled(TRUE); \
178+ func((HDC)wParam); \
179+ lResult = 0; \
180+ if(IsMsgHandled()) \
181+ return TRUE; \
182+ }
183+
184+// void OnClose()
185+#define MSG_WM_CLOSE(func) \
186+ if (uMsg == WM_CLOSE) \
187+ { \
188+ SetMsgHandled(TRUE); \
189+ func(); \
190+ lResult = 0; \
191+ if(IsMsgHandled()) \
192+ return TRUE; \
193+ }
194+
195+// BOOL OnQueryEndSession(UINT nSource, UINT uLogOff)
196+#define MSG_WM_QUERYENDSESSION(func) \
197+ if (uMsg == WM_QUERYENDSESSION) \
198+ { \
199+ SetMsgHandled(TRUE); \
200+ lResult = (LRESULT)func((UINT)wParam, (UINT)lParam); \
201+ if(IsMsgHandled()) \
202+ return TRUE; \
203+ }
204+
205+// BOOL OnQueryOpen()
206+#define MSG_WM_QUERYOPEN(func) \
207+ if (uMsg == WM_QUERYOPEN) \
208+ { \
209+ SetMsgHandled(TRUE); \
210+ lResult = (LRESULT)func(); \
211+ if(IsMsgHandled()) \
212+ return TRUE; \
213+ }
214+
215+// BOOL OnEraseBkgnd(CDCHandle dc)
216+#define MSG_WM_ERASEBKGND(func) \
217+ if (uMsg == WM_ERASEBKGND) \
218+ { \
219+ SetMsgHandled(TRUE); \
220+ lResult = (LRESULT)func((HDC)wParam); \
221+ if(IsMsgHandled()) \
222+ return TRUE; \
223+ }
224+
225+// void OnSysColorChange()
226+#define MSG_WM_SYSCOLORCHANGE(func) \
227+ if (uMsg == WM_SYSCOLORCHANGE) \
228+ { \
229+ SetMsgHandled(TRUE); \
230+ func(); \
231+ lResult = 0; \
232+ if(IsMsgHandled()) \
233+ return TRUE; \
234+ }
235+
236+// void OnEndSession(BOOL bEnding, UINT uLogOff)
237+#define MSG_WM_ENDSESSION(func) \
238+ if (uMsg == WM_ENDSESSION) \
239+ { \
240+ SetMsgHandled(TRUE); \
241+ func((BOOL)wParam, (UINT)lParam); \
242+ lResult = 0; \
243+ if(IsMsgHandled()) \
244+ return TRUE; \
245+ }
246+
247+// void OnShowWindow(BOOL bShow, UINT nStatus)
248+#define MSG_WM_SHOWWINDOW(func) \
249+ if (uMsg == WM_SHOWWINDOW) \
250+ { \
251+ SetMsgHandled(TRUE); \
252+ func((BOOL)wParam, (int)lParam); \
253+ lResult = 0; \
254+ if(IsMsgHandled()) \
255+ return TRUE; \
256+ }
257+
258+// HBRUSH OnCtlColorEdit(CDCHandle dc, CEdit edit)
259+#define MSG_WM_CTLCOLOREDIT(func) \
260+ if (uMsg == WM_CTLCOLOREDIT) \
261+ { \
262+ SetMsgHandled(TRUE); \
263+ lResult = (LRESULT)func((HDC)wParam, (HWND)lParam); \
264+ if(IsMsgHandled()) \
265+ return TRUE; \
266+ }
267+
268+// HBRUSH OnCtlColorListBox(CDCHandle dc, CListBox listBox)
269+#define MSG_WM_CTLCOLORLISTBOX(func) \
270+ if (uMsg == WM_CTLCOLORLISTBOX) \
271+ { \
272+ SetMsgHandled(TRUE); \
273+ lResult = (LRESULT)func((HDC)wParam, (HWND)lParam); \
274+ if(IsMsgHandled()) \
275+ return TRUE; \
276+ }
277+
278+// HBRUSH OnCtlColorBtn(CDCHandle dc, CButton button)
279+#define MSG_WM_CTLCOLORBTN(func) \
280+ if (uMsg == WM_CTLCOLORBTN) \
281+ { \
282+ SetMsgHandled(TRUE); \
283+ lResult = (LRESULT)func((HDC)wParam, (HWND)lParam); \
284+ if(IsMsgHandled()) \
285+ return TRUE; \
286+ }
287+
288+// HBRUSH OnCtlColorDlg(CDCHandle dc, CWindow wnd)
289+#define MSG_WM_CTLCOLORDLG(func) \
290+ if (uMsg == WM_CTLCOLORDLG) \
291+ { \
292+ SetMsgHandled(TRUE); \
293+ lResult = (LRESULT)func((HDC)wParam, (HWND)lParam); \
294+ if(IsMsgHandled()) \
295+ return TRUE; \
296+ }
297+
298+// HBRUSH OnCtlColorScrollBar(CDCHandle dc, CScrollBar scrollBar)
299+#define MSG_WM_CTLCOLORSCROLLBAR(func) \
300+ if (uMsg == WM_CTLCOLORSCROLLBAR) \
301+ { \
302+ SetMsgHandled(TRUE); \
303+ lResult = (LRESULT)func((HDC)wParam, (HWND)lParam); \
304+ if(IsMsgHandled()) \
305+ return TRUE; \
306+ }
307+
308+// HBRUSH OnCtlColorStatic(CDCHandle dc, CStatic wndStatic)
309+#define MSG_WM_CTLCOLORSTATIC(func) \
310+ if (uMsg == WM_CTLCOLORSTATIC) \
311+ { \
312+ SetMsgHandled(TRUE); \
313+ lResult = (LRESULT)func((HDC)wParam, (HWND)lParam); \
314+ if(IsMsgHandled()) \
315+ return TRUE; \
316+ }
317+
318+// void OnSettingChange(UINT uFlags, LPCTSTR lpszSection)
319+#define MSG_WM_SETTINGCHANGE(func) \
320+ if (uMsg == WM_SETTINGCHANGE) \
321+ { \
322+ SetMsgHandled(TRUE); \
323+ func((UINT)wParam, (LPCTSTR)lParam); \
324+ lResult = 0; \
325+ if(IsMsgHandled()) \
326+ return TRUE; \
327+ }
328+
329+// void OnDevModeChange(LPCTSTR lpDeviceName)
330+#define MSG_WM_DEVMODECHANGE(func) \
331+ if (uMsg == WM_DEVMODECHANGE) \
332+ { \
333+ SetMsgHandled(TRUE); \
334+ func((LPCTSTR)lParam); \
335+ lResult = 0; \
336+ if(IsMsgHandled()) \
337+ return TRUE; \
338+ }
339+
340+// void OnActivateApp(BOOL bActive, DWORD dwThreadID)
341+#define MSG_WM_ACTIVATEAPP(func) \
342+ if (uMsg == WM_ACTIVATEAPP) \
343+ { \
344+ SetMsgHandled(TRUE); \
345+ func((BOOL)wParam, (DWORD)lParam); \
346+ lResult = 0; \
347+ if(IsMsgHandled()) \
348+ return TRUE; \
349+ }
350+
351+// void OnFontChange()
352+#define MSG_WM_FONTCHANGE(func) \
353+ if (uMsg == WM_FONTCHANGE) \
354+ { \
355+ SetMsgHandled(TRUE); \
356+ func(); \
357+ lResult = 0; \
358+ if(IsMsgHandled()) \
359+ return TRUE; \
360+ }
361+
362+// void OnTimeChange()
363+#define MSG_WM_TIMECHANGE(func) \
364+ if (uMsg == WM_TIMECHANGE) \
365+ { \
366+ SetMsgHandled(TRUE); \
367+ func(); \
368+ lResult = 0; \
369+ if(IsMsgHandled()) \
370+ return TRUE; \
371+ }
372+
373+// void OnCancelMode()
374+#define MSG_WM_CANCELMODE(func) \
375+ if (uMsg == WM_CANCELMODE) \
376+ { \
377+ SetMsgHandled(TRUE); \
378+ func(); \
379+ lResult = 0; \
380+ if(IsMsgHandled()) \
381+ return TRUE; \
382+ }
383+
384+// BOOL OnSetCursor(CWindow wnd, UINT nHitTest, UINT message)
385+#define MSG_WM_SETCURSOR(func) \
386+ if (uMsg == WM_SETCURSOR) \
387+ { \
388+ SetMsgHandled(TRUE); \
389+ lResult = (LRESULT)func((HWND)wParam, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam)); \
390+ if(IsMsgHandled()) \
391+ return TRUE; \
392+ }
393+
394+// int OnMouseActivate(CWindow wndTopLevel, UINT nHitTest, UINT message)
395+#define MSG_WM_MOUSEACTIVATE(func) \
396+ if (uMsg == WM_MOUSEACTIVATE) \
397+ { \
398+ SetMsgHandled(TRUE); \
399+ lResult = (LRESULT)func((HWND)wParam, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam)); \
400+ if(IsMsgHandled()) \
401+ return TRUE; \
402+ }
403+
404+// void OnChildActivate()
405+#define MSG_WM_CHILDACTIVATE(func) \
406+ if (uMsg == WM_CHILDACTIVATE) \
407+ { \
408+ SetMsgHandled(TRUE); \
409+ func(); \
410+ lResult = 0; \
411+ if(IsMsgHandled()) \
412+ return TRUE; \
413+ }
414+
415+// void OnGetMinMaxInfo(LPMINMAXINFO lpMMI)
416+#define MSG_WM_GETMINMAXINFO(func) \
417+ if (uMsg == WM_GETMINMAXINFO) \
418+ { \
419+ SetMsgHandled(TRUE); \
420+ func((LPMINMAXINFO)lParam); \
421+ lResult = 0; \
422+ if(IsMsgHandled()) \
423+ return TRUE; \
424+ }
425+
426+// void OnIconEraseBkgnd(CDCHandle dc)
427+#define MSG_WM_ICONERASEBKGND(func) \
428+ if (uMsg == WM_ICONERASEBKGND) \
429+ { \
430+ SetMsgHandled(TRUE); \
431+ func((HDC)wParam); \
432+ lResult = 0; \
433+ if(IsMsgHandled()) \
434+ return TRUE; \
435+ }
436+
437+// void OnSpoolerStatus(UINT nStatus, UINT nJobs)
438+#define MSG_WM_SPOOLERSTATUS(func) \
439+ if (uMsg == WM_SPOOLERSTATUS) \
440+ { \
441+ SetMsgHandled(TRUE); \
442+ func((UINT)wParam, (UINT)LOWORD(lParam)); \
443+ lResult = 0; \
444+ if(IsMsgHandled()) \
445+ return TRUE; \
446+ }
447+
448+// void OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
449+#define MSG_WM_DRAWITEM(func) \
450+ if (uMsg == WM_DRAWITEM) \
451+ { \
452+ SetMsgHandled(TRUE); \
453+ func((UINT)wParam, (LPDRAWITEMSTRUCT)lParam); \
454+ lResult = TRUE; \
455+ if(IsMsgHandled()) \
456+ return TRUE; \
457+ }
458+
459+// void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
460+#define MSG_WM_MEASUREITEM(func) \
461+ if (uMsg == WM_MEASUREITEM) \
462+ { \
463+ SetMsgHandled(TRUE); \
464+ func((UINT)wParam, (LPMEASUREITEMSTRUCT)lParam); \
465+ lResult = TRUE; \
466+ if(IsMsgHandled()) \
467+ return TRUE; \
468+ }
469+
470+// void OnDeleteItem(int nIDCtl, LPDELETEITEMSTRUCT lpDeleteItemStruct)
471+#define MSG_WM_DELETEITEM(func) \
472+ if (uMsg == WM_DELETEITEM) \
473+ { \
474+ SetMsgHandled(TRUE); \
475+ func((UINT)wParam, (LPDELETEITEMSTRUCT)lParam); \
476+ lResult = TRUE; \
477+ if(IsMsgHandled()) \
478+ return TRUE; \
479+ }
480+
481+//int OnCharToItem(UINT nChar, UINT nIndex, CListBox listBox)
482+#define MSG_WM_CHARTOITEM(func) \
483+ if (uMsg == WM_CHARTOITEM) \
484+ { \
485+ SetMsgHandled(TRUE); \
486+ lResult = (LRESULT)func((UINT)LOWORD(wParam), (UINT)HIWORD(wParam), (HWND)lParam); \
487+ if(IsMsgHandled()) \
488+ return TRUE; \
489+ }
490+
491+// int OnVKeyToItem(UINT nKey, UINT nIndex, CListBox listBox)
492+#define MSG_WM_VKEYTOITEM(func) \
493+ if (uMsg == WM_VKEYTOITEM) \
494+ { \
495+ SetMsgHandled(TRUE); \
496+ lResult = (LRESULT)func((UINT)LOWORD(wParam), (UINT)HIWORD(wParam), (HWND)lParam); \
497+ if(IsMsgHandled()) \
498+ return TRUE; \
499+ }
500+
501+// HCURSOR OnQueryDragIcon()
502+#define MSG_WM_QUERYDRAGICON(func) \
503+ if (uMsg == WM_QUERYDRAGICON) \
504+ { \
505+ SetMsgHandled(TRUE); \
506+ lResult = (LRESULT)func(); \
507+ if(IsMsgHandled()) \
508+ return TRUE; \
509+ }
510+
511+// int OnCompareItem(int nIDCtl, LPCOMPAREITEMSTRUCT lpCompareItemStruct)
512+#define MSG_WM_COMPAREITEM(func) \
513+ if (uMsg == WM_COMPAREITEM) \
514+ { \
515+ SetMsgHandled(TRUE); \
516+ lResult = (LRESULT)func((UINT)wParam, (LPCOMPAREITEMSTRUCT)lParam); \
517+ if(IsMsgHandled()) \
518+ return TRUE; \
519+ }
520+
521+// void OnCompacting(UINT nCpuTime)
522+#define MSG_WM_COMPACTING(func) \
523+ if (uMsg == WM_COMPACTING) \
524+ { \
525+ SetMsgHandled(TRUE); \
526+ func((UINT)wParam); \
527+ lResult = 0; \
528+ if(IsMsgHandled()) \
529+ return TRUE; \
530+ }
531+
532+// BOOL OnNcCreate(LPCREATESTRUCT lpCreateStruct)
533+#define MSG_WM_NCCREATE(func) \
534+ if (uMsg == WM_NCCREATE) \
535+ { \
536+ SetMsgHandled(TRUE); \
537+ lResult = (LRESULT)func((LPCREATESTRUCT)lParam); \
538+ if(IsMsgHandled()) \
539+ return TRUE; \
540+ }
541+
542+// void OnNcDestroy()
543+#define MSG_WM_NCDESTROY(func) \
544+ if (uMsg == WM_NCDESTROY) \
545+ { \
546+ SetMsgHandled(TRUE); \
547+ func(); \
548+ lResult = 0; \
549+ if(IsMsgHandled()) \
550+ return TRUE; \
551+ }
552+
553+// LRESULT OnNcCalcSize(BOOL bCalcValidRects, LPARAM lParam)
554+#define MSG_WM_NCCALCSIZE(func) \
555+ if (uMsg == WM_NCCALCSIZE) \
556+ { \
557+ SetMsgHandled(TRUE); \
558+ lResult = func((BOOL)wParam, lParam); \
559+ if(IsMsgHandled()) \
560+ return TRUE; \
561+ }
562+
563+// UINT OnNcHitTest(CPoint point)
564+#define MSG_WM_NCHITTEST(func) \
565+ if (uMsg == WM_NCHITTEST) \
566+ { \
567+ SetMsgHandled(TRUE); \
568+ lResult = (LRESULT)func(_WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
569+ if(IsMsgHandled()) \
570+ return TRUE; \
571+ }
572+
573+// void OnNcPaint(CRgnHandle rgn)
574+#define MSG_WM_NCPAINT(func) \
575+ if (uMsg == WM_NCPAINT) \
576+ { \
577+ SetMsgHandled(TRUE); \
578+ func((HRGN)wParam); \
579+ lResult = 0; \
580+ if(IsMsgHandled()) \
581+ return TRUE; \
582+ }
583+
584+// BOOL OnNcActivate(BOOL bActive)
585+#define MSG_WM_NCACTIVATE(func) \
586+ if (uMsg == WM_NCACTIVATE) \
587+ { \
588+ SetMsgHandled(TRUE); \
589+ lResult = (LRESULT)func((BOOL)wParam); \
590+ if(IsMsgHandled()) \
591+ return TRUE; \
592+ }
593+
594+// UINT OnGetDlgCode(LPMSG lpMsg)
595+#define MSG_WM_GETDLGCODE(func) \
596+ if (uMsg == WM_GETDLGCODE) \
597+ { \
598+ SetMsgHandled(TRUE); \
599+ lResult = (LRESULT)func((LPMSG)lParam); \
600+ if(IsMsgHandled()) \
601+ return TRUE; \
602+ }
603+
604+// void OnNcMouseMove(UINT nHitTest, CPoint point)
605+#define MSG_WM_NCMOUSEMOVE(func) \
606+ if (uMsg == WM_NCMOUSEMOVE) \
607+ { \
608+ SetMsgHandled(TRUE); \
609+ func((UINT)wParam, _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
610+ lResult = 0; \
611+ if(IsMsgHandled()) \
612+ return TRUE; \
613+ }
614+
615+// void OnNcLButtonDown(UINT nHitTest, CPoint point)
616+#define MSG_WM_NCLBUTTONDOWN(func) \
617+ if (uMsg == WM_NCLBUTTONDOWN) \
618+ { \
619+ SetMsgHandled(TRUE); \
620+ func((UINT)wParam, _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
621+ lResult = 0; \
622+ if(IsMsgHandled()) \
623+ return TRUE; \
624+ }
625+
626+// void OnNcLButtonUp(UINT nHitTest, CPoint point)
627+#define MSG_WM_NCLBUTTONUP(func) \
628+ if (uMsg == WM_NCLBUTTONUP) \
629+ { \
630+ SetMsgHandled(TRUE); \
631+ func((UINT)wParam, _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
632+ lResult = 0; \
633+ if(IsMsgHandled()) \
634+ return TRUE; \
635+ }
636+
637+// void OnNcLButtonDblClk(UINT nHitTest, CPoint point)
638+#define MSG_WM_NCLBUTTONDBLCLK(func) \
639+ if (uMsg == WM_NCLBUTTONDBLCLK) \
640+ { \
641+ SetMsgHandled(TRUE); \
642+ func((UINT)wParam, _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
643+ lResult = 0; \
644+ if(IsMsgHandled()) \
645+ return TRUE; \
646+ }
647+
648+// void OnNcRButtonDown(UINT nHitTest, CPoint point)
649+#define MSG_WM_NCRBUTTONDOWN(func) \
650+ if (uMsg == WM_NCRBUTTONDOWN) \
651+ { \
652+ SetMsgHandled(TRUE); \
653+ func((UINT)wParam, _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
654+ lResult = 0; \
655+ if(IsMsgHandled()) \
656+ return TRUE; \
657+ }
658+
659+// void OnNcRButtonUp(UINT nHitTest, CPoint point)
660+#define MSG_WM_NCRBUTTONUP(func) \
661+ if (uMsg == WM_NCRBUTTONUP) \
662+ { \
663+ SetMsgHandled(TRUE); \
664+ func((UINT)wParam, _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
665+ lResult = 0; \
666+ if(IsMsgHandled()) \
667+ return TRUE; \
668+ }
669+
670+// void OnNcRButtonDblClk(UINT nHitTest, CPoint point)
671+#define MSG_WM_NCRBUTTONDBLCLK(func) \
672+ if (uMsg == WM_NCRBUTTONDBLCLK) \
673+ { \
674+ SetMsgHandled(TRUE); \
675+ func((UINT)wParam, _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
676+ lResult = 0; \
677+ if(IsMsgHandled()) \
678+ return TRUE; \
679+ }
680+
681+// void OnNcMButtonDown(UINT nHitTest, CPoint point)
682+#define MSG_WM_NCMBUTTONDOWN(func) \
683+ if (uMsg == WM_NCMBUTTONDOWN) \
684+ { \
685+ SetMsgHandled(TRUE); \
686+ func((UINT)wParam, _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
687+ lResult = 0; \
688+ if(IsMsgHandled()) \
689+ return TRUE; \
690+ }
691+
692+// void OnNcMButtonUp(UINT nHitTest, CPoint point)
693+#define MSG_WM_NCMBUTTONUP(func) \
694+ if (uMsg == WM_NCMBUTTONUP) \
695+ { \
696+ SetMsgHandled(TRUE); \
697+ func((UINT)wParam, _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
698+ lResult = 0; \
699+ if(IsMsgHandled()) \
700+ return TRUE; \
701+ }
702+
703+// void OnNcMButtonDblClk(UINT nHitTest, CPoint point)
704+#define MSG_WM_NCMBUTTONDBLCLK(func) \
705+ if (uMsg == WM_NCMBUTTONDBLCLK) \
706+ { \
707+ SetMsgHandled(TRUE); \
708+ func((UINT)wParam, _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
709+ lResult = 0; \
710+ if(IsMsgHandled()) \
711+ return TRUE; \
712+ }
713+
714+// void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
715+#define MSG_WM_KEYDOWN(func) \
716+ if (uMsg == WM_KEYDOWN) \
717+ { \
718+ SetMsgHandled(TRUE); \
719+ func((TCHAR)wParam, (UINT)lParam & 0xFFFF, (UINT)((lParam & 0xFFFF0000) >> 16)); \
720+ lResult = 0; \
721+ if(IsMsgHandled()) \
722+ return TRUE; \
723+ }
724+
725+// void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
726+#define MSG_WM_KEYUP(func) \
727+ if (uMsg == WM_KEYUP) \
728+ { \
729+ SetMsgHandled(TRUE); \
730+ func((TCHAR)wParam, (UINT)lParam & 0xFFFF, (UINT)((lParam & 0xFFFF0000) >> 16)); \
731+ lResult = 0; \
732+ if(IsMsgHandled()) \
733+ return TRUE; \
734+ }
735+
736+// void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
737+#define MSG_WM_CHAR(func) \
738+ if (uMsg == WM_CHAR) \
739+ { \
740+ SetMsgHandled(TRUE); \
741+ func((TCHAR)wParam, (UINT)lParam & 0xFFFF, (UINT)((lParam & 0xFFFF0000) >> 16)); \
742+ lResult = 0; \
743+ if(IsMsgHandled()) \
744+ return TRUE; \
745+ }
746+
747+// void OnDeadChar(UINT nChar, UINT nRepCnt, UINT nFlags)
748+#define MSG_WM_DEADCHAR(func) \
749+ if (uMsg == WM_DEADCHAR) \
750+ { \
751+ SetMsgHandled(TRUE); \
752+ func((TCHAR)wParam, (UINT)lParam & 0xFFFF, (UINT)((lParam & 0xFFFF0000) >> 16)); \
753+ lResult = 0; \
754+ if(IsMsgHandled()) \
755+ return TRUE; \
756+ }
757+
758+// void OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
759+#define MSG_WM_SYSKEYDOWN(func) \
760+ if (uMsg == WM_SYSKEYDOWN) \
761+ { \
762+ SetMsgHandled(TRUE); \
763+ func((TCHAR)wParam, (UINT)lParam & 0xFFFF, (UINT)((lParam & 0xFFFF0000) >> 16)); \
764+ lResult = 0; \
765+ if(IsMsgHandled()) \
766+ return TRUE; \
767+ }
768+
769+// void OnSysKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
770+#define MSG_WM_SYSKEYUP(func) \
771+ if (uMsg == WM_SYSKEYUP) \
772+ { \
773+ SetMsgHandled(TRUE); \
774+ func((TCHAR)wParam, (UINT)lParam & 0xFFFF, (UINT)((lParam & 0xFFFF0000) >> 16)); \
775+ lResult = 0; \
776+ if(IsMsgHandled()) \
777+ return TRUE; \
778+ }
779+
780+// void OnSysChar(UINT nChar, UINT nRepCnt, UINT nFlags)
781+#define MSG_WM_SYSCHAR(func) \
782+ if (uMsg == WM_SYSCHAR) \
783+ { \
784+ SetMsgHandled(TRUE); \
785+ func((TCHAR)wParam, (UINT)lParam & 0xFFFF, (UINT)((lParam & 0xFFFF0000) >> 16)); \
786+ lResult = 0; \
787+ if(IsMsgHandled()) \
788+ return TRUE; \
789+ }
790+
791+// void OnSysDeadChar(UINT nChar, UINT nRepCnt, UINT nFlags)
792+#define MSG_WM_SYSDEADCHAR(func) \
793+ if (uMsg == WM_SYSDEADCHAR) \
794+ { \
795+ SetMsgHandled(TRUE); \
796+ func((TCHAR)wParam, (UINT)lParam & 0xFFFF, (UINT)((lParam & 0xFFFF0000) >> 16)); \
797+ lResult = 0; \
798+ if(IsMsgHandled()) \
799+ return TRUE; \
800+ }
801+
802+// void OnSysCommand(UINT nID, LPARAM lParam)
803+#define MSG_WM_SYSCOMMAND(func) \
804+ if (uMsg == WM_SYSCOMMAND) \
805+ { \
806+ SetMsgHandled(TRUE); \
807+ func((UINT)wParam, _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
808+ lResult = 0; \
809+ if(IsMsgHandled()) \
810+ return TRUE; \
811+ }
812+
813+// void OnTCard(UINT idAction, DWORD dwActionData)
814+#define MSG_WM_TCARD(func) \
815+ if (uMsg == WM_TCARD) \
816+ { \
817+ SetMsgHandled(TRUE); \
818+ func((UINT)wParam, (DWORD)lParam); \
819+ lResult = 0; \
820+ if(IsMsgHandled()) \
821+ return TRUE; \
822+ }
823+
824+// void OnTimer(UINT_PTR nIDEvent)
825+#define MSG_WM_TIMER(func) \
826+ if (uMsg == WM_TIMER) \
827+ { \
828+ SetMsgHandled(TRUE); \
829+ func((UINT_PTR)wParam); \
830+ lResult = 0; \
831+ if(IsMsgHandled()) \
832+ return TRUE; \
833+ }
834+
835+// void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar pScrollBar)
836+#define MSG_WM_HSCROLL(func) \
837+ if (uMsg == WM_HSCROLL) \
838+ { \
839+ SetMsgHandled(TRUE); \
840+ func((int)LOWORD(wParam), (short)HIWORD(wParam), (HWND)lParam); \
841+ lResult = 0; \
842+ if(IsMsgHandled()) \
843+ return TRUE; \
844+ }
845+
846+// void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar pScrollBar)
847+#define MSG_WM_VSCROLL(func) \
848+ if (uMsg == WM_VSCROLL) \
849+ { \
850+ SetMsgHandled(TRUE); \
851+ func((int)LOWORD(wParam), (short)HIWORD(wParam), (HWND)lParam); \
852+ lResult = 0; \
853+ if(IsMsgHandled()) \
854+ return TRUE; \
855+ }
856+
857+// void OnInitMenu(CMenuHandle menu)
858+#define MSG_WM_INITMENU(func) \
859+ if (uMsg == WM_INITMENU) \
860+ { \
861+ SetMsgHandled(TRUE); \
862+ func((HMENU)wParam); \
863+ lResult = 0; \
864+ if(IsMsgHandled()) \
865+ return TRUE; \
866+ }
867+
868+// void OnInitMenuPopup(CMenuHandle menuPopup, UINT nIndex, BOOL bSysMenu)
869+#define MSG_WM_INITMENUPOPUP(func) \
870+ if (uMsg == WM_INITMENUPOPUP) \
871+ { \
872+ SetMsgHandled(TRUE); \
873+ func((HMENU)wParam, (UINT)LOWORD(lParam), (BOOL)HIWORD(lParam)); \
874+ lResult = 0; \
875+ if(IsMsgHandled()) \
876+ return TRUE; \
877+ }
878+
879+// void OnMenuSelect(UINT nItemID, UINT nFlags, CMenuHandle menu)
880+#define MSG_WM_MENUSELECT(func) \
881+ if (uMsg == WM_MENUSELECT) \
882+ { \
883+ SetMsgHandled(TRUE); \
884+ func((UINT)LOWORD(wParam), (UINT)HIWORD(wParam), (HMENU)lParam); \
885+ lResult = 0; \
886+ if(IsMsgHandled()) \
887+ return TRUE; \
888+ }
889+
890+// LRESULT OnMenuChar(UINT nChar, UINT nFlags, CMenuHandle menu)
891+#define MSG_WM_MENUCHAR(func) \
892+ if (uMsg == WM_MENUCHAR) \
893+ { \
894+ SetMsgHandled(TRUE); \
895+ lResult = func((TCHAR)LOWORD(wParam), (UINT)HIWORD(wParam), (HMENU)lParam); \
896+ if(IsMsgHandled()) \
897+ return TRUE; \
898+ }
899+
900+// LRESULT OnNotify(int idCtrl, LPNMHDR pnmh)
901+#define MSG_WM_NOTIFY(func) \
902+ if (uMsg == WM_NOTIFY) \
903+ { \
904+ SetMsgHandled(TRUE); \
905+ lResult = func((int)wParam, (LPNMHDR)lParam); \
906+ if(IsMsgHandled()) \
907+ return TRUE; \
908+ }
909+
910+// void OnEnterIdle(UINT nWhy, CWindow wndWho)
911+#define MSG_WM_ENTERIDLE(func) \
912+ if (uMsg == WM_ENTERIDLE) \
913+ { \
914+ SetMsgHandled(TRUE); \
915+ func((UINT)wParam, (HWND)lParam); \
916+ lResult = 0; \
917+ if(IsMsgHandled()) \
918+ return TRUE; \
919+ }
920+
921+// void OnMouseMove(UINT nFlags, CPoint point)
922+#define MSG_WM_MOUSEMOVE(func) \
923+ if (uMsg == WM_MOUSEMOVE) \
924+ { \
925+ SetMsgHandled(TRUE); \
926+ func((UINT)wParam, _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
927+ lResult = 0; \
928+ if(IsMsgHandled()) \
929+ return TRUE; \
930+ }
931+
932+// BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
933+#define MSG_WM_MOUSEWHEEL(func) \
934+ if (uMsg == WM_MOUSEWHEEL) \
935+ { \
936+ SetMsgHandled(TRUE); \
937+ lResult = (LRESULT)func((UINT)LOWORD(wParam), (short)HIWORD(wParam), _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
938+ if(IsMsgHandled()) \
939+ return TRUE; \
940+ }
941+
942+// void OnLButtonDown(UINT nFlags, CPoint point)
943+#define MSG_WM_LBUTTONDOWN(func) \
944+ if (uMsg == WM_LBUTTONDOWN) \
945+ { \
946+ SetMsgHandled(TRUE); \
947+ func((UINT)wParam, _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
948+ lResult = 0; \
949+ if(IsMsgHandled()) \
950+ return TRUE; \
951+ }
952+
953+// void OnLButtonUp(UINT nFlags, CPoint point)
954+#define MSG_WM_LBUTTONUP(func) \
955+ if (uMsg == WM_LBUTTONUP) \
956+ { \
957+ SetMsgHandled(TRUE); \
958+ func((UINT)wParam, _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
959+ lResult = 0; \
960+ if(IsMsgHandled()) \
961+ return TRUE; \
962+ }
963+
964+// void OnLButtonDblClk(UINT nFlags, CPoint point)
965+#define MSG_WM_LBUTTONDBLCLK(func) \
966+ if (uMsg == WM_LBUTTONDBLCLK) \
967+ { \
968+ SetMsgHandled(TRUE); \
969+ func((UINT)wParam, _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
970+ lResult = 0; \
971+ if(IsMsgHandled()) \
972+ return TRUE; \
973+ }
974+
975+// void OnRButtonDown(UINT nFlags, CPoint point)
976+#define MSG_WM_RBUTTONDOWN(func) \
977+ if (uMsg == WM_RBUTTONDOWN) \
978+ { \
979+ SetMsgHandled(TRUE); \
980+ func((UINT)wParam, _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
981+ lResult = 0; \
982+ if(IsMsgHandled()) \
983+ return TRUE; \
984+ }
985+
986+// void OnRButtonUp(UINT nFlags, CPoint point)
987+#define MSG_WM_RBUTTONUP(func) \
988+ if (uMsg == WM_RBUTTONUP) \
989+ { \
990+ SetMsgHandled(TRUE); \
991+ func((UINT)wParam, _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
992+ lResult = 0; \
993+ if(IsMsgHandled()) \
994+ return TRUE; \
995+ }
996+
997+// void OnRButtonDblClk(UINT nFlags, CPoint point)
998+#define MSG_WM_RBUTTONDBLCLK(func) \
999+ if (uMsg == WM_RBUTTONDBLCLK) \
1000+ { \
1001+ SetMsgHandled(TRUE); \
1002+ func((UINT)wParam, _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
1003+ lResult = 0; \
1004+ if(IsMsgHandled()) \
1005+ return TRUE; \
1006+ }
1007+
1008+// void OnMButtonDown(UINT nFlags, CPoint point)
1009+#define MSG_WM_MBUTTONDOWN(func) \
1010+ if (uMsg == WM_MBUTTONDOWN) \
1011+ { \
1012+ SetMsgHandled(TRUE); \
1013+ func((UINT)wParam, _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
1014+ lResult = 0; \
1015+ if(IsMsgHandled()) \
1016+ return TRUE; \
1017+ }
1018+
1019+// void OnMButtonUp(UINT nFlags, CPoint point)
1020+#define MSG_WM_MBUTTONUP(func) \
1021+ if (uMsg == WM_MBUTTONUP) \
1022+ { \
1023+ SetMsgHandled(TRUE); \
1024+ func((UINT)wParam, _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
1025+ lResult = 0; \
1026+ if(IsMsgHandled()) \
1027+ return TRUE; \
1028+ }
1029+
1030+// void OnMButtonDblClk(UINT nFlags, CPoint point)
1031+#define MSG_WM_MBUTTONDBLCLK(func) \
1032+ if (uMsg == WM_MBUTTONDBLCLK) \
1033+ { \
1034+ SetMsgHandled(TRUE); \
1035+ func((UINT)wParam, _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
1036+ lResult = 0; \
1037+ if(IsMsgHandled()) \
1038+ return TRUE; \
1039+ }
1040+
1041+// void OnParentNotify(UINT message, UINT nChildID, LPARAM lParam)
1042+#define MSG_WM_PARENTNOTIFY(func) \
1043+ if (uMsg == WM_PARENTNOTIFY) \
1044+ { \
1045+ SetMsgHandled(TRUE); \
1046+ func((UINT)LOWORD(wParam), (UINT)HIWORD(wParam), lParam); \
1047+ lResult = 0; \
1048+ if(IsMsgHandled()) \
1049+ return TRUE; \
1050+ }
1051+
1052+// void OnMDIActivate(CWindow wndActivate, CWindow wndDeactivate)
1053+#define MSG_WM_MDIACTIVATE(func) \
1054+ if (uMsg == WM_MDIACTIVATE) \
1055+ { \
1056+ SetMsgHandled(TRUE); \
1057+ func((HWND)wParam, (HWND)lParam); \
1058+ lResult = 0; \
1059+ if(IsMsgHandled()) \
1060+ return TRUE; \
1061+ }
1062+
1063+// void OnRenderFormat(UINT nFormat)
1064+#define MSG_WM_RENDERFORMAT(func) \
1065+ if (uMsg == WM_RENDERFORMAT) \
1066+ { \
1067+ SetMsgHandled(TRUE); \
1068+ func((UINT)wParam); \
1069+ lResult = 0; \
1070+ if(IsMsgHandled()) \
1071+ return TRUE; \
1072+ }
1073+
1074+// void OnRenderAllFormats()
1075+#define MSG_WM_RENDERALLFORMATS(func) \
1076+ if (uMsg == WM_RENDERALLFORMATS) \
1077+ { \
1078+ SetMsgHandled(TRUE); \
1079+ func(); \
1080+ lResult = 0; \
1081+ if(IsMsgHandled()) \
1082+ return TRUE; \
1083+ }
1084+
1085+// void OnDestroyClipboard()
1086+#define MSG_WM_DESTROYCLIPBOARD(func) \
1087+ if (uMsg == WM_DESTROYCLIPBOARD) \
1088+ { \
1089+ SetMsgHandled(TRUE); \
1090+ func(); \
1091+ lResult = 0; \
1092+ if(IsMsgHandled()) \
1093+ return TRUE; \
1094+ }
1095+
1096+// void OnDrawClipboard()
1097+#define MSG_WM_DRAWCLIPBOARD(func) \
1098+ if (uMsg == WM_DRAWCLIPBOARD) \
1099+ { \
1100+ SetMsgHandled(TRUE); \
1101+ func(); \
1102+ lResult = 0; \
1103+ if(IsMsgHandled()) \
1104+ return TRUE; \
1105+ }
1106+
1107+// void OnPaintClipboard(CWindow wndViewer, const LPPAINTSTRUCT lpPaintStruct)
1108+#define MSG_WM_PAINTCLIPBOARD(func) \
1109+ if (uMsg == WM_PAINTCLIPBOARD) \
1110+ { \
1111+ SetMsgHandled(TRUE); \
1112+ func((HWND)wParam, (const LPPAINTSTRUCT)::GlobalLock((HGLOBAL)lParam)); \
1113+ ::GlobalUnlock((HGLOBAL)lParam); \
1114+ lResult = 0; \
1115+ if(IsMsgHandled()) \
1116+ return TRUE; \
1117+ }
1118+
1119+// void OnVScrollClipboard(CWindow wndViewer, UINT nSBCode, UINT nPos)
1120+#define MSG_WM_VSCROLLCLIPBOARD(func) \
1121+ if (uMsg == WM_VSCROLLCLIPBOARD) \
1122+ { \
1123+ SetMsgHandled(TRUE); \
1124+ func((HWND)wParam, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam)); \
1125+ lResult = 0; \
1126+ if(IsMsgHandled()) \
1127+ return TRUE; \
1128+ }
1129+
1130+// void OnContextMenu(CWindow wnd, CPoint point)
1131+#define MSG_WM_CONTEXTMENU(func) \
1132+ if (uMsg == WM_CONTEXTMENU) \
1133+ { \
1134+ SetMsgHandled(TRUE); \
1135+ func((HWND)wParam, _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
1136+ lResult = 0; \
1137+ if(IsMsgHandled()) \
1138+ return TRUE; \
1139+ }
1140+
1141+// void OnSizeClipboard(CWindow wndViewer, const LPRECT lpRect)
1142+#define MSG_WM_SIZECLIPBOARD(func) \
1143+ if (uMsg == WM_SIZECLIPBOARD) \
1144+ { \
1145+ SetMsgHandled(TRUE); \
1146+ func((HWND)wParam, (const LPRECT)::GlobalLock((HGLOBAL)lParam)); \
1147+ ::GlobalUnlock((HGLOBAL)lParam); \
1148+ lResult = 0; \
1149+ if(IsMsgHandled()) \
1150+ return TRUE; \
1151+ }
1152+
1153+// void OnAskCbFormatName(UINT nMaxCount, LPTSTR lpszString)
1154+#define MSG_WM_ASKCBFORMATNAME(func) \
1155+ if (uMsg == WM_ASKCBFORMATNAME) \
1156+ { \
1157+ SetMsgHandled(TRUE); \
1158+ func((DWORD)wParam, (LPTSTR)lParam); \
1159+ lResult = 0; \
1160+ if(IsMsgHandled()) \
1161+ return TRUE; \
1162+ }
1163+
1164+// void OnChangeCbChain(CWindow wndRemove, CWindow wndAfter)
1165+#define MSG_WM_CHANGECBCHAIN(func) \
1166+ if (uMsg == WM_CHANGECBCHAIN) \
1167+ { \
1168+ SetMsgHandled(TRUE); \
1169+ func((HWND)wParam, (HWND)lParam); \
1170+ lResult = 0; \
1171+ if(IsMsgHandled()) \
1172+ return TRUE; \
1173+ }
1174+
1175+// void OnHScrollClipboard(CWindow wndViewer, UINT nSBCode, UINT nPos)
1176+#define MSG_WM_HSCROLLCLIPBOARD(func) \
1177+ if (uMsg == WM_HSCROLLCLIPBOARD) \
1178+ { \
1179+ SetMsgHandled(TRUE); \
1180+ func((HWND)wParam, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam)); \
1181+ lResult = 0; \
1182+ if(IsMsgHandled()) \
1183+ return TRUE; \
1184+ }
1185+
1186+// BOOL OnQueryNewPalette()
1187+#define MSG_WM_QUERYNEWPALETTE(func) \
1188+ if (uMsg == WM_QUERYNEWPALETTE) \
1189+ { \
1190+ SetMsgHandled(TRUE); \
1191+ lResult = (LRESULT)func(); \
1192+ if(IsMsgHandled()) \
1193+ return TRUE; \
1194+ }
1195+
1196+// void OnPaletteChanged(CWindow wndFocus)
1197+#define MSG_WM_PALETTECHANGED(func) \
1198+ if (uMsg == WM_PALETTECHANGED) \
1199+ { \
1200+ SetMsgHandled(TRUE); \
1201+ func((HWND)wParam); \
1202+ lResult = 0; \
1203+ if(IsMsgHandled()) \
1204+ return TRUE; \
1205+ }
1206+
1207+// void OnPaletteIsChanging(CWindow wndPalChg)
1208+#define MSG_WM_PALETTEISCHANGING(func) \
1209+ if (uMsg == WM_PALETTEISCHANGING) \
1210+ { \
1211+ SetMsgHandled(TRUE); \
1212+ func((HWND)wParam); \
1213+ lResult = 0; \
1214+ if(IsMsgHandled()) \
1215+ return TRUE; \
1216+ }
1217+
1218+// void OnDropFiles(HDROP hDropInfo)
1219+#define MSG_WM_DROPFILES(func) \
1220+ if (uMsg == WM_DROPFILES) \
1221+ { \
1222+ SetMsgHandled(TRUE); \
1223+ func((HDROP)wParam); \
1224+ lResult = 0; \
1225+ if(IsMsgHandled()) \
1226+ return TRUE; \
1227+ }
1228+
1229+// void OnWindowPosChanging(LPWINDOWPOS lpWndPos)
1230+#define MSG_WM_WINDOWPOSCHANGING(func) \
1231+ if (uMsg == WM_WINDOWPOSCHANGING) \
1232+ { \
1233+ SetMsgHandled(TRUE); \
1234+ func((LPWINDOWPOS)lParam); \
1235+ lResult = 0; \
1236+ if(IsMsgHandled()) \
1237+ return TRUE; \
1238+ }
1239+
1240+// void OnWindowPosChanged(LPWINDOWPOS lpWndPos)
1241+#define MSG_WM_WINDOWPOSCHANGED(func) \
1242+ if (uMsg == WM_WINDOWPOSCHANGED) \
1243+ { \
1244+ SetMsgHandled(TRUE); \
1245+ func((LPWINDOWPOS)lParam); \
1246+ lResult = 0; \
1247+ if(IsMsgHandled()) \
1248+ return TRUE; \
1249+ }
1250+
1251+// void OnExitMenuLoop(BOOL fIsTrackPopupMenu)
1252+#define MSG_WM_EXITMENULOOP(func) \
1253+ if (uMsg == WM_EXITMENULOOP) \
1254+ { \
1255+ SetMsgHandled(TRUE); \
1256+ func((BOOL)wParam); \
1257+ lResult = 0; \
1258+ if(IsMsgHandled()) \
1259+ return TRUE; \
1260+ }
1261+
1262+// void OnEnterMenuLoop(BOOL fIsTrackPopupMenu)
1263+#define MSG_WM_ENTERMENULOOP(func) \
1264+ if (uMsg == WM_ENTERMENULOOP) \
1265+ { \
1266+ SetMsgHandled(TRUE); \
1267+ func((BOOL)wParam); \
1268+ lResult = 0; \
1269+ if(IsMsgHandled()) \
1270+ return TRUE; \
1271+ }
1272+
1273+// void OnStyleChanged(int nStyleType, LPSTYLESTRUCT lpStyleStruct)
1274+#define MSG_WM_STYLECHANGED(func) \
1275+ if (uMsg == WM_STYLECHANGED) \
1276+ { \
1277+ SetMsgHandled(TRUE); \
1278+ func((UINT)wParam, (LPSTYLESTRUCT)lParam); \
1279+ lResult = 0; \
1280+ if(IsMsgHandled()) \
1281+ return TRUE; \
1282+ }
1283+
1284+// void OnStyleChanging(int nStyleType, LPSTYLESTRUCT lpStyleStruct)
1285+#define MSG_WM_STYLECHANGING(func) \
1286+ if (uMsg == WM_STYLECHANGING) \
1287+ { \
1288+ SetMsgHandled(TRUE); \
1289+ func((UINT)wParam, (LPSTYLESTRUCT)lParam); \
1290+ lResult = 0; \
1291+ if(IsMsgHandled()) \
1292+ return TRUE; \
1293+ }
1294+
1295+// void OnSizing(UINT fwSide, LPRECT pRect)
1296+#define MSG_WM_SIZING(func) \
1297+ if (uMsg == WM_SIZING) \
1298+ { \
1299+ SetMsgHandled(TRUE); \
1300+ func((UINT)wParam, (LPRECT)lParam); \
1301+ lResult = TRUE; \
1302+ if(IsMsgHandled()) \
1303+ return TRUE; \
1304+ }
1305+
1306+// void OnMoving(UINT fwSide, LPRECT pRect)
1307+#define MSG_WM_MOVING(func) \
1308+ if (uMsg == WM_MOVING) \
1309+ { \
1310+ SetMsgHandled(TRUE); \
1311+ func((UINT)wParam, (LPRECT)lParam); \
1312+ lResult = TRUE; \
1313+ if(IsMsgHandled()) \
1314+ return TRUE; \
1315+ }
1316+
1317+// void OnCaptureChanged(CWindow wnd)
1318+#define MSG_WM_CAPTURECHANGED(func) \
1319+ if (uMsg == WM_CAPTURECHANGED) \
1320+ { \
1321+ SetMsgHandled(TRUE); \
1322+ func((HWND)lParam); \
1323+ lResult = 0; \
1324+ if(IsMsgHandled()) \
1325+ return TRUE; \
1326+ }
1327+
1328+// BOOL OnDeviceChange(UINT nEventType, DWORD dwData)
1329+#define MSG_WM_DEVICECHANGE(func) \
1330+ if (uMsg == WM_DEVICECHANGE) \
1331+ { \
1332+ SetMsgHandled(TRUE); \
1333+ lResult = (LRESULT)func((UINT)wParam, (DWORD)lParam); \
1334+ if(IsMsgHandled()) \
1335+ return TRUE; \
1336+ }
1337+
1338+// void OnCommand(UINT uNotifyCode, int nID, CWindow wndCtl)
1339+#define MSG_WM_COMMAND(func) \
1340+ if (uMsg == WM_COMMAND) \
1341+ { \
1342+ SetMsgHandled(TRUE); \
1343+ func((UINT)HIWORD(wParam), (int)LOWORD(wParam), (HWND)lParam); \
1344+ lResult = 0; \
1345+ if(IsMsgHandled()) \
1346+ return TRUE; \
1347+ }
1348+
1349+// void OnDisplayChange(UINT uBitsPerPixel, CSize sizeScreen)
1350+#define MSG_WM_DISPLAYCHANGE(func) \
1351+ if (uMsg == WM_DISPLAYCHANGE) \
1352+ { \
1353+ SetMsgHandled(TRUE); \
1354+ func((UINT)wParam, _WTYPES_NS::CSize(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
1355+ lResult = 0; \
1356+ if(IsMsgHandled()) \
1357+ return TRUE; \
1358+ }
1359+
1360+// void OnEnterSizeMove()
1361+#define MSG_WM_ENTERSIZEMOVE(func) \
1362+ if (uMsg == WM_ENTERSIZEMOVE) \
1363+ { \
1364+ SetMsgHandled(TRUE); \
1365+ func(); \
1366+ lResult = 0; \
1367+ if(IsMsgHandled()) \
1368+ return TRUE; \
1369+ }
1370+
1371+// void OnExitSizeMove()
1372+#define MSG_WM_EXITSIZEMOVE(func) \
1373+ if (uMsg == WM_EXITSIZEMOVE) \
1374+ { \
1375+ SetMsgHandled(TRUE); \
1376+ func(); \
1377+ lResult = 0; \
1378+ if(IsMsgHandled()) \
1379+ return TRUE; \
1380+ }
1381+
1382+// HFONT OnGetFont()
1383+#define MSG_WM_GETFONT(func) \
1384+ if (uMsg == WM_GETFONT) \
1385+ { \
1386+ SetMsgHandled(TRUE); \
1387+ lResult = (LRESULT)func(); \
1388+ if(IsMsgHandled()) \
1389+ return TRUE; \
1390+ }
1391+
1392+// LRESULT OnGetHotKey()
1393+#define MSG_WM_GETHOTKEY(func) \
1394+ if (uMsg == WM_GETHOTKEY) \
1395+ { \
1396+ SetMsgHandled(TRUE); \
1397+ lResult = func(); \
1398+ if(IsMsgHandled()) \
1399+ return TRUE; \
1400+ }
1401+
1402+// HICON OnGetIcon()
1403+#define MSG_WM_GETICON(func) \
1404+ if (uMsg == WM_GETICON) \
1405+ { \
1406+ SetMsgHandled(TRUE); \
1407+ lResult = (LRESULT)func((UINT)wParam); \
1408+ if(IsMsgHandled()) \
1409+ return TRUE; \
1410+ }
1411+
1412+// int OnGetText(int cchTextMax, LPTSTR lpszText)
1413+#define MSG_WM_GETTEXT(func) \
1414+ if (uMsg == WM_GETTEXT) \
1415+ { \
1416+ SetMsgHandled(TRUE); \
1417+ lResult = (LRESULT)func((int)wParam, (LPTSTR)lParam); \
1418+ if(IsMsgHandled()) \
1419+ return TRUE; \
1420+ }
1421+
1422+// int OnGetTextLength()
1423+#define MSG_WM_GETTEXTLENGTH(func) \
1424+ if (uMsg == WM_GETTEXTLENGTH) \
1425+ { \
1426+ SetMsgHandled(TRUE); \
1427+ lResult = (LRESULT)func(); \
1428+ if(IsMsgHandled()) \
1429+ return TRUE; \
1430+ }
1431+
1432+// void OnHelp(LPHELPINFO lpHelpInfo)
1433+#define MSG_WM_HELP(func) \
1434+ if (uMsg == WM_HELP) \
1435+ { \
1436+ SetMsgHandled(TRUE); \
1437+ func((LPHELPINFO)lParam); \
1438+ lResult = TRUE; \
1439+ if(IsMsgHandled()) \
1440+ return TRUE; \
1441+ }
1442+
1443+// void OnHotKey(int nHotKeyID, UINT uModifiers, UINT uVirtKey)
1444+#define MSG_WM_HOTKEY(func) \
1445+ if (uMsg == WM_HOTKEY) \
1446+ { \
1447+ SetMsgHandled(TRUE); \
1448+ func((int)wParam, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam)); \
1449+ lResult = 0; \
1450+ if(IsMsgHandled()) \
1451+ return TRUE; \
1452+ }
1453+
1454+// void OnInputLangChange(DWORD dwCharSet, HKL hKbdLayout)
1455+#define MSG_WM_INPUTLANGCHANGE(func) \
1456+ if (uMsg == WM_INPUTLANGCHANGE) \
1457+ { \
1458+ SetMsgHandled(TRUE); \
1459+ func((DWORD)wParam, (HKL)lParam); \
1460+ lResult = TRUE; \
1461+ if(IsMsgHandled()) \
1462+ return TRUE; \
1463+ }
1464+
1465+// void OnInputLangChangeRequest(BOOL bSysCharSet, HKL hKbdLayout)
1466+#define MSG_WM_INPUTLANGCHANGEREQUEST(func) \
1467+ if (uMsg == WM_INPUTLANGCHANGEREQUEST) \
1468+ { \
1469+ SetMsgHandled(TRUE); \
1470+ func((BOOL)wParam, (HKL)lParam); \
1471+ lResult = 0; \
1472+ if(IsMsgHandled()) \
1473+ return TRUE; \
1474+ }
1475+
1476+// void OnNextDlgCtl(BOOL bHandle, WPARAM wCtlFocus)
1477+#define MSG_WM_NEXTDLGCTL(func) \
1478+ if (uMsg == WM_NEXTDLGCTL) \
1479+ { \
1480+ SetMsgHandled(TRUE); \
1481+ func((BOOL)LOWORD(lParam), wParam); \
1482+ lResult = 0; \
1483+ if(IsMsgHandled()) \
1484+ return TRUE; \
1485+ }
1486+
1487+// void OnNextMenu(int nVirtKey, LPMDINEXTMENU lpMdiNextMenu)
1488+#define MSG_WM_NEXTMENU(func) \
1489+ if (uMsg == WM_NEXTMENU) \
1490+ { \
1491+ SetMsgHandled(TRUE); \
1492+ func((int)wParam, (LPMDINEXTMENU)lParam); \
1493+ lResult = 0; \
1494+ if(IsMsgHandled()) \
1495+ return TRUE; \
1496+ }
1497+
1498+// int OnNotifyFormat(CWindow wndFrom, int nCommand)
1499+#define MSG_WM_NOTIFYFORMAT(func) \
1500+ if (uMsg == WM_NOTIFYFORMAT) \
1501+ { \
1502+ SetMsgHandled(TRUE); \
1503+ lResult = (LRESULT)func((HWND)wParam, (int)lParam); \
1504+ if(IsMsgHandled()) \
1505+ return TRUE; \
1506+ }
1507+
1508+// BOOL OnPowerBroadcast(DWORD dwPowerEvent, DWORD dwData)
1509+#define MSG_WM_POWERBROADCAST(func) \
1510+ if (uMsg == WM_POWERBROADCAST) \
1511+ { \
1512+ SetMsgHandled(TRUE); \
1513+ lResult = (LRESULT)func((DWORD)wParam, (DWORD)lParam); \
1514+ if(IsMsgHandled()) \
1515+ return TRUE; \
1516+ }
1517+
1518+// void OnPrint(CDCHandle dc, UINT uFlags)
1519+#define MSG_WM_PRINT(func) \
1520+ if (uMsg == WM_PRINT) \
1521+ { \
1522+ SetMsgHandled(TRUE); \
1523+ func((HDC)wParam, (UINT)lParam); \
1524+ lResult = 0; \
1525+ if(IsMsgHandled()) \
1526+ return TRUE; \
1527+ }
1528+
1529+// void OnPrintClient(CDCHandle dc, UINT uFlags)
1530+#define MSG_WM_PRINTCLIENT(func) \
1531+ if (uMsg == WM_PRINTCLIENT) \
1532+ { \
1533+ SetMsgHandled(TRUE); \
1534+ func((HDC)wParam, (UINT)lParam); \
1535+ lResult = 0; \
1536+ if(IsMsgHandled()) \
1537+ return TRUE; \
1538+ }
1539+
1540+// void OnRasDialEvent(RASCONNSTATE rasconnstate, DWORD dwError)
1541+#define MSG_WM_RASDIALEVENT(func) \
1542+ if (uMsg == WM_RASDIALEVENT) \
1543+ { \
1544+ SetMsgHandled(TRUE); \
1545+ func((RASCONNSTATE)wParam, (DWORD)lParam); \
1546+ lResult = TRUE; \
1547+ if(IsMsgHandled()) \
1548+ return TRUE; \
1549+ }
1550+
1551+// void OnSetFont(CFontHandle font, BOOL bRedraw)
1552+#define MSG_WM_SETFONT(func) \
1553+ if (uMsg == WM_SETFONT) \
1554+ { \
1555+ SetMsgHandled(TRUE); \
1556+ func((HFONT)wParam, (BOOL)LOWORD(lParam)); \
1557+ lResult = 0; \
1558+ if(IsMsgHandled()) \
1559+ return TRUE; \
1560+ }
1561+
1562+// int OnSetHotKey(int nVirtKey, UINT uFlags)
1563+#define MSG_WM_SETHOTKEY(func) \
1564+ if (uMsg == WM_SETHOTKEY) \
1565+ { \
1566+ SetMsgHandled(TRUE); \
1567+ lResult = (LRESULT)func((int)LOBYTE(LOWORD(wParam)), (UINT)HIBYTE(LOWORD(wParam))); \
1568+ if(IsMsgHandled()) \
1569+ return TRUE; \
1570+ }
1571+
1572+// HICON OnSetIcon(UINT uType, HICON hIcon)
1573+#define MSG_WM_SETICON(func) \
1574+ if (uMsg == WM_SETICON) \
1575+ { \
1576+ SetMsgHandled(TRUE); \
1577+ lResult = (LRESULT)func((UINT)wParam, (HICON)lParam); \
1578+ if(IsMsgHandled()) \
1579+ return TRUE; \
1580+ }
1581+
1582+// void OnSetRedraw(BOOL bRedraw)
1583+#define MSG_WM_SETREDRAW(func) \
1584+ if (uMsg == WM_SETREDRAW) \
1585+ { \
1586+ SetMsgHandled(TRUE); \
1587+ func((BOOL)wParam); \
1588+ lResult = 0; \
1589+ if(IsMsgHandled()) \
1590+ return TRUE; \
1591+ }
1592+
1593+// int OnSetText(LPCTSTR lpstrText)
1594+#define MSG_WM_SETTEXT(func) \
1595+ if (uMsg == WM_SETTEXT) \
1596+ { \
1597+ SetMsgHandled(TRUE); \
1598+ lResult = (LRESULT)func((LPCTSTR)lParam); \
1599+ if(IsMsgHandled()) \
1600+ return TRUE; \
1601+ }
1602+
1603+// void OnUserChanged()
1604+#define MSG_WM_USERCHANGED(func) \
1605+ if (uMsg == WM_USERCHANGED) \
1606+ { \
1607+ SetMsgHandled(TRUE); \
1608+ func(); \
1609+ lResult = 0; \
1610+ if(IsMsgHandled()) \
1611+ return TRUE; \
1612+ }
1613+
1614+///////////////////////////////////////////////////////////////////////////////
1615+// New NT4 & NT5 messages
1616+
1617+#if(_WIN32_WINNT >= 0x0400)
1618+
1619+// void OnMouseHover(WPARAM wParam, CPoint ptPos)
1620+#define MSG_WM_MOUSEHOVER(func) \
1621+ if (uMsg == WM_MOUSEHOVER) \
1622+ { \
1623+ SetMsgHandled(TRUE); \
1624+ func(wParam, _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
1625+ lResult = 0; \
1626+ if(IsMsgHandled()) \
1627+ return TRUE; \
1628+ }
1629+
1630+// void OnMouseLeave()
1631+#define MSG_WM_MOUSELEAVE(func) \
1632+ if (uMsg == WM_MOUSELEAVE) \
1633+ { \
1634+ SetMsgHandled(TRUE); \
1635+ func(); \
1636+ lResult = 0; \
1637+ if(IsMsgHandled()) \
1638+ return TRUE; \
1639+ }
1640+
1641+#endif /* _WIN32_WINNT >= 0x0400 */
1642+
1643+#if(WINVER >= 0x0500)
1644+
1645+// void OnMenuRButtonUp(WPARAM wParam, CMenuHandle menu)
1646+#define MSG_WM_MENURBUTTONUP(func) \
1647+ if (uMsg == WM_MENURBUTTONUP) \
1648+ { \
1649+ SetMsgHandled(TRUE); \
1650+ func(wParam, (HMENU)lParam); \
1651+ lResult = 0; \
1652+ if(IsMsgHandled()) \
1653+ return TRUE; \
1654+ }
1655+
1656+// LRESULT OnMenuDrag(WPARAM wParam, CMenuHandle menu)
1657+#define MSG_WM_MENUDRAG(func) \
1658+ if (uMsg == WM_MENUDRAG) \
1659+ { \
1660+ SetMsgHandled(TRUE); \
1661+ lResult = func(wParam, (HMENU)lParam); \
1662+ if(IsMsgHandled()) \
1663+ return TRUE; \
1664+ }
1665+
1666+// LRESULT OnMenuGetObject(PMENUGETOBJECTINFO info)
1667+#define MSG_WM_MENUGETOBJECT(func) \
1668+ if (uMsg == WM_MENUGETOBJECT) \
1669+ { \
1670+ SetMsgHandled(TRUE); \
1671+ lResult = func((PMENUGETOBJECTINFO)lParam); \
1672+ if(IsMsgHandled()) \
1673+ return TRUE; \
1674+ }
1675+
1676+// void OnUnInitMenuPopup(UINT nID, CMenuHandle menu)
1677+#define MSG_WM_UNINITMENUPOPUP(func) \
1678+ if (uMsg == WM_UNINITMENUPOPUP) \
1679+ { \
1680+ SetMsgHandled(TRUE); \
1681+ func((UINT)HIWORD(lParam), (HMENU)wParam); \
1682+ lResult = 0; \
1683+ if(IsMsgHandled()) \
1684+ return TRUE; \
1685+ }
1686+
1687+// void OnMenuCommand(WPARAM nIndex, CMenuHandle menu)
1688+#define MSG_WM_MENUCOMMAND(func) \
1689+ if (uMsg == WM_MENUCOMMAND) \
1690+ { \
1691+ SetMsgHandled(TRUE); \
1692+ func(wParam, (HMENU)lParam); \
1693+ lResult = 0; \
1694+ if(IsMsgHandled()) \
1695+ return TRUE; \
1696+ }
1697+
1698+#endif /* WINVER >= 0x0500 */
1699+
1700+#if(_WIN32_WINNT >= 0x0500)
1701+
1702+// BOOL OnAppCommand(CWindow wndFocus, short cmd, WORD uDevice, int dwKeys)
1703+#define MSG_WM_APPCOMMAND(func) \
1704+ if (uMsg == WM_APPCOMMAND) \
1705+ { \
1706+ SetMsgHandled(TRUE); \
1707+ lResult = (LRESULT)func((HWND)wParam, GET_APPCOMMAND_LPARAM(lParam), GET_DEVICE_LPARAM(lParam), GET_KEYSTATE_LPARAM(lParam)); \
1708+ if(IsMsgHandled()) \
1709+ return TRUE; \
1710+ }
1711+
1712+// void OnNCXButtonDown(int fwButton, short nHittest, CPoint ptPos)
1713+#define MSG_WM_NCXBUTTONDOWN(func) \
1714+ if (uMsg == WM_NCXBUTTONDOWN) \
1715+ { \
1716+ SetMsgHandled(TRUE); \
1717+ func(GET_XBUTTON_WPARAM(wParam), GET_NCHITTEST_WPARAM(wParam), _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
1718+ lResult = 0; \
1719+ if(IsMsgHandled()) \
1720+ return TRUE; \
1721+ }
1722+
1723+// void OnNCXButtonUp(int fwButton, short nHittest, CPoint ptPos)
1724+#define MSG_WM_NCXBUTTONUP(func) \
1725+ if (uMsg == WM_NCXBUTTONUP) \
1726+ { \
1727+ SetMsgHandled(TRUE); \
1728+ func(GET_XBUTTON_WPARAM(wParam), GET_NCHITTEST_WPARAM(wParam), _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
1729+ lResult = 0; \
1730+ if(IsMsgHandled()) \
1731+ return TRUE; \
1732+ }
1733+
1734+// void OnNCXButtonDblClk(int fwButton, short nHittest, CPoint ptPos)
1735+#define MSG_WM_NCXBUTTONDBLCLK(func) \
1736+ if (uMsg == WM_NCXBUTTONDBLCLK) \
1737+ { \
1738+ SetMsgHandled(TRUE); \
1739+ func(GET_XBUTTON_WPARAM(wParam), GET_NCHITTEST_WPARAM(wParam), _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
1740+ lResult = 0; \
1741+ if(IsMsgHandled()) \
1742+ return TRUE; \
1743+ }
1744+
1745+// void OnXButtonDown(int fwButton, int dwKeys, CPoint ptPos)
1746+#define MSG_WM_XBUTTONDOWN(func) \
1747+ if (uMsg == WM_XBUTTONDOWN) \
1748+ { \
1749+ SetMsgHandled(TRUE); \
1750+ func(GET_XBUTTON_WPARAM(wParam), GET_KEYSTATE_WPARAM(wParam), _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
1751+ lResult = 0; \
1752+ if(IsMsgHandled()) \
1753+ return TRUE; \
1754+ }
1755+
1756+// void OnXButtonUp(int fwButton, int dwKeys, CPoint ptPos)
1757+#define MSG_WM_XBUTTONUP(func) \
1758+ if (uMsg == WM_XBUTTONUP) \
1759+ { \
1760+ SetMsgHandled(TRUE); \
1761+ func(GET_XBUTTON_WPARAM(wParam), GET_KEYSTATE_WPARAM(wParam), _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
1762+ lResult = 0; \
1763+ if(IsMsgHandled()) \
1764+ return TRUE; \
1765+ }
1766+
1767+// void OnXButtonDblClk(int fwButton, int dwKeys, CPoint ptPos)
1768+#define MSG_WM_XBUTTONDBLCLK(func) \
1769+ if (uMsg == WM_XBUTTONDBLCLK) \
1770+ { \
1771+ SetMsgHandled(TRUE); \
1772+ func(GET_XBUTTON_WPARAM(wParam), GET_KEYSTATE_WPARAM(wParam), _WTYPES_NS::CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); \
1773+ lResult = 0; \
1774+ if(IsMsgHandled()) \
1775+ return TRUE; \
1776+ }
1777+
1778+// void OnChangeUIState(WORD nAction, WORD nState)
1779+#define MSG_WM_CHANGEUISTATE(func) \
1780+ if (uMsg == WM_CHANGEUISTATE) \
1781+ { \
1782+ SetMsgHandled(TRUE); \
1783+ func(LOWORD(wParam), HIWORD(wParam)); \
1784+ lResult = 0; \
1785+ if(IsMsgHandled()) \
1786+ return TRUE; \
1787+ }
1788+
1789+// void OnUpdateUIState(WORD nAction, WORD nState)
1790+#define MSG_WM_UPDATEUISTATE(func) \
1791+ if (uMsg == WM_UPDATEUISTATE) \
1792+ { \
1793+ SetMsgHandled(TRUE); \
1794+ func(LOWORD(wParam), HIWORD(wParam)); \
1795+ lResult = 0; \
1796+ if(IsMsgHandled()) \
1797+ return TRUE; \
1798+ }
1799+
1800+// LRESULT OnQueryUIState()
1801+#define MSG_WM_QUERYUISTATE(func) \
1802+ if (uMsg == WM_QUERYUISTATE) \
1803+ { \
1804+ SetMsgHandled(TRUE); \
1805+ lResult = func(); \
1806+ if(IsMsgHandled()) \
1807+ return TRUE; \
1808+ }
1809+
1810+#endif // (_WIN32_WINNT >= 0x0500)
1811+
1812+#if(_WIN32_WINNT >= 0x0501)
1813+
1814+// void OnInput(WPARAM RawInputCode, HRAWINPUT hRawInput)
1815+#define MSG_WM_INPUT(func) \
1816+ if (uMsg == WM_INPUT) \
1817+ { \
1818+ SetMsgHandled(TRUE); \
1819+ func(GET_RAWINPUT_CODE_WPARAM(wParam), (HRAWINPUT)lParam); \
1820+ lResult = 0; \
1821+ if(IsMsgHandled()) \
1822+ return TRUE; \
1823+ }
1824+
1825+// void OnUniChar(TCHAR nChar, UINT nRepCnt, UINT nFlags)
1826+#define MSG_WM_UNICHAR(func) \
1827+ if (uMsg == WM_UNICHAR) \
1828+ { \
1829+ SetMsgHandled(TRUE); \
1830+ func((TCHAR)wParam, (UINT)lParam & 0xFFFF, (UINT)((lParam & 0xFFFF0000) >> 16)); \
1831+ if(IsMsgHandled()) \
1832+ { \
1833+ lResult = (wParam == UNICODE_NOCHAR) ? TRUE : FALSE; \
1834+ return TRUE; \
1835+ } \
1836+ }
1837+
1838+// void OnWTSSessionChange(WPARAM nStatusCode, PWTSSESSION_NOTIFICATION nSessionID)
1839+#define MSG_WM_WTSSESSION_CHANGE(func) \
1840+ if (uMsg == WM_WTSSESSION_CHANGE) \
1841+ { \
1842+ SetMsgHandled(TRUE); \
1843+ func(wParam, (PWTSSESSION_NOTIFICATION)lParam); \
1844+ lResult = 0; \
1845+ if(IsMsgHandled()) \
1846+ return TRUE; \
1847+ }
1848+
1849+// OnThemeChanged()
1850+#define MSG_WM_THEMECHANGED(func) \
1851+ if (uMsg == WM_THEMECHANGED) \
1852+ { \
1853+ SetMsgHandled(TRUE); \
1854+ func(); \
1855+ lResult = 0; \
1856+ if(IsMsgHandled()) \
1857+ return TRUE; \
1858+ }
1859+
1860+#endif /* _WIN32_WINNT >= 0x0501 */
1861+
1862+///////////////////////////////////////////////////////////////////////////////
1863+// ATL defined messages
1864+
1865+// BOOL OnForwardMsg(LPMSG Msg, DWORD nUserData)
1866+#define MSG_WM_FORWARDMSG(func) \
1867+ if (uMsg == WM_FORWARDMSG) \
1868+ { \
1869+ SetMsgHandled(TRUE); \
1870+ lResult = (LRESULT)func((LPMSG)lParam, (DWORD)wParam); \
1871+ if(IsMsgHandled()) \
1872+ return TRUE; \
1873+ }
1874+
1875+///////////////////////////////////////////////////////////////////////////////
1876+// Dialog specific messages
1877+
1878+// LRESULT OnDMGetDefID()
1879+#define MSG_DM_GETDEFID(func) \
1880+ if (uMsg == DM_GETDEFID) \
1881+ { \
1882+ SetMsgHandled(TRUE); \
1883+ lResult = func(); \
1884+ if(IsMsgHandled()) \
1885+ return TRUE; \
1886+ }
1887+
1888+// void OnDMSetDefID(UINT DefID)
1889+#define MSG_DM_SETDEFID(func) \
1890+ if (uMsg == DM_SETDEFID) \
1891+ { \
1892+ SetMsgHandled(TRUE); \
1893+ func((UINT)wParam); \
1894+ lResult = TRUE; \
1895+ if(IsMsgHandled()) \
1896+ return TRUE; \
1897+ }
1898+
1899+// void OnDMReposition()
1900+#define MSG_DM_REPOSITION(func) \
1901+ if (uMsg == DM_REPOSITION) \
1902+ { \
1903+ SetMsgHandled(TRUE); \
1904+ func(); \
1905+ lResult = 0; \
1906+ if(IsMsgHandled()) \
1907+ return TRUE; \
1908+ }
1909+
1910+///////////////////////////////////////////////////////////////////////////////
1911+// Reflected messages
1912+
1913+// void OnReflectedCommand(UINT uNotifyCode, int nID, CWindow wndCtl)
1914+#define MSG_OCM_COMMAND(func) \
1915+ if (uMsg == OCM_COMMAND) \
1916+ { \
1917+ SetMsgHandled(TRUE); \
1918+ func((UINT)HIWORD(wParam), (int)LOWORD(wParam), (HWND)lParam); \
1919+ lResult = 0; \
1920+ if(IsMsgHandled()) \
1921+ return TRUE; \
1922+ }
1923+
1924+// LRESULT OnReflectedNotify(int idCtrl, LPNMHDR pnmh)
1925+#define MSG_OCM_NOTIFY(func) \
1926+ if (uMsg == OCM_NOTIFY) \
1927+ { \
1928+ SetMsgHandled(TRUE); \
1929+ lResult = func((int)wParam, (LPNMHDR)lParam); \
1930+ if(IsMsgHandled()) \
1931+ return TRUE; \
1932+ }
1933+
1934+// void OnReflectedParentNotify(UINT message, UINT nChildID, LPARAM lParam)
1935+#define MSG_OCM_PARENTNOTIFY(func) \
1936+ if (uMsg == OCM_PARENTNOTIFY) \
1937+ { \
1938+ SetMsgHandled(TRUE); \
1939+ func((UINT)LOWORD(wParam), (UINT)HIWORD(wParam), lParam); \
1940+ lResult = 0; \
1941+ if(IsMsgHandled()) \
1942+ return TRUE; \
1943+ }
1944+
1945+// void OnReflectedDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
1946+#define MSG_OCM_DRAWITEM(func) \
1947+ if (uMsg == OCM_DRAWITEM) \
1948+ { \
1949+ SetMsgHandled(TRUE); \
1950+ func((UINT)wParam, (LPDRAWITEMSTRUCT)lParam); \
1951+ lResult = TRUE; \
1952+ if(IsMsgHandled()) \
1953+ return TRUE; \
1954+ }
1955+
1956+// void OnReflectedMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
1957+#define MSG_OCM_MEASUREITEM(func) \
1958+ if (uMsg == OCM_MEASUREITEM) \
1959+ { \
1960+ SetMsgHandled(TRUE); \
1961+ func((UINT)wParam, (LPMEASUREITEMSTRUCT)lParam); \
1962+ lResult = TRUE; \
1963+ if(IsMsgHandled()) \
1964+ return TRUE; \
1965+ }
1966+
1967+// int OnReflectedCompareItem(int nIDCtl, LPCOMPAREITEMSTRUCT lpCompareItemStruct)
1968+#define MSG_OCM_COMPAREITEM(func) \
1969+ if (uMsg == OCM_COMPAREITEM) \
1970+ { \
1971+ SetMsgHandled(TRUE); \
1972+ lResult = (LRESULT)func((UINT)wParam, (LPCOMPAREITEMSTRUCT)lParam); \
1973+ if(IsMsgHandled()) \
1974+ return TRUE; \
1975+ }
1976+
1977+// void OnReflectedDeleteItem(int nIDCtl, LPDELETEITEMSTRUCT lpDeleteItemStruct)
1978+#define MSG_OCM_DELETEITEM(func) \
1979+ if (uMsg == OCM_DELETEITEM) \
1980+ { \
1981+ SetMsgHandled(TRUE); \
1982+ func((UINT)wParam, (LPDELETEITEMSTRUCT)lParam); \
1983+ lResult = TRUE; \
1984+ if(IsMsgHandled()) \
1985+ return TRUE; \
1986+ }
1987+
1988+// int OnReflectedVKeyToItem(UINT nKey, UINT nIndex, CListBox listBox)
1989+#define MSG_OCM_VKEYTOITEM(func) \
1990+ if (uMsg == OCM_VKEYTOITEM) \
1991+ { \
1992+ SetMsgHandled(TRUE); \
1993+ lResult = (LRESULT)func((UINT)LOWORD(wParam), (UINT)HIWORD(wParam), (HWND)lParam); \
1994+ if(IsMsgHandled()) \
1995+ return TRUE; \
1996+ }
1997+
1998+//int OnReflectedCharToItem(UINT nChar, UINT nIndex, CListBox listBox)
1999+#define MSG_OCM_CHARTOITEM(func) \
2000+ if (uMsg == OCM_CHARTOITEM) \
2001+ { \
2002+ SetMsgHandled(TRUE); \
2003+ lResult = (LRESULT)func((UINT)LOWORD(wParam), (UINT)HIWORD(wParam), (HWND)lParam); \
2004+ if(IsMsgHandled()) \
2005+ return TRUE; \
2006+ }
2007+
2008+// void OnReflectedHScroll(UINT nSBCode, UINT nPos, CScrollBar pScrollBar)
2009+#define MSG_OCM_HSCROLL(func) \
2010+ if (uMsg == OCM_HSCROLL) \
2011+ { \
2012+ SetMsgHandled(TRUE); \
2013+ func((int)LOWORD(wParam), (short)HIWORD(wParam), (HWND)lParam); \
2014+ lResult = 0; \
2015+ if(IsMsgHandled()) \
2016+ return TRUE; \
2017+ }
2018+
2019+// void OnReflectedVScroll(UINT nSBCode, UINT nPos, CScrollBar pScrollBar)
2020+#define MSG_OCM_VSCROLL(func) \
2021+ if (uMsg == OCM_VSCROLL) \
2022+ { \
2023+ SetMsgHandled(TRUE); \
2024+ func((int)LOWORD(wParam), (short)HIWORD(wParam), (HWND)lParam); \
2025+ lResult = 0; \
2026+ if(IsMsgHandled()) \
2027+ return TRUE; \
2028+ }
2029+
2030+// HBRUSH OnReflectedCtlColorEdit(CDCHandle dc, CEdit edit)
2031+#define MSG_OCM_CTLCOLOREDIT(func) \
2032+ if (uMsg == OCM_CTLCOLOREDIT) \
2033+ { \
2034+ SetMsgHandled(TRUE); \
2035+ lResult = (LRESULT)func((HDC)wParam, (HWND)lParam); \
2036+ if(IsMsgHandled()) \
2037+ return TRUE; \
2038+ }
2039+
2040+// HBRUSH OnReflectedCtlColorListBox(CDCHandle dc, CListBox listBox)
2041+#define MSG_OCM_CTLCOLORLISTBOX(func) \
2042+ if (uMsg == OCM_CTLCOLORLISTBOX) \
2043+ { \
2044+ SetMsgHandled(TRUE); \
2045+ lResult = (LRESULT)func((HDC)wParam, (HWND)lParam); \
2046+ if(IsMsgHandled()) \
2047+ return TRUE; \
2048+ }
2049+
2050+// HBRUSH OnReflectedCtlColorBtn(CDCHandle dc, CButton button)
2051+#define MSG_OCM_CTLCOLORBTN(func) \
2052+ if (uMsg == OCM_CTLCOLORBTN) \
2053+ { \
2054+ SetMsgHandled(TRUE); \
2055+ lResult = (LRESULT)func((HDC)wParam, (HWND)lParam); \
2056+ if(IsMsgHandled()) \
2057+ return TRUE; \
2058+ }
2059+
2060+// HBRUSH OnReflectedCtlColorDlg(CDCHandle dc, CWindow wnd)
2061+#define MSG_OCM_CTLCOLORDLG(func) \
2062+ if (uMsg == OCM_CTLCOLORDLG) \
2063+ { \
2064+ SetMsgHandled(TRUE); \
2065+ lResult = (LRESULT)func((HDC)wParam, (HWND)lParam); \
2066+ if(IsMsgHandled()) \
2067+ return TRUE; \
2068+ }
2069+
2070+// HBRUSH OnReflectedCtlColorScrollBar(CDCHandle dc, CScrollBar scrollBar)
2071+#define MSG_OCM_CTLCOLORSCROLLBAR(func) \
2072+ if (uMsg == OCM_CTLCOLORSCROLLBAR) \
2073+ { \
2074+ SetMsgHandled(TRUE); \
2075+ lResult = (LRESULT)func((HDC)wParam, (HWND)lParam); \
2076+ if(IsMsgHandled()) \
2077+ return TRUE; \
2078+ }
2079+
2080+// HBRUSH OnReflectedCtlColorStatic(CDCHandle dc, CStatic wndStatic)
2081+#define MSG_OCM_CTLCOLORSTATIC(func) \
2082+ if (uMsg == OCM_CTLCOLORSTATIC) \
2083+ { \
2084+ SetMsgHandled(TRUE); \
2085+ lResult = (LRESULT)func((HDC)wParam, (HWND)lParam); \
2086+ if(IsMsgHandled()) \
2087+ return TRUE; \
2088+ }
2089+
2090+///////////////////////////////////////////////////////////////////////////////
2091+// Edit specific messages
2092+
2093+// void OnClear()
2094+#define MSG_WM_CLEAR(func) \
2095+ if (uMsg == WM_CLEAR) \
2096+ { \
2097+ SetMsgHandled(TRUE); \
2098+ func(); \
2099+ lResult = 0; \
2100+ if(IsMsgHandled()) \
2101+ return TRUE; \
2102+ }
2103+
2104+// void OnCopy()
2105+#define MSG_WM_COPY(func) \
2106+ if (uMsg == WM_COPY) \
2107+ { \
2108+ SetMsgHandled(TRUE); \
2109+ func(); \
2110+ lResult = 0; \
2111+ if(IsMsgHandled()) \
2112+ return TRUE; \
2113+ }
2114+
2115+// void OnCut()
2116+#define MSG_WM_CUT(func) \
2117+ if (uMsg == WM_CUT) \
2118+ { \
2119+ SetMsgHandled(TRUE); \
2120+ func(); \
2121+ lResult = 0; \
2122+ if(IsMsgHandled()) \
2123+ return TRUE; \
2124+ }
2125+
2126+// void OnPaste()
2127+#define MSG_WM_PASTE(func) \
2128+ if (uMsg == WM_PASTE) \
2129+ { \
2130+ SetMsgHandled(TRUE); \
2131+ func(); \
2132+ lResult = 0; \
2133+ if(IsMsgHandled()) \
2134+ return TRUE; \
2135+ }
2136+
2137+// void OnUndo()
2138+#define MSG_WM_UNDO(func) \
2139+ if (uMsg == WM_UNDO) \
2140+ { \
2141+ SetMsgHandled(TRUE); \
2142+ func(); \
2143+ lResult = 0; \
2144+ if(IsMsgHandled()) \
2145+ return TRUE; \
2146+ }
2147+
2148+///////////////////////////////////////////////////////////////////////////////
2149+// Generic message handlers
2150+
2151+// LRESULT OnMessageHandlerEX(UINT uMsg, WPARAM wParam, LPARAM lParam)
2152+#define MESSAGE_HANDLER_EX(msg, func) \
2153+ if(uMsg == msg) \
2154+ { \
2155+ SetMsgHandled(TRUE); \
2156+ lResult = func(uMsg, wParam, lParam); \
2157+ if(IsMsgHandled()) \
2158+ return TRUE; \
2159+ }
2160+
2161+// LRESULT OnMessageRangeHandlerEX(UINT uMsg, WPARAM wParam, LPARAM lParam)
2162+#define MESSAGE_RANGE_HANDLER_EX(msgFirst, msgLast, func) \
2163+ if(uMsg >= msgFirst && uMsg <= msgLast) \
2164+ { \
2165+ SetMsgHandled(TRUE); \
2166+ lResult = func(uMsg, wParam, lParam); \
2167+ if(IsMsgHandled()) \
2168+ return TRUE; \
2169+ }
2170+
2171+///////////////////////////////////////////////////////////////////////////////
2172+// Commands and notifications
2173+
2174+// void OnCommandHandlerEX(UINT uNotifyCode, int nID, CWindow wndCtl)
2175+#define COMMAND_HANDLER_EX(id, code, func) \
2176+ if (uMsg == WM_COMMAND && code == HIWORD(wParam) && id == LOWORD(wParam)) \
2177+ { \
2178+ SetMsgHandled(TRUE); \
2179+ func((UINT)HIWORD(wParam), (int)LOWORD(wParam), (HWND)lParam); \
2180+ lResult = 0; \
2181+ if(IsMsgHandled()) \
2182+ return TRUE; \
2183+ }
2184+
2185+// void OnCommandIDHandlerEX(UINT uNotifyCode, int nID, CWindow wndCtl)
2186+#define COMMAND_ID_HANDLER_EX(id, func) \
2187+ if (uMsg == WM_COMMAND && id == LOWORD(wParam)) \
2188+ { \
2189+ SetMsgHandled(TRUE); \
2190+ func((UINT)HIWORD(wParam), (int)LOWORD(wParam), (HWND)lParam); \
2191+ lResult = 0; \
2192+ if(IsMsgHandled()) \
2193+ return TRUE; \
2194+ }
2195+
2196+// void OnCommandCodeHandlerEX(UINT uNotifyCode, int nID, CWindow wndCtl)
2197+#define COMMAND_CODE_HANDLER_EX(code, func) \
2198+ if (uMsg == WM_COMMAND && code == HIWORD(wParam)) \
2199+ { \
2200+ SetMsgHandled(TRUE); \
2201+ func((UINT)HIWORD(wParam), (int)LOWORD(wParam), (HWND)lParam); \
2202+ lResult = 0; \
2203+ if(IsMsgHandled()) \
2204+ return TRUE; \
2205+ }
2206+
2207+// LRESULT OnNotifyHandlerEX(LPNMHDR pnmh)
2208+#define NOTIFY_HANDLER_EX(id, cd, func) \
2209+ if (uMsg == WM_NOTIFY && cd == ((LPNMHDR)lParam)->code && id == ((LPNMHDR)lParam)->idFrom) \
2210+ { \
2211+ SetMsgHandled(TRUE); \
2212+ lResult = func((LPNMHDR)lParam); \
2213+ if(IsMsgHandled()) \
2214+ return TRUE; \
2215+ }
2216+
2217+// LRESULT OnNotifyIDHandlerEX(LPNMHDR pnmh)
2218+#define NOTIFY_ID_HANDLER_EX(id, func) \
2219+ if (uMsg == WM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom) \
2220+ { \
2221+ SetMsgHandled(TRUE); \
2222+ lResult = func((LPNMHDR)lParam); \
2223+ if(IsMsgHandled()) \
2224+ return TRUE; \
2225+ }
2226+
2227+// LRESULT OnNotifyCodeHandlerEX(LPNMHDR pnmh)
2228+#define NOTIFY_CODE_HANDLER_EX(cd, func) \
2229+ if (uMsg == WM_NOTIFY && cd == ((LPNMHDR)lParam)->code) \
2230+ { \
2231+ SetMsgHandled(TRUE); \
2232+ lResult = func((LPNMHDR)lParam); \
2233+ if(IsMsgHandled()) \
2234+ return TRUE; \
2235+ }
2236+
2237+// void OnCommandRangeHandlerEX(UINT uNotifyCode, int nID, CWindow wndCtl)
2238+#define COMMAND_RANGE_HANDLER_EX(idFirst, idLast, func) \
2239+ if(uMsg == WM_COMMAND && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
2240+ { \
2241+ SetMsgHandled(TRUE); \
2242+ func((UINT)HIWORD(wParam), (int)LOWORD(wParam), (HWND)lParam); \
2243+ lResult = 0; \
2244+ if(IsMsgHandled()) \
2245+ return TRUE; \
2246+ }
2247+
2248+// void OnCommandRangeCodeHandlerEX(UINT uNotifyCode, int nID, CWindow wndCtl)
2249+#define COMMAND_RANGE_CODE_HANDLER_EX(idFirst, idLast, code, func) \
2250+ if(uMsg == WM_COMMAND && code == HIWORD(wParam) && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
2251+ { \
2252+ SetMsgHandled(TRUE); \
2253+ func((UINT)HIWORD(wParam), (int)LOWORD(wParam), (HWND)lParam); \
2254+ lResult = 0; \
2255+ if(IsMsgHandled()) \
2256+ return TRUE; \
2257+ }
2258+
2259+// LRESULT OnNotifyRangeHandlerEX(LPNMHDR pnmh)
2260+#define NOTIFY_RANGE_HANDLER_EX(idFirst, idLast, func) \
2261+ if(uMsg == WM_NOTIFY && ((LPNMHDR)lParam)->idFrom >= idFirst && ((LPNMHDR)lParam)->idFrom <= idLast) \
2262+ { \
2263+ SetMsgHandled(TRUE); \
2264+ lResult = func((LPNMHDR)lParam); \
2265+ if(IsMsgHandled()) \
2266+ return TRUE; \
2267+ }
2268+
2269+// LRESULT OnNotifyRangeCodeHandlerEX(LPNMHDR pnmh)
2270+#define NOTIFY_RANGE_CODE_HANDLER_EX(idFirst, idLast, cd, func) \
2271+ if(uMsg == WM_NOTIFY && cd == ((LPNMHDR)lParam)->code && ((LPNMHDR)lParam)->idFrom >= idFirst && ((LPNMHDR)lParam)->idFrom <= idLast) \
2272+ { \
2273+ SetMsgHandled(TRUE); \
2274+ lResult = func((LPNMHDR)lParam); \
2275+ if(IsMsgHandled()) \
2276+ return TRUE; \
2277+ }
2278+
2279+// LRESULT OnReflectedCommandHandlerEX(UINT uNotifyCode, int nID, CWindow wndCtl)
2280+#define REFLECTED_COMMAND_HANDLER_EX(id, code, func) \
2281+ if (uMsg == OCM_COMMAND && code == HIWORD(wParam) && id == LOWORD(wParam)) \
2282+ { \
2283+ SetMsgHandled(TRUE); \
2284+ func((UINT)HIWORD(wParam), (int)LOWORD(wParam), (HWND)lParam); \
2285+ lResult = 0; \
2286+ if(IsMsgHandled()) \
2287+ return TRUE; \
2288+ }
2289+
2290+// LRESULT OnReflectedCommandIDHandlerEX(UINT uNotifyCode, int nID, CWindow wndCtl)
2291+#define REFLECTED_COMMAND_ID_HANDLER_EX(id, func) \
2292+ if (uMsg == OCM_COMMAND && id == LOWORD(wParam)) \
2293+ { \
2294+ SetMsgHandled(TRUE); \
2295+ func((UINT)HIWORD(wParam), (int)LOWORD(wParam), (HWND)lParam); \
2296+ lResult = 0; \
2297+ if(IsMsgHandled()) \
2298+ return TRUE; \
2299+ }
2300+
2301+// LRESULT OnReflectedCommandCodeHandlerEX(UINT uNotifyCode, int nID, CWindow wndCtl)
2302+#define REFLECTED_COMMAND_CODE_HANDLER_EX(code, func) \
2303+ if (uMsg == OCM_COMMAND && code == HIWORD(wParam)) \
2304+ { \
2305+ SetMsgHandled(TRUE); \
2306+ func((UINT)HIWORD(wParam), (int)LOWORD(wParam), (HWND)lParam); \
2307+ lResult = 0; \
2308+ if(IsMsgHandled()) \
2309+ return TRUE; \
2310+ }
2311+
2312+// LRESULT OnReflectedNotifyHandlerEX(LPNMHDR pnmh)
2313+#define REFLECTED_NOTIFY_HANDLER_EX(id, cd, func) \
2314+ if (uMsg == OCM_NOTIFY && cd == ((LPNMHDR)lParam)->code && id == ((LPNMHDR)lParam)->idFrom) \
2315+ { \
2316+ SetMsgHandled(TRUE); \
2317+ lResult = func((LPNMHDR)lParam); \
2318+ if(IsMsgHandled()) \
2319+ return TRUE; \
2320+ }
2321+
2322+// LRESULT OnReflectedNotifyIDHandlerEX(LPNMHDR pnmh)
2323+#define REFLECTED_NOTIFY_ID_HANDLER_EX(id, func) \
2324+ if (uMsg == OCM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom) \
2325+ { \
2326+ SetMsgHandled(TRUE); \
2327+ lResult = func((LPNMHDR)lParam); \
2328+ if(IsMsgHandled()) \
2329+ return TRUE; \
2330+ }
2331+
2332+// LRESULT OnReflectedNotifyCodeHandlerEX(LPNMHDR pnmh)
2333+#define REFLECTED_NOTIFY_CODE_HANDLER_EX(cd, func) \
2334+ if (uMsg == OCM_NOTIFY && cd == ((LPNMHDR)lParam)->code) \
2335+ { \
2336+ SetMsgHandled(TRUE); \
2337+ lResult = func((LPNMHDR)lParam); \
2338+ if(IsMsgHandled()) \
2339+ return TRUE; \
2340+ }
2341+
2342+// void OnReflectedCommandRangeHandlerEX(UINT uNotifyCode, int nID, CWindow wndCtl)
2343+#define REFLECTED_COMMAND_RANGE_HANDLER_EX(idFirst, idLast, func) \
2344+ if(uMsg == OCM_COMMAND && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
2345+ { \
2346+ SetMsgHandled(TRUE); \
2347+ func((UINT)HIWORD(wParam), (int)LOWORD(wParam), (HWND)lParam); \
2348+ lResult = 0; \
2349+ if(IsMsgHandled()) \
2350+ return TRUE; \
2351+ }
2352+
2353+// void OnReflectedCommandRangeCodeHandlerEX(UINT uNotifyCode, int nID, CWindow wndCtl)
2354+#define REFLECTED_COMMAND_RANGE_CODE_HANDLER_EX(idFirst, idLast, code, func) \
2355+ if(uMsg == OCM_COMMAND && code == HIWORD(wParam) && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
2356+ { \
2357+ SetMsgHandled(TRUE); \
2358+ func((UINT)HIWORD(wParam), (int)LOWORD(wParam), (HWND)lParam); \
2359+ lResult = 0; \
2360+ if(IsMsgHandled()) \
2361+ return TRUE; \
2362+ }
2363+
2364+// LRESULT OnReflectedNotifyRangeHandlerEX(LPNMHDR pnmh)
2365+#define REFLECTED_NOTIFY_RANGE_HANDLER_EX(idFirst, idLast, func) \
2366+ if(uMsg == OCM_NOTIFY && ((LPNMHDR)lParam)->idFrom >= idFirst && ((LPNMHDR)lParam)->idFrom <= idLast) \
2367+ { \
2368+ SetMsgHandled(TRUE); \
2369+ lResult = func((LPNMHDR)lParam); \
2370+ if(IsMsgHandled()) \
2371+ return TRUE; \
2372+ }
2373+
2374+// LRESULT OnReflectedNotifyRangeCodeHandlerEX(LPNMHDR pnmh)
2375+#define REFLECTED_NOTIFY_RANGE_CODE_HANDLER_EX(idFirst, idLast, cd, func) \
2376+ if(uMsg == OCM_NOTIFY && cd == ((LPNMHDR)lParam)->code && ((LPNMHDR)lParam)->idFrom >= idFirst && ((LPNMHDR)lParam)->idFrom <= idLast) \
2377+ { \
2378+ SetMsgHandled(TRUE); \
2379+ lResult = func((LPNMHDR)lParam); \
2380+ if(IsMsgHandled()) \
2381+ return TRUE; \
2382+ }
2383+
2384+#endif // __ATLCRACK_H__
--- /dev/null
+++ b/include/WTL/Include/atlctrls.h
@@ -0,0 +1,10035 @@
1+// Windows Template Library - WTL version 8.1
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+// 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.
11+
12+#ifndef __ATLCTRLS_H__
13+#define __ATLCTRLS_H__
14+
15+#pragma once
16+
17+#ifndef __ATLAPP_H__
18+ #error atlctrls.h requires atlapp.h to be included first
19+#endif
20+
21+#ifndef __ATLWIN_H__
22+ #error atlctrls.h requires atlwin.h to be included first
23+#endif
24+
25+#ifndef _WIN32_WCE
26+ #include <richedit.h>
27+ #include <richole.h>
28+#elif defined(WIN32_PLATFORM_WFSP) && !defined(_WINUSERM_H_)
29+ #include <winuserm.h>
30+#endif // !_WIN32_WCE
31+
32+// protect template members from windowsx.h macros
33+#ifdef _INC_WINDOWSX
34+ #undef GetNextSibling
35+ #undef GetPrevSibling
36+#endif // _INC_WINDOWSX
37+
38+
39+///////////////////////////////////////////////////////////////////////////////
40+// Classes in this file:
41+//
42+// CStaticT<TBase> - CStatic
43+// CButtonT<TBase> - CButton
44+// CListBoxT<TBase> - CListBox
45+// CComboBoxT<TBase> - CComboBox
46+// CEditT<TBase> - CEdit
47+// CEditCommands<T>
48+// CScrollBarT<TBase> - CScrollBar
49+//
50+// CImageList
51+// CListViewCtrlT<TBase> - CListViewCtrl
52+// CTreeViewCtrlT<TBase> - CTreeViewCtrl
53+// CTreeItemT<TBase> - CTreeItem
54+// CTreeViewCtrlExT<TBase> - CTreeViewCtrlEx
55+// CHeaderCtrlT<TBase> - CHeaderCtrl
56+// CToolBarCtrlT<TBase> - CToolBarCtrl
57+// CStatusBarCtrlT<TBase> - CStatusBarCtrl
58+// CTabCtrlT<TBase> - CTabCtrl
59+// CToolInfo
60+// CToolTipCtrlT<TBase> - CToolTipCtrl
61+// CTrackBarCtrlT<TBase> - CTrackBarCtrl
62+// CUpDownCtrlT<TBase> - CUpDownCtrl
63+// CProgressBarCtrlT<TBase> - CProgressBarCtrl
64+// CHotKeyCtrlT<TBase> - CHotKeyCtrl
65+// CAnimateCtrlT<TBase> - CAnimateCtrl
66+// CRichEditCtrlT<TBase> - CRichEditCtrl
67+// CRichEditCommands<T>
68+// CDragListBoxT<TBase> - CDragListBox
69+// CDragListNotifyImpl<T>
70+// CReBarCtrlT<TBase> - CReBarCtrl
71+// CComboBoxExT<TBase> - CComboBoxEx
72+// CDateTimePickerCtrlT<TBase> - CDateTimePickerCtrl
73+// CMonthCalendarCtrlT<TBase> - CMonthCalendarCtrl
74+// CFlatScrollBarImpl<T>
75+// CFlatScrollBarT<TBase> - CFlatScrollBar
76+// CIPAddressCtrlT<TBase> - CIPAddressCtrl
77+// CPagerCtrlT<TBase> - CPagerCtrl
78+// CLinkCtrlT<TBase> - CLinkCtrl
79+//
80+// CCustomDraw<T>
81+//
82+// CCECommandBarCtrlT<TBase> - CCECommandBarCtrl
83+// CCECommandBandsCtrlT<TBase> - CCECommandBandsCtrl
84+
85+
86+namespace WTL
87+{
88+
89+// These are wrapper classes for Windows standard and common controls.
90+// To implement a window based on a control, use following:
91+// Example: Implementing a window based on a list box
92+//
93+// class CMyListBox : CWindowImpl<CMyListBox, CListBox>
94+// {
95+// public:
96+// BEGIN_MSG_MAP(CMyListBox)
97+// // put your message handler entries here
98+// END_MSG_MAP()
99+// };
100+
101+
102+
103+// --- Standard Windows controls ---
104+
105+///////////////////////////////////////////////////////////////////////////////
106+// CStatic - client side for a Windows STATIC control
107+
108+template <class TBase>
109+class CStaticT : public TBase
110+{
111+public:
112+// Constructors
113+ CStaticT(HWND hWnd = NULL) : TBase(hWnd)
114+ { }
115+
116+ CStaticT< TBase >& operator =(HWND hWnd)
117+ {
118+ m_hWnd = hWnd;
119+ return *this;
120+ }
121+
122+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
123+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
124+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
125+ {
126+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
127+ }
128+
129+// Attributes
130+ static LPCTSTR GetWndClassName()
131+ {
132+ return _T("STATIC");
133+ }
134+
135+#ifndef _WIN32_WCE
136+ HICON GetIcon() const
137+ {
138+ ATLASSERT(::IsWindow(m_hWnd));
139+ return (HICON)::SendMessage(m_hWnd, STM_GETICON, 0, 0L);
140+ }
141+
142+ HICON SetIcon(HICON hIcon)
143+ {
144+ ATLASSERT(::IsWindow(m_hWnd));
145+ return (HICON)::SendMessage(m_hWnd, STM_SETICON, (WPARAM)hIcon, 0L);
146+ }
147+
148+ HENHMETAFILE GetEnhMetaFile() const
149+ {
150+ ATLASSERT(::IsWindow(m_hWnd));
151+ return (HENHMETAFILE)::SendMessage(m_hWnd, STM_GETIMAGE, IMAGE_ENHMETAFILE, 0L);
152+ }
153+
154+ HENHMETAFILE SetEnhMetaFile(HENHMETAFILE hMetaFile)
155+ {
156+ ATLASSERT(::IsWindow(m_hWnd));
157+ return (HENHMETAFILE)::SendMessage(m_hWnd, STM_SETIMAGE, IMAGE_ENHMETAFILE, (LPARAM)hMetaFile);
158+ }
159+#else // CE specific
160+ HICON GetIcon() const
161+ {
162+ ATLASSERT(::IsWindow(m_hWnd));
163+ return (HICON)::SendMessage(m_hWnd, STM_GETIMAGE, IMAGE_ICON, 0L);
164+ }
165+
166+ HICON SetIcon(HICON hIcon)
167+ {
168+ ATLASSERT(::IsWindow(m_hWnd));
169+ return (HICON)::SendMessage(m_hWnd, STM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
170+ }
171+#endif // _WIN32_WCE
172+
173+ CBitmapHandle GetBitmap() const
174+ {
175+ ATLASSERT(::IsWindow(m_hWnd));
176+ return CBitmapHandle((HBITMAP)::SendMessage(m_hWnd, STM_GETIMAGE, IMAGE_BITMAP, 0L));
177+ }
178+
179+ CBitmapHandle SetBitmap(HBITMAP hBitmap)
180+ {
181+ ATLASSERT(::IsWindow(m_hWnd));
182+ return CBitmapHandle((HBITMAP)::SendMessage(m_hWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap));
183+ }
184+
185+ HCURSOR GetCursor() const
186+ {
187+ ATLASSERT(::IsWindow(m_hWnd));
188+ return (HCURSOR)::SendMessage(m_hWnd, STM_GETIMAGE, IMAGE_CURSOR, 0L);
189+ }
190+
191+ HCURSOR SetCursor(HCURSOR hCursor)
192+ {
193+ ATLASSERT(::IsWindow(m_hWnd));
194+ return (HCURSOR)::SendMessage(m_hWnd, STM_SETIMAGE, IMAGE_CURSOR, (LPARAM)hCursor);
195+ }
196+};
197+
198+typedef CStaticT<ATL::CWindow> CStatic;
199+
200+
201+///////////////////////////////////////////////////////////////////////////////
202+// CButton - client side for a Windows BUTTON control
203+
204+template <class TBase>
205+class CButtonT : public TBase
206+{
207+public:
208+// Constructors
209+ CButtonT(HWND hWnd = NULL) : TBase(hWnd)
210+ { }
211+
212+ CButtonT< TBase >& operator =(HWND hWnd)
213+ {
214+ m_hWnd = hWnd;
215+ return *this;
216+ }
217+
218+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
219+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
220+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
221+ {
222+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
223+ }
224+
225+// Attributes
226+ static LPCTSTR GetWndClassName()
227+ {
228+ return _T("BUTTON");
229+ }
230+
231+ UINT GetState() const
232+ {
233+ ATLASSERT(::IsWindow(m_hWnd));
234+ return (UINT)::SendMessage(m_hWnd, BM_GETSTATE, 0, 0L);
235+ }
236+
237+ void SetState(BOOL bHighlight)
238+ {
239+ ATLASSERT(::IsWindow(m_hWnd));
240+ ::SendMessage(m_hWnd, BM_SETSTATE, bHighlight, 0L);
241+ }
242+
243+ int GetCheck() const
244+ {
245+ ATLASSERT(::IsWindow(m_hWnd));
246+ return (int)::SendMessage(m_hWnd, BM_GETCHECK, 0, 0L);
247+ }
248+
249+ void SetCheck(int nCheck)
250+ {
251+ ATLASSERT(::IsWindow(m_hWnd));
252+ ::SendMessage(m_hWnd, BM_SETCHECK, nCheck, 0L);
253+ }
254+
255+ UINT GetButtonStyle() const
256+ {
257+ ATLASSERT(::IsWindow(m_hWnd));
258+ return (UINT)::GetWindowLong(m_hWnd, GWL_STYLE) & 0xFFFF;
259+ }
260+
261+ void SetButtonStyle(UINT nStyle, BOOL bRedraw = TRUE)
262+ {
263+ ATLASSERT(::IsWindow(m_hWnd));
264+ ::SendMessage(m_hWnd, BM_SETSTYLE, nStyle, (LPARAM)bRedraw);
265+ }
266+
267+#ifndef _WIN32_WCE
268+ HICON GetIcon() const
269+ {
270+ ATLASSERT(::IsWindow(m_hWnd));
271+ return (HICON)::SendMessage(m_hWnd, BM_GETIMAGE, IMAGE_ICON, 0L);
272+ }
273+
274+ HICON SetIcon(HICON hIcon)
275+ {
276+ ATLASSERT(::IsWindow(m_hWnd));
277+ return (HICON)::SendMessage(m_hWnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
278+ }
279+
280+ CBitmapHandle GetBitmap() const
281+ {
282+ ATLASSERT(::IsWindow(m_hWnd));
283+ return CBitmapHandle((HBITMAP)::SendMessage(m_hWnd, BM_GETIMAGE, IMAGE_BITMAP, 0L));
284+ }
285+
286+ CBitmapHandle SetBitmap(HBITMAP hBitmap)
287+ {
288+ ATLASSERT(::IsWindow(m_hWnd));
289+ return CBitmapHandle((HBITMAP)::SendMessage(m_hWnd, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap));
290+ }
291+#endif // !_WIN32_WCE
292+
293+#if (_WIN32_WINNT >= 0x0501)
294+ BOOL GetIdealSize(LPSIZE lpSize) const
295+ {
296+ ATLASSERT(::IsWindow(m_hWnd));
297+ return (BOOL)::SendMessage(m_hWnd, BCM_GETIDEALSIZE, 0, (LPARAM)lpSize);
298+ }
299+
300+ BOOL GetImageList(PBUTTON_IMAGELIST pButtonImagelist) const
301+ {
302+ ATLASSERT(::IsWindow(m_hWnd));
303+ return (BOOL)::SendMessage(m_hWnd, BCM_GETIMAGELIST, 0, (LPARAM)pButtonImagelist);
304+ }
305+
306+ BOOL SetImageList(PBUTTON_IMAGELIST pButtonImagelist)
307+ {
308+ ATLASSERT(::IsWindow(m_hWnd));
309+ return (BOOL)::SendMessage(m_hWnd, BCM_SETIMAGELIST, 0, (LPARAM)pButtonImagelist);
310+ }
311+
312+ BOOL GetTextMargin(LPRECT lpRect) const
313+ {
314+ ATLASSERT(::IsWindow(m_hWnd));
315+ return (BOOL)::SendMessage(m_hWnd, BCM_GETTEXTMARGIN, 0, (LPARAM)lpRect);
316+ }
317+
318+ BOOL SetTextMargin(LPRECT lpRect)
319+ {
320+ ATLASSERT(::IsWindow(m_hWnd));
321+ return (BOOL)::SendMessage(m_hWnd, BCM_SETTEXTMARGIN, 0, (LPARAM)lpRect);
322+ }
323+#endif // (_WIN32_WINNT >= 0x0501)
324+
325+#if (WINVER >= 0x0600)
326+ void SetDontClick(BOOL bDontClick)
327+ {
328+ ATLASSERT(::IsWindow(m_hWnd));
329+ ::SendMessage(m_hWnd, BM_SETDONTCLICK, (WPARAM)bDontClick, 0L);
330+ }
331+#endif // (WINVER >= 0x0600)
332+
333+#if (_WIN32_WINNT >= 0x0600)
334+ BOOL SetDropDownState(BOOL bDropDown)
335+ {
336+ ATLASSERT(::IsWindow(m_hWnd));
337+ ATLASSERT((GetStyle() & (BS_SPLITBUTTON | BS_DEFSPLITBUTTON)) != 0);
338+ return (BOOL)::SendMessage(m_hWnd, BCM_SETDROPDOWNSTATE, (WPARAM)bDropDown, 0L);
339+ }
340+
341+ BOOL GetSplitInfo(PBUTTON_SPLITINFO pSplitInfo) const
342+ {
343+ ATLASSERT(::IsWindow(m_hWnd));
344+ ATLASSERT((GetStyle() & (BS_SPLITBUTTON | BS_DEFSPLITBUTTON)) != 0);
345+ return (BOOL)::SendMessage(m_hWnd, BCM_GETSPLITINFO, 0, (LPARAM)pSplitInfo);
346+ }
347+
348+ BOOL SetSplitInfo(PBUTTON_SPLITINFO pSplitInfo)
349+ {
350+ ATLASSERT(::IsWindow(m_hWnd));
351+ ATLASSERT((GetStyle() & (BS_SPLITBUTTON | BS_DEFSPLITBUTTON)) != 0);
352+ return (BOOL)::SendMessage(m_hWnd, BCM_SETSPLITINFO, 0, (LPARAM)pSplitInfo);
353+ }
354+
355+ int GetNoteLength() const
356+ {
357+ ATLASSERT(::IsWindow(m_hWnd));
358+ ATLASSERT((GetStyle() & (BS_COMMANDLINK | BS_DEFCOMMANDLINK)) != 0);
359+ return (int)::SendMessage(m_hWnd, BCM_GETNOTELENGTH, 0, 0L);
360+ }
361+
362+ BOOL GetNote(LPWSTR lpstrNoteText, int cchNoteText) const
363+ {
364+ ATLASSERT(::IsWindow(m_hWnd));
365+ ATLASSERT((GetStyle() & (BS_COMMANDLINK | BS_DEFCOMMANDLINK)) != 0);
366+ return (BOOL)::SendMessage(m_hWnd, BCM_GETNOTE, cchNoteText, (LPARAM)lpstrNoteText);
367+ }
368+
369+ BOOL SetNote(LPCWSTR lpstrNoteText)
370+ {
371+ ATLASSERT(::IsWindow(m_hWnd));
372+ ATLASSERT((GetStyle() & (BS_COMMANDLINK | BS_DEFCOMMANDLINK)) != 0);
373+ return (BOOL)::SendMessage(m_hWnd, BCM_SETNOTE, 0, (LPARAM)lpstrNoteText);
374+ }
375+
376+ LRESULT SetElevationRequiredState(BOOL bSet)
377+ {
378+ ATLASSERT(::IsWindow(m_hWnd));
379+ return ::SendMessage(m_hWnd, BCM_SETSHIELD, 0, (LPARAM)bSet);
380+ }
381+#endif // (_WIN32_WINNT >= 0x0600)
382+
383+// Operations
384+ void Click()
385+ {
386+ ATLASSERT(::IsWindow(m_hWnd));
387+ ::SendMessage(m_hWnd, BM_CLICK, 0, 0L);
388+ }
389+};
390+
391+typedef CButtonT<ATL::CWindow> CButton;
392+
393+
394+///////////////////////////////////////////////////////////////////////////////
395+// CListBox - client side for a Windows LISTBOX control
396+
397+template <class TBase>
398+class CListBoxT : public TBase
399+{
400+public:
401+// Constructors
402+ CListBoxT(HWND hWnd = NULL) : TBase(hWnd)
403+ { }
404+
405+ CListBoxT< TBase >& operator =(HWND hWnd)
406+ {
407+ m_hWnd = hWnd;
408+ return *this;
409+ }
410+
411+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
412+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
413+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
414+ {
415+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
416+ }
417+
418+// Attributes
419+ static LPCTSTR GetWndClassName()
420+ {
421+ return _T("LISTBOX");
422+ }
423+
424+ // for entire listbox
425+ int GetCount() const
426+ {
427+ ATLASSERT(::IsWindow(m_hWnd));
428+ return (int)::SendMessage(m_hWnd, LB_GETCOUNT, 0, 0L);
429+ }
430+
431+#ifndef _WIN32_WCE
432+ int SetCount(int cItems)
433+ {
434+ ATLASSERT(::IsWindow(m_hWnd));
435+ ATLASSERT(((GetStyle() & LBS_NODATA) != 0) && ((GetStyle() & LBS_HASSTRINGS) == 0));
436+ return (int)::SendMessage(m_hWnd, LB_SETCOUNT, cItems, 0L);
437+ }
438+#endif // !_WIN32_WCE
439+
440+ int GetHorizontalExtent() const
441+ {
442+ ATLASSERT(::IsWindow(m_hWnd));
443+ return (int)::SendMessage(m_hWnd, LB_GETHORIZONTALEXTENT, 0, 0L);
444+ }
445+
446+ void SetHorizontalExtent(int cxExtent)
447+ {
448+ ATLASSERT(::IsWindow(m_hWnd));
449+ ::SendMessage(m_hWnd, LB_SETHORIZONTALEXTENT, cxExtent, 0L);
450+ }
451+
452+ int GetTopIndex() const
453+ {
454+ ATLASSERT(::IsWindow(m_hWnd));
455+ return (int)::SendMessage(m_hWnd, LB_GETTOPINDEX, 0, 0L);
456+ }
457+
458+ int SetTopIndex(int nIndex)
459+ {
460+ ATLASSERT(::IsWindow(m_hWnd));
461+ return (int)::SendMessage(m_hWnd, LB_SETTOPINDEX, nIndex, 0L);
462+ }
463+
464+ LCID GetLocale() const
465+ {
466+ ATLASSERT(::IsWindow(m_hWnd));
467+ return (LCID)::SendMessage(m_hWnd, LB_GETLOCALE, 0, 0L);
468+ }
469+
470+ LCID SetLocale(LCID nNewLocale)
471+ {
472+ ATLASSERT(::IsWindow(m_hWnd));
473+ return (LCID)::SendMessage(m_hWnd, LB_SETLOCALE, (WPARAM)nNewLocale, 0L);
474+ }
475+
476+#if (WINVER >= 0x0500) && !defined(_WIN32_WCE)
477+ DWORD GetListBoxInfo() const
478+ {
479+ ATLASSERT(::IsWindow(m_hWnd));
480+#if (_WIN32_WINNT >= 0x0501)
481+ return (DWORD)::SendMessage(m_hWnd, LB_GETLISTBOXINFO, 0, 0L);
482+#else // !(_WIN32_WINNT >= 0x0501)
483+ return ::GetListBoxInfo(m_hWnd);
484+#endif // !(_WIN32_WINNT >= 0x0501)
485+ }
486+#endif // (WINVER >= 0x0500) && !defined(_WIN32_WCE)
487+
488+ // for single-selection listboxes
489+ int GetCurSel() const
490+ {
491+ ATLASSERT(::IsWindow(m_hWnd));
492+ ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) == 0);
493+ return (int)::SendMessage(m_hWnd, LB_GETCURSEL, 0, 0L);
494+ }
495+
496+ int SetCurSel(int nSelect)
497+ {
498+ ATLASSERT(::IsWindow(m_hWnd));
499+ ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) == 0);
500+ return (int)::SendMessage(m_hWnd, LB_SETCURSEL, nSelect, 0L);
501+ }
502+
503+ // for multiple-selection listboxes
504+ int GetSel(int nIndex) const // also works for single-selection
505+ {
506+ ATLASSERT(::IsWindow(m_hWnd));
507+ return (int)::SendMessage(m_hWnd, LB_GETSEL, nIndex, 0L);
508+ }
509+
510+ int SetSel(int nIndex, BOOL bSelect = TRUE)
511+ {
512+ ATLASSERT(::IsWindow(m_hWnd));
513+ ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
514+ return (int)::SendMessage(m_hWnd, LB_SETSEL, bSelect, nIndex);
515+ }
516+
517+ int GetSelCount() const
518+ {
519+ ATLASSERT(::IsWindow(m_hWnd));
520+ ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
521+ return (int)::SendMessage(m_hWnd, LB_GETSELCOUNT, 0, 0L);
522+ }
523+
524+ int GetSelItems(int nMaxItems, LPINT rgIndex) const
525+ {
526+ ATLASSERT(::IsWindow(m_hWnd));
527+ ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
528+ return (int)::SendMessage(m_hWnd, LB_GETSELITEMS, nMaxItems, (LPARAM)rgIndex);
529+ }
530+
531+ int GetAnchorIndex() const
532+ {
533+ ATLASSERT(::IsWindow(m_hWnd));
534+ ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
535+ return (int)::SendMessage(m_hWnd, LB_GETANCHORINDEX, 0, 0L);
536+ }
537+
538+ void SetAnchorIndex(int nIndex)
539+ {
540+ ATLASSERT(::IsWindow(m_hWnd));
541+ ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
542+ ::SendMessage(m_hWnd, LB_SETANCHORINDEX, nIndex, 0L);
543+ }
544+
545+ int GetCaretIndex() const
546+ {
547+ ATLASSERT(::IsWindow(m_hWnd));
548+ return (int)::SendMessage(m_hWnd, LB_GETCARETINDEX, 0, 0);
549+ }
550+
551+ int SetCaretIndex(int nIndex, BOOL bScroll = TRUE)
552+ {
553+ ATLASSERT(::IsWindow(m_hWnd));
554+ return (int)::SendMessage(m_hWnd, LB_SETCARETINDEX, nIndex, MAKELONG(bScroll, 0));
555+ }
556+
557+ // for listbox items
558+ DWORD_PTR GetItemData(int nIndex) const
559+ {
560+ ATLASSERT(::IsWindow(m_hWnd));
561+ return (DWORD_PTR)::SendMessage(m_hWnd, LB_GETITEMDATA, nIndex, 0L);
562+ }
563+
564+ int SetItemData(int nIndex, DWORD_PTR dwItemData)
565+ {
566+ ATLASSERT(::IsWindow(m_hWnd));
567+ return (int)::SendMessage(m_hWnd, LB_SETITEMDATA, nIndex, (LPARAM)dwItemData);
568+ }
569+
570+ void* GetItemDataPtr(int nIndex) const
571+ {
572+ ATLASSERT(::IsWindow(m_hWnd));
573+ return (void*)::SendMessage(m_hWnd, LB_GETITEMDATA, nIndex, 0L);
574+ }
575+
576+ int SetItemDataPtr(int nIndex, void* pData)
577+ {
578+ ATLASSERT(::IsWindow(m_hWnd));
579+ return SetItemData(nIndex, (DWORD_PTR)pData);
580+ }
581+
582+ int GetItemRect(int nIndex, LPRECT lpRect) const
583+ {
584+ ATLASSERT(::IsWindow(m_hWnd));
585+ return (int)::SendMessage(m_hWnd, LB_GETITEMRECT, nIndex, (LPARAM)lpRect);
586+ }
587+
588+ int GetText(int nIndex, LPTSTR lpszBuffer) const
589+ {
590+ ATLASSERT(::IsWindow(m_hWnd));
591+ return (int)::SendMessage(m_hWnd, LB_GETTEXT, nIndex, (LPARAM)lpszBuffer);
592+ }
593+
594+#ifndef _ATL_NO_COM
595+#ifdef _OLEAUTO_H_
596+ BOOL GetTextBSTR(int nIndex, BSTR& bstrText) const
597+ {
598+ USES_CONVERSION;
599+ ATLASSERT(::IsWindow(m_hWnd));
600+ ATLASSERT(bstrText == NULL);
601+
602+ int nLen = GetTextLen(nIndex);
603+ if(nLen == LB_ERR)
604+ return FALSE;
605+
606+ CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
607+ LPTSTR lpstrText = buff.Allocate(nLen + 1);
608+ if(lpstrText == NULL)
609+ return FALSE;
610+
611+ if(GetText(nIndex, lpstrText) == LB_ERR)
612+ return FALSE;
613+
614+ bstrText = ::SysAllocString(T2OLE(lpstrText));
615+ return (bstrText != NULL) ? TRUE : FALSE;
616+ }
617+#endif // _OLEAUTO_H_
618+#endif // !_ATL_NO_COM
619+
620+#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
621+ int GetText(int nIndex, _CSTRING_NS::CString& strText) const
622+ {
623+ ATLASSERT(::IsWindow(m_hWnd));
624+ int cchLen = GetTextLen(nIndex);
625+ if(cchLen == LB_ERR)
626+ return LB_ERR;
627+ int nRet = LB_ERR;
628+ LPTSTR lpstr = strText.GetBufferSetLength(cchLen);
629+ if(lpstr != NULL)
630+ {
631+ nRet = GetText(nIndex, lpstr);
632+ strText.ReleaseBuffer();
633+ }
634+ return nRet;
635+ }
636+#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
637+
638+ int GetTextLen(int nIndex) const
639+ {
640+ ATLASSERT(::IsWindow(m_hWnd));
641+ return (int)::SendMessage(m_hWnd, LB_GETTEXTLEN, nIndex, 0L);
642+ }
643+
644+ int GetItemHeight(int nIndex) const
645+ {
646+ ATLASSERT(::IsWindow(m_hWnd));
647+ return (int)::SendMessage(m_hWnd, LB_GETITEMHEIGHT, nIndex, 0L);
648+ }
649+
650+ int SetItemHeight(int nIndex, UINT cyItemHeight)
651+ {
652+ ATLASSERT(::IsWindow(m_hWnd));
653+ return (int)::SendMessage(m_hWnd, LB_SETITEMHEIGHT, nIndex, MAKELONG(cyItemHeight, 0));
654+ }
655+
656+ // Settable only attributes
657+ void SetColumnWidth(int cxWidth)
658+ {
659+ ATLASSERT(::IsWindow(m_hWnd));
660+ ::SendMessage(m_hWnd, LB_SETCOLUMNWIDTH, cxWidth, 0L);
661+ }
662+
663+ BOOL SetTabStops(int nTabStops, LPINT rgTabStops)
664+ {
665+ ATLASSERT(::IsWindow(m_hWnd));
666+ ATLASSERT((GetStyle() & LBS_USETABSTOPS) != 0);
667+ return (BOOL)::SendMessage(m_hWnd, LB_SETTABSTOPS, nTabStops, (LPARAM)rgTabStops);
668+ }
669+
670+ BOOL SetTabStops()
671+ {
672+ ATLASSERT(::IsWindow(m_hWnd));
673+ ATLASSERT((GetStyle() & LBS_USETABSTOPS) != 0);
674+ return (BOOL)::SendMessage(m_hWnd, LB_SETTABSTOPS, 0, 0L);
675+ }
676+
677+ BOOL SetTabStops(const int& cxEachStop) // takes an 'int'
678+ {
679+ ATLASSERT(::IsWindow(m_hWnd));
680+ ATLASSERT((GetStyle() & LBS_USETABSTOPS) != 0);
681+ return (BOOL)::SendMessage(m_hWnd, LB_SETTABSTOPS, 1, (LPARAM)(LPINT)&cxEachStop);
682+ }
683+
684+// Operations
685+ int InitStorage(int nItems, UINT nBytes)
686+ {
687+ ATLASSERT(::IsWindow(m_hWnd));
688+ return (int)::SendMessage(m_hWnd, LB_INITSTORAGE, (WPARAM)nItems, nBytes);
689+ }
690+
691+ void ResetContent()
692+ {
693+ ATLASSERT(::IsWindow(m_hWnd));
694+ ::SendMessage(m_hWnd, LB_RESETCONTENT, 0, 0L);
695+ }
696+
697+ UINT ItemFromPoint(POINT pt, BOOL& bOutside) const
698+ {
699+ ATLASSERT(::IsWindow(m_hWnd));
700+ DWORD dw = (DWORD)::SendMessage(m_hWnd, LB_ITEMFROMPOINT, 0, MAKELPARAM(pt.x, pt.y));
701+ bOutside = (BOOL)HIWORD(dw);
702+ return (UINT)LOWORD(dw);
703+ }
704+
705+ // manipulating listbox items
706+ int AddString(LPCTSTR lpszItem)
707+ {
708+ ATLASSERT(::IsWindow(m_hWnd));
709+ return (int)::SendMessage(m_hWnd, LB_ADDSTRING, 0, (LPARAM)lpszItem);
710+ }
711+
712+ int DeleteString(UINT nIndex)
713+ {
714+ ATLASSERT(::IsWindow(m_hWnd));
715+ return (int)::SendMessage(m_hWnd, LB_DELETESTRING, nIndex, 0L);
716+ }
717+
718+ int InsertString(int nIndex, LPCTSTR lpszItem)
719+ {
720+ ATLASSERT(::IsWindow(m_hWnd));
721+ return (int)::SendMessage(m_hWnd, LB_INSERTSTRING, nIndex, (LPARAM)lpszItem);
722+ }
723+
724+#ifndef _WIN32_WCE
725+ int Dir(UINT attr, LPCTSTR lpszWildCard)
726+ {
727+ ATLASSERT(::IsWindow(m_hWnd));
728+ return (int)::SendMessage(m_hWnd, LB_DIR, attr, (LPARAM)lpszWildCard);
729+ }
730+
731+ int AddFile(LPCTSTR lpstrFileName)
732+ {
733+ ATLASSERT(::IsWindow(m_hWnd));
734+ return (int)::SendMessage(m_hWnd, LB_ADDFILE, 0, (LPARAM)lpstrFileName);
735+ }
736+#endif // !_WIN32_WCE
737+
738+ // selection helpers
739+ int FindString(int nStartAfter, LPCTSTR lpszItem) const
740+ {
741+ ATLASSERT(::IsWindow(m_hWnd));
742+ return (int)::SendMessage(m_hWnd, LB_FINDSTRING, nStartAfter, (LPARAM)lpszItem);
743+ }
744+
745+ int FindStringExact(int nIndexStart, LPCTSTR lpszFind) const
746+ {
747+ ATLASSERT(::IsWindow(m_hWnd));
748+ return (int)::SendMessage(m_hWnd, LB_FINDSTRINGEXACT, nIndexStart, (LPARAM)lpszFind);
749+ }
750+
751+ int SelectString(int nStartAfter, LPCTSTR lpszItem)
752+ {
753+ ATLASSERT(::IsWindow(m_hWnd));
754+ return (int)::SendMessage(m_hWnd, LB_SELECTSTRING, nStartAfter, (LPARAM)lpszItem);
755+ }
756+
757+ int SelItemRange(BOOL bSelect, int nFirstItem, int nLastItem)
758+ {
759+ ATLASSERT(::IsWindow(m_hWnd));
760+ ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
761+ ATLASSERT(nFirstItem <= nLastItem);
762+ return bSelect ? (int)::SendMessage(m_hWnd, LB_SELITEMRANGEEX, nFirstItem, nLastItem) : (int)::SendMessage(m_hWnd, LB_SELITEMRANGEEX, nLastItem, nFirstItem);
763+ }
764+
765+#ifdef WIN32_PLATFORM_WFSP // SmartPhone only messages
766+ DWORD GetInputMode(BOOL bCurrentMode = TRUE)
767+ {
768+ return SendMessage(LB_GETINPUTMODE, 0, (LPARAM)bCurrentMode);
769+ }
770+
771+ BOOL SetInputMode(DWORD dwMode)
772+ {
773+ return SendMessage(LB_SETINPUTMODE, 0, (LPARAM)dwMode);
774+ }
775+#endif // WIN32_PLATFORM_WFSP
776+};
777+
778+typedef CListBoxT<ATL::CWindow> CListBox;
779+
780+
781+///////////////////////////////////////////////////////////////////////////////
782+// CComboBox - client side for a Windows COMBOBOX control
783+
784+#ifndef WIN32_PLATFORM_WFSP // No COMBOBOX on SmartPhones
785+
786+template <class TBase>
787+class CComboBoxT : public TBase
788+{
789+public:
790+// Constructors
791+ CComboBoxT(HWND hWnd = NULL) : TBase(hWnd)
792+ { }
793+
794+ CComboBoxT< TBase >& operator =(HWND hWnd)
795+ {
796+ m_hWnd = hWnd;
797+ return *this;
798+ }
799+
800+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
801+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
802+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
803+ {
804+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
805+ }
806+
807+// Attributes
808+ static LPCTSTR GetWndClassName()
809+ {
810+ return _T("COMBOBOX");
811+ }
812+
813+ // for entire combo box
814+ int GetCount() const
815+ {
816+ ATLASSERT(::IsWindow(m_hWnd));
817+ return (int)::SendMessage(m_hWnd, CB_GETCOUNT, 0, 0L);
818+ }
819+
820+ int GetCurSel() const
821+ {
822+ ATLASSERT(::IsWindow(m_hWnd));
823+ return (int)::SendMessage(m_hWnd, CB_GETCURSEL, 0, 0L);
824+ }
825+
826+ int SetCurSel(int nSelect)
827+ {
828+ ATLASSERT(::IsWindow(m_hWnd));
829+ return (int)::SendMessage(m_hWnd, CB_SETCURSEL, nSelect, 0L);
830+ }
831+
832+ LCID GetLocale() const
833+ {
834+ ATLASSERT(::IsWindow(m_hWnd));
835+ return (LCID)::SendMessage(m_hWnd, CB_GETLOCALE, 0, 0L);
836+ }
837+
838+ LCID SetLocale(LCID nNewLocale)
839+ {
840+ ATLASSERT(::IsWindow(m_hWnd));
841+ return (LCID)::SendMessage(m_hWnd, CB_SETLOCALE, (WPARAM)nNewLocale, 0L);
842+ }
843+
844+ int GetTopIndex() const
845+ {
846+ ATLASSERT(::IsWindow(m_hWnd));
847+ return (int)::SendMessage(m_hWnd, CB_GETTOPINDEX, 0, 0L);
848+ }
849+
850+ int SetTopIndex(int nIndex)
851+ {
852+ ATLASSERT(::IsWindow(m_hWnd));
853+ return (int)::SendMessage(m_hWnd, CB_SETTOPINDEX, nIndex, 0L);
854+ }
855+
856+ UINT GetHorizontalExtent() const
857+ {
858+ ATLASSERT(::IsWindow(m_hWnd));
859+ return (UINT)::SendMessage(m_hWnd, CB_GETHORIZONTALEXTENT, 0, 0L);
860+ }
861+
862+ void SetHorizontalExtent(UINT nExtent)
863+ {
864+ ATLASSERT(::IsWindow(m_hWnd));
865+ ::SendMessage(m_hWnd, CB_SETHORIZONTALEXTENT, nExtent, 0L);
866+ }
867+
868+ int GetDroppedWidth() const
869+ {
870+ ATLASSERT(::IsWindow(m_hWnd));
871+ return (int)::SendMessage(m_hWnd, CB_GETDROPPEDWIDTH, 0, 0L);
872+ }
873+
874+ int SetDroppedWidth(UINT nWidth)
875+ {
876+ ATLASSERT(::IsWindow(m_hWnd));
877+ return (int)::SendMessage(m_hWnd, CB_SETDROPPEDWIDTH, nWidth, 0L);
878+ }
879+
880+#if ((WINVER >= 0x0500) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
881+ BOOL GetComboBoxInfo(PCOMBOBOXINFO pComboBoxInfo) const
882+ {
883+ ATLASSERT(::IsWindow(m_hWnd));
884+#if ((_WIN32_WINNT >= 0x0501) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
885+ return (BOOL)::SendMessage(m_hWnd, CB_GETCOMBOBOXINFO, 0, (LPARAM)pComboBoxInfo);
886+#else // !((_WIN32_WINNT >= 0x0501) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
887+ return ::GetComboBoxInfo(m_hWnd, pComboBoxInfo);
888+#endif // !((_WIN32_WINNT >= 0x0501) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
889+ }
890+#endif // ((WINVER >= 0x0500) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
891+
892+ // for edit control
893+ DWORD GetEditSel() const
894+ {
895+ ATLASSERT(::IsWindow(m_hWnd));
896+ return (DWORD)::SendMessage(m_hWnd, CB_GETEDITSEL, 0, 0L);
897+ }
898+
899+ BOOL SetEditSel(int nStartChar, int nEndChar)
900+ {
901+ ATLASSERT(::IsWindow(m_hWnd));
902+ return (BOOL)::SendMessage(m_hWnd, CB_SETEDITSEL, 0, MAKELONG(nStartChar, nEndChar));
903+ }
904+
905+ // for combobox item
906+ DWORD_PTR GetItemData(int nIndex) const
907+ {
908+ ATLASSERT(::IsWindow(m_hWnd));
909+ return (DWORD_PTR)::SendMessage(m_hWnd, CB_GETITEMDATA, nIndex, 0L);
910+ }
911+
912+ int SetItemData(int nIndex, DWORD_PTR dwItemData)
913+ {
914+ ATLASSERT(::IsWindow(m_hWnd));
915+ return (int)::SendMessage(m_hWnd, CB_SETITEMDATA, nIndex, (LPARAM)dwItemData);
916+ }
917+
918+ void* GetItemDataPtr(int nIndex) const
919+ {
920+ ATLASSERT(::IsWindow(m_hWnd));
921+ return (void*)GetItemData(nIndex);
922+ }
923+
924+ int SetItemDataPtr(int nIndex, void* pData)
925+ {
926+ ATLASSERT(::IsWindow(m_hWnd));
927+ return SetItemData(nIndex, (DWORD_PTR)pData);
928+ }
929+
930+ int GetLBText(int nIndex, LPTSTR lpszText) const
931+ {
932+ ATLASSERT(::IsWindow(m_hWnd));
933+ return (int)::SendMessage(m_hWnd, CB_GETLBTEXT, nIndex, (LPARAM)lpszText);
934+ }
935+
936+#ifndef _ATL_NO_COM
937+ BOOL GetLBTextBSTR(int nIndex, BSTR& bstrText) const
938+ {
939+ USES_CONVERSION;
940+ ATLASSERT(::IsWindow(m_hWnd));
941+ ATLASSERT(bstrText == NULL);
942+
943+ int nLen = GetLBTextLen(nIndex);
944+ if(nLen == CB_ERR)
945+ return FALSE;
946+
947+ CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
948+ LPTSTR lpstrText = buff.Allocate(nLen + 1);
949+ if(lpstrText == NULL)
950+ return FALSE;
951+
952+ if(GetLBText(nIndex, lpstrText) == CB_ERR)
953+ return FALSE;
954+
955+ bstrText = ::SysAllocString(T2OLE(lpstrText));
956+ return (bstrText != NULL) ? TRUE : FALSE;
957+ }
958+#endif // !_ATL_NO_COM
959+
960+#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
961+ int GetLBText(int nIndex, _CSTRING_NS::CString& strText) const
962+ {
963+ ATLASSERT(::IsWindow(m_hWnd));
964+ int cchLen = GetLBTextLen(nIndex);
965+ if(cchLen == CB_ERR)
966+ return CB_ERR;
967+ int nRet = CB_ERR;
968+ LPTSTR lpstr = strText.GetBufferSetLength(cchLen);
969+ if(lpstr != NULL)
970+ {
971+ nRet = GetLBText(nIndex, lpstr);
972+ strText.ReleaseBuffer();
973+ }
974+ return nRet;
975+ }
976+#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
977+
978+ int GetLBTextLen(int nIndex) const
979+ {
980+ ATLASSERT(::IsWindow(m_hWnd));
981+ return (int)::SendMessage(m_hWnd, CB_GETLBTEXTLEN, nIndex, 0L);
982+ }
983+
984+ int GetItemHeight(int nIndex) const
985+ {
986+ ATLASSERT(::IsWindow(m_hWnd));
987+ return (int)::SendMessage(m_hWnd, CB_GETITEMHEIGHT, nIndex, 0L);
988+ }
989+
990+ int SetItemHeight(int nIndex, UINT cyItemHeight)
991+ {
992+ ATLASSERT(::IsWindow(m_hWnd));
993+ return (int)::SendMessage(m_hWnd, CB_SETITEMHEIGHT, nIndex, MAKELONG(cyItemHeight, 0));
994+ }
995+
996+ BOOL GetExtendedUI() const
997+ {
998+ ATLASSERT(::IsWindow(m_hWnd));
999+ return (BOOL)::SendMessage(m_hWnd, CB_GETEXTENDEDUI, 0, 0L);
1000+ }
1001+
1002+ int SetExtendedUI(BOOL bExtended = TRUE)
1003+ {
1004+ ATLASSERT(::IsWindow(m_hWnd));
1005+ return (int)::SendMessage(m_hWnd, CB_SETEXTENDEDUI, bExtended, 0L);
1006+ }
1007+
1008+ void GetDroppedControlRect(LPRECT lprect) const
1009+ {
1010+ ATLASSERT(::IsWindow(m_hWnd));
1011+ ::SendMessage(m_hWnd, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)lprect);
1012+ }
1013+
1014+ BOOL GetDroppedState() const
1015+ {
1016+ ATLASSERT(::IsWindow(m_hWnd));
1017+ return (BOOL)::SendMessage(m_hWnd, CB_GETDROPPEDSTATE, 0, 0L);
1018+ }
1019+
1020+#if (_WIN32_WINNT >= 0x0501)
1021+ int GetMinVisible() const
1022+ {
1023+ ATLASSERT(::IsWindow(m_hWnd));
1024+ return (int)::SendMessage(m_hWnd, CB_GETMINVISIBLE, 0, 0L);
1025+ }
1026+
1027+ BOOL SetMinVisible(int nMinVisible)
1028+ {
1029+ ATLASSERT(::IsWindow(m_hWnd));
1030+ return (BOOL)::SendMessage(m_hWnd, CB_SETMINVISIBLE, nMinVisible, 0L);
1031+ }
1032+
1033+ // Vista only
1034+ BOOL GetCueBannerText(LPWSTR lpwText, int cchText) const
1035+ {
1036+#ifndef CB_GETCUEBANNER
1037+ const UINT CB_GETCUEBANNER = (CBM_FIRST + 4);
1038+#endif
1039+ ATLASSERT(::IsWindow(m_hWnd));
1040+ return (BOOL)::SendMessage(m_hWnd, CB_GETCUEBANNER, (WPARAM)lpwText, cchText);
1041+ }
1042+
1043+ // Vista only
1044+ BOOL SetCueBannerText(LPCWSTR lpcwText)
1045+ {
1046+#ifndef CB_SETCUEBANNER
1047+ const UINT CB_SETCUEBANNER = (CBM_FIRST + 3);
1048+#endif
1049+ ATLASSERT(::IsWindow(m_hWnd));
1050+ return (BOOL)::SendMessage(m_hWnd, CB_SETCUEBANNER, 0, (LPARAM)lpcwText);
1051+ }
1052+#endif // (_WIN32_WINNT >= 0x0501)
1053+
1054+// Operations
1055+ int InitStorage(int nItems, UINT nBytes)
1056+ {
1057+ ATLASSERT(::IsWindow(m_hWnd));
1058+ return (int)::SendMessage(m_hWnd, CB_INITSTORAGE, (WPARAM)nItems, nBytes);
1059+ }
1060+
1061+ void ResetContent()
1062+ {
1063+ ATLASSERT(::IsWindow(m_hWnd));
1064+ ::SendMessage(m_hWnd, CB_RESETCONTENT, 0, 0L);
1065+ }
1066+
1067+ // for edit control
1068+ BOOL LimitText(int nMaxChars)
1069+ {
1070+ ATLASSERT(::IsWindow(m_hWnd));
1071+ return (BOOL)::SendMessage(m_hWnd, CB_LIMITTEXT, nMaxChars, 0L);
1072+ }
1073+
1074+ // for drop-down combo boxes
1075+ void ShowDropDown(BOOL bShowIt = TRUE)
1076+ {
1077+ ATLASSERT(::IsWindow(m_hWnd));
1078+ ::SendMessage(m_hWnd, CB_SHOWDROPDOWN, bShowIt, 0L);
1079+ }
1080+
1081+ // manipulating listbox items
1082+ int AddString(LPCTSTR lpszString)
1083+ {
1084+ ATLASSERT(::IsWindow(m_hWnd));
1085+ return (int)::SendMessage(m_hWnd, CB_ADDSTRING, 0, (LPARAM)lpszString);
1086+ }
1087+
1088+ int DeleteString(UINT nIndex)
1089+ {
1090+ ATLASSERT(::IsWindow(m_hWnd));
1091+ return (int)::SendMessage(m_hWnd, CB_DELETESTRING, nIndex, 0L);
1092+ }
1093+
1094+ int InsertString(int nIndex, LPCTSTR lpszString)
1095+ {
1096+ ATLASSERT(::IsWindow(m_hWnd));
1097+ return (int)::SendMessage(m_hWnd, CB_INSERTSTRING, nIndex, (LPARAM)lpszString);
1098+ }
1099+
1100+#ifndef _WIN32_WCE
1101+ int Dir(UINT attr, LPCTSTR lpszWildCard)
1102+ {
1103+ ATLASSERT(::IsWindow(m_hWnd));
1104+ return (int)::SendMessage(m_hWnd, CB_DIR, attr, (LPARAM)lpszWildCard);
1105+ }
1106+#endif // !_WIN32_WCE
1107+
1108+ // selection helpers
1109+ int FindString(int nStartAfter, LPCTSTR lpszString) const
1110+ {
1111+ ATLASSERT(::IsWindow(m_hWnd));
1112+ return (int)::SendMessage(m_hWnd, CB_FINDSTRING, nStartAfter, (LPARAM)lpszString);
1113+ }
1114+
1115+ int FindStringExact(int nIndexStart, LPCTSTR lpszFind) const
1116+ {
1117+ ATLASSERT(::IsWindow(m_hWnd));
1118+ return (int)::SendMessage(m_hWnd, CB_FINDSTRINGEXACT, nIndexStart, (LPARAM)lpszFind);
1119+ }
1120+
1121+ int SelectString(int nStartAfter, LPCTSTR lpszString)
1122+ {
1123+ ATLASSERT(::IsWindow(m_hWnd));
1124+ return (int)::SendMessage(m_hWnd, CB_SELECTSTRING, nStartAfter, (LPARAM)lpszString);
1125+ }
1126+
1127+ // Clipboard operations
1128+ void Clear()
1129+ {
1130+ ATLASSERT(::IsWindow(m_hWnd));
1131+ ::SendMessage(m_hWnd, WM_CLEAR, 0, 0L);
1132+ }
1133+
1134+ void Copy()
1135+ {
1136+ ATLASSERT(::IsWindow(m_hWnd));
1137+ ::SendMessage(m_hWnd, WM_COPY, 0, 0L);
1138+ }
1139+
1140+ void Cut()
1141+ {
1142+ ATLASSERT(::IsWindow(m_hWnd));
1143+ ::SendMessage(m_hWnd, WM_CUT, 0, 0L);
1144+ }
1145+
1146+ void Paste()
1147+ {
1148+ ATLASSERT(::IsWindow(m_hWnd));
1149+ ::SendMessage(m_hWnd, WM_PASTE, 0, 0L);
1150+ }
1151+};
1152+
1153+typedef CComboBoxT<ATL::CWindow> CComboBox;
1154+
1155+#endif // !WIN32_PLATFORM_WFSP
1156+
1157+///////////////////////////////////////////////////////////////////////////////
1158+// CEdit - client side for a Windows EDIT control
1159+
1160+template <class TBase>
1161+class CEditT : public TBase
1162+{
1163+public:
1164+// Constructors
1165+ CEditT(HWND hWnd = NULL) : TBase(hWnd)
1166+ { }
1167+
1168+ CEditT< TBase >& operator =(HWND hWnd)
1169+ {
1170+ m_hWnd = hWnd;
1171+ return *this;
1172+ }
1173+
1174+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
1175+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
1176+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
1177+ {
1178+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
1179+ }
1180+
1181+// Attributes
1182+ static LPCTSTR GetWndClassName()
1183+ {
1184+ return _T("EDIT");
1185+ }
1186+
1187+ BOOL CanUndo() const
1188+ {
1189+ ATLASSERT(::IsWindow(m_hWnd));
1190+ return (BOOL)::SendMessage(m_hWnd, EM_CANUNDO, 0, 0L);
1191+ }
1192+
1193+ int GetLineCount() const
1194+ {
1195+ ATLASSERT(::IsWindow(m_hWnd));
1196+ return (int)::SendMessage(m_hWnd, EM_GETLINECOUNT, 0, 0L);
1197+ }
1198+
1199+ BOOL GetModify() const
1200+ {
1201+ ATLASSERT(::IsWindow(m_hWnd));
1202+ return (BOOL)::SendMessage(m_hWnd, EM_GETMODIFY, 0, 0L);
1203+ }
1204+
1205+ void SetModify(BOOL bModified = TRUE)
1206+ {
1207+ ATLASSERT(::IsWindow(m_hWnd));
1208+ ::SendMessage(m_hWnd, EM_SETMODIFY, bModified, 0L);
1209+ }
1210+
1211+ void GetRect(LPRECT lpRect) const
1212+ {
1213+ ATLASSERT(::IsWindow(m_hWnd));
1214+ ::SendMessage(m_hWnd, EM_GETRECT, 0, (LPARAM)lpRect);
1215+ }
1216+
1217+ DWORD GetSel() const
1218+ {
1219+ ATLASSERT(::IsWindow(m_hWnd));
1220+ return (DWORD)::SendMessage(m_hWnd, EM_GETSEL, 0, 0L);
1221+ }
1222+
1223+ void GetSel(int& nStartChar, int& nEndChar) const
1224+ {
1225+ ATLASSERT(::IsWindow(m_hWnd));
1226+ ::SendMessage(m_hWnd, EM_GETSEL, (WPARAM)&nStartChar, (LPARAM)&nEndChar);
1227+ }
1228+
1229+#ifndef _WIN32_WCE
1230+ HLOCAL GetHandle() const
1231+ {
1232+ ATLASSERT(::IsWindow(m_hWnd));
1233+ return (HLOCAL)::SendMessage(m_hWnd, EM_GETHANDLE, 0, 0L);
1234+ }
1235+
1236+ void SetHandle(HLOCAL hBuffer)
1237+ {
1238+ ATLASSERT(::IsWindow(m_hWnd));
1239+ ::SendMessage(m_hWnd, EM_SETHANDLE, (WPARAM)hBuffer, 0L);
1240+ }
1241+#endif // !_WIN32_WCE
1242+
1243+ DWORD GetMargins() const
1244+ {
1245+ ATLASSERT(::IsWindow(m_hWnd));
1246+ return (DWORD)::SendMessage(m_hWnd, EM_GETMARGINS, 0, 0L);
1247+ }
1248+
1249+ void SetMargins(UINT nLeft, UINT nRight)
1250+ {
1251+ ATLASSERT(::IsWindow(m_hWnd));
1252+ ::SendMessage(m_hWnd, EM_SETMARGINS, EC_LEFTMARGIN|EC_RIGHTMARGIN, MAKELONG(nLeft, nRight));
1253+ }
1254+
1255+ UINT GetLimitText() const
1256+ {
1257+ ATLASSERT(::IsWindow(m_hWnd));
1258+ return (UINT)::SendMessage(m_hWnd, EM_GETLIMITTEXT, 0, 0L);
1259+ }
1260+
1261+ void SetLimitText(UINT nMax)
1262+ {
1263+ ATLASSERT(::IsWindow(m_hWnd));
1264+ ::SendMessage(m_hWnd, EM_SETLIMITTEXT, nMax, 0L);
1265+ }
1266+
1267+ POINT PosFromChar(UINT nChar) const
1268+ {
1269+ ATLASSERT(::IsWindow(m_hWnd));
1270+ DWORD dwRet = (DWORD)::SendMessage(m_hWnd, EM_POSFROMCHAR, nChar, 0);
1271+ POINT point = { GET_X_LPARAM(dwRet), GET_Y_LPARAM(dwRet) };
1272+ return point;
1273+ }
1274+
1275+ int CharFromPos(POINT pt, int* pLine = NULL) const
1276+ {
1277+ ATLASSERT(::IsWindow(m_hWnd));
1278+ DWORD dwRet = (DWORD)::SendMessage(m_hWnd, EM_CHARFROMPOS, 0, MAKELPARAM(pt.x, pt.y));
1279+ if(pLine != NULL)
1280+ *pLine = (int)(short)HIWORD(dwRet);
1281+ return (int)(short)LOWORD(dwRet);
1282+ }
1283+
1284+ // NOTE: first word in lpszBuffer must contain the size of the buffer!
1285+ int GetLine(int nIndex, LPTSTR lpszBuffer) const
1286+ {
1287+ ATLASSERT(::IsWindow(m_hWnd));
1288+ return (int)::SendMessage(m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer);
1289+ }
1290+
1291+ int GetLine(int nIndex, LPTSTR lpszBuffer, int nMaxLength) const
1292+ {
1293+ ATLASSERT(::IsWindow(m_hWnd));
1294+ *(LPWORD)lpszBuffer = (WORD)nMaxLength;
1295+ return (int)::SendMessage(m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer);
1296+ }
1297+
1298+ TCHAR GetPasswordChar() const
1299+ {
1300+ ATLASSERT(::IsWindow(m_hWnd));
1301+ return (TCHAR)::SendMessage(m_hWnd, EM_GETPASSWORDCHAR, 0, 0L);
1302+ }
1303+
1304+ void SetPasswordChar(TCHAR ch)
1305+ {
1306+ ATLASSERT(::IsWindow(m_hWnd));
1307+ ::SendMessage(m_hWnd, EM_SETPASSWORDCHAR, ch, 0L);
1308+ }
1309+
1310+#ifndef _WIN32_WCE
1311+ EDITWORDBREAKPROC GetWordBreakProc() const
1312+ {
1313+ ATLASSERT(::IsWindow(m_hWnd));
1314+ return (EDITWORDBREAKPROC)::SendMessage(m_hWnd, EM_GETWORDBREAKPROC, 0, 0L);
1315+ }
1316+
1317+ void SetWordBreakProc(EDITWORDBREAKPROC ewbprc)
1318+ {
1319+ ATLASSERT(::IsWindow(m_hWnd));
1320+ ::SendMessage(m_hWnd, EM_SETWORDBREAKPROC, 0, (LPARAM)ewbprc);
1321+ }
1322+#endif // !_WIN32_WCE
1323+
1324+ int GetFirstVisibleLine() const
1325+ {
1326+ ATLASSERT(::IsWindow(m_hWnd));
1327+ return (int)::SendMessage(m_hWnd, EM_GETFIRSTVISIBLELINE, 0, 0L);
1328+ }
1329+
1330+#ifndef _WIN32_WCE
1331+ int GetThumb() const
1332+ {
1333+ ATLASSERT(::IsWindow(m_hWnd));
1334+ ATLASSERT((GetStyle() & ES_MULTILINE) != 0);
1335+ return (int)::SendMessage(m_hWnd, EM_GETTHUMB, 0, 0L);
1336+ }
1337+#endif // !_WIN32_WCE
1338+
1339+ BOOL SetReadOnly(BOOL bReadOnly = TRUE)
1340+ {
1341+ ATLASSERT(::IsWindow(m_hWnd));
1342+ return (BOOL)::SendMessage(m_hWnd, EM_SETREADONLY, bReadOnly, 0L);
1343+ }
1344+
1345+#if (WINVER >= 0x0500) && !defined(_WIN32_WCE)
1346+ UINT GetImeStatus(UINT uStatus) const
1347+ {
1348+ ATLASSERT(::IsWindow(m_hWnd));
1349+ return (UINT)::SendMessage(m_hWnd, EM_GETIMESTATUS, uStatus, 0L);
1350+ }
1351+
1352+ UINT SetImeStatus(UINT uStatus, UINT uData)
1353+ {
1354+ ATLASSERT(::IsWindow(m_hWnd));
1355+ return (UINT)::SendMessage(m_hWnd, EM_SETIMESTATUS, uStatus, uData);
1356+ }
1357+#endif // (WINVER >= 0x0500) && !defined(_WIN32_WCE)
1358+
1359+#if (_WIN32_WINNT >= 0x0501)
1360+ BOOL GetCueBannerText(LPCWSTR lpstrText, int cchText) const
1361+ {
1362+ ATLASSERT(::IsWindow(m_hWnd));
1363+ return (BOOL)::SendMessage(m_hWnd, EM_GETCUEBANNER, (WPARAM)lpstrText, cchText);
1364+ }
1365+
1366+ // bKeepWithFocus - Vista only
1367+ BOOL SetCueBannerText(LPCWSTR lpstrText, BOOL bKeepWithFocus = FALSE)
1368+ {
1369+ ATLASSERT(::IsWindow(m_hWnd));
1370+ return (BOOL)::SendMessage(m_hWnd, EM_SETCUEBANNER, (WPARAM)bKeepWithFocus, (LPARAM)(lpstrText));
1371+ }
1372+#endif // (_WIN32_WINNT >= 0x0501)
1373+
1374+// Operations
1375+ void EmptyUndoBuffer()
1376+ {
1377+ ATLASSERT(::IsWindow(m_hWnd));
1378+ ::SendMessage(m_hWnd, EM_EMPTYUNDOBUFFER, 0, 0L);
1379+ }
1380+
1381+ BOOL FmtLines(BOOL bAddEOL)
1382+ {
1383+ ATLASSERT(::IsWindow(m_hWnd));
1384+ return (BOOL)::SendMessage(m_hWnd, EM_FMTLINES, bAddEOL, 0L);
1385+ }
1386+
1387+ void LimitText(int nChars = 0)
1388+ {
1389+ ATLASSERT(::IsWindow(m_hWnd));
1390+ ::SendMessage(m_hWnd, EM_LIMITTEXT, nChars, 0L);
1391+ }
1392+
1393+ int LineFromChar(int nIndex = -1) const
1394+ {
1395+ ATLASSERT(::IsWindow(m_hWnd));
1396+ return (int)::SendMessage(m_hWnd, EM_LINEFROMCHAR, nIndex, 0L);
1397+ }
1398+
1399+ int LineIndex(int nLine = -1) const
1400+ {
1401+ ATLASSERT(::IsWindow(m_hWnd));
1402+ return (int)::SendMessage(m_hWnd, EM_LINEINDEX, nLine, 0L);
1403+ }
1404+
1405+ int LineLength(int nLine = -1) const
1406+ {
1407+ ATLASSERT(::IsWindow(m_hWnd));
1408+ return (int)::SendMessage(m_hWnd, EM_LINELENGTH, nLine, 0L);
1409+ }
1410+
1411+ void LineScroll(int nLines, int nChars = 0)
1412+ {
1413+ ATLASSERT(::IsWindow(m_hWnd));
1414+ ::SendMessage(m_hWnd, EM_LINESCROLL, nChars, nLines);
1415+ }
1416+
1417+ void ReplaceSel(LPCTSTR lpszNewText, BOOL bCanUndo = FALSE)
1418+ {
1419+ ATLASSERT(::IsWindow(m_hWnd));
1420+ ::SendMessage(m_hWnd, EM_REPLACESEL, (WPARAM) bCanUndo, (LPARAM)lpszNewText);
1421+ }
1422+
1423+ void SetRect(LPCRECT lpRect)
1424+ {
1425+ ATLASSERT(::IsWindow(m_hWnd));
1426+ ::SendMessage(m_hWnd, EM_SETRECT, 0, (LPARAM)lpRect);
1427+ }
1428+
1429+ void SetRectNP(LPCRECT lpRect)
1430+ {
1431+ ATLASSERT(::IsWindow(m_hWnd));
1432+ ::SendMessage(m_hWnd, EM_SETRECTNP, 0, (LPARAM)lpRect);
1433+ }
1434+
1435+ void SetSel(DWORD dwSelection, BOOL bNoScroll = FALSE)
1436+ {
1437+ ATLASSERT(::IsWindow(m_hWnd));
1438+ ::SendMessage(m_hWnd, EM_SETSEL, LOWORD(dwSelection), HIWORD(dwSelection));
1439+ if(!bNoScroll)
1440+ ::SendMessage(m_hWnd, EM_SCROLLCARET, 0, 0L);
1441+ }
1442+
1443+ void SetSel(int nStartChar, int nEndChar, BOOL bNoScroll = FALSE)
1444+ {
1445+ ATLASSERT(::IsWindow(m_hWnd));
1446+ ::SendMessage(m_hWnd, EM_SETSEL, nStartChar, nEndChar);
1447+ if(!bNoScroll)
1448+ ::SendMessage(m_hWnd, EM_SCROLLCARET, 0, 0L);
1449+ }
1450+
1451+ void SetSelAll(BOOL bNoScroll = FALSE)
1452+ {
1453+ SetSel(0, -1, bNoScroll);
1454+ }
1455+
1456+ void SetSelNone(BOOL bNoScroll = FALSE)
1457+ {
1458+ SetSel(-1, 0, bNoScroll);
1459+ }
1460+
1461+ BOOL SetTabStops(int nTabStops, LPINT rgTabStops)
1462+ {
1463+ ATLASSERT(::IsWindow(m_hWnd));
1464+ return (BOOL)::SendMessage(m_hWnd, EM_SETTABSTOPS, nTabStops, (LPARAM)rgTabStops);
1465+ }
1466+
1467+ BOOL SetTabStops()
1468+ {
1469+ ATLASSERT(::IsWindow(m_hWnd));
1470+ return (BOOL)::SendMessage(m_hWnd, EM_SETTABSTOPS, 0, 0L);
1471+ }
1472+
1473+ BOOL SetTabStops(const int& cxEachStop) // takes an 'int'
1474+ {
1475+ ATLASSERT(::IsWindow(m_hWnd));
1476+ return (BOOL)::SendMessage(m_hWnd, EM_SETTABSTOPS, 1, (LPARAM)(LPINT)&cxEachStop);
1477+ }
1478+
1479+ void ScrollCaret()
1480+ {
1481+ ATLASSERT(::IsWindow(m_hWnd));
1482+ ::SendMessage(m_hWnd, EM_SCROLLCARET, 0, 0L);
1483+ }
1484+
1485+ int Scroll(int nScrollAction)
1486+ {
1487+ ATLASSERT(::IsWindow(m_hWnd));
1488+ ATLASSERT((GetStyle() & ES_MULTILINE) != 0);
1489+ LRESULT lRet = ::SendMessage(m_hWnd, EM_SCROLL, nScrollAction, 0L);
1490+ if(!(BOOL)HIWORD(lRet))
1491+ return -1; // failed
1492+ return (int)(short)LOWORD(lRet);
1493+
1494+ }
1495+
1496+ void InsertText(int nInsertAfterChar, LPCTSTR lpstrText, BOOL bNoScroll = FALSE, BOOL bCanUndo = FALSE)
1497+ {
1498+ SetSel(nInsertAfterChar, nInsertAfterChar, bNoScroll);
1499+ ReplaceSel(lpstrText, bCanUndo);
1500+ }
1501+
1502+ void AppendText(LPCTSTR lpstrText, BOOL bNoScroll = FALSE, BOOL bCanUndo = FALSE)
1503+ {
1504+ InsertText(GetWindowTextLength(), lpstrText, bNoScroll, bCanUndo);
1505+ }
1506+
1507+#if (_WIN32_WINNT >= 0x0501)
1508+ BOOL ShowBalloonTip(PEDITBALLOONTIP pEditBaloonTip)
1509+ {
1510+ ATLASSERT(::IsWindow(m_hWnd));
1511+ return (BOOL)::SendMessage(m_hWnd, EM_SHOWBALLOONTIP, 0, (LPARAM)pEditBaloonTip);
1512+ }
1513+
1514+ BOOL HideBalloonTip()
1515+ {
1516+ ATLASSERT(::IsWindow(m_hWnd));
1517+ return (BOOL)::SendMessage(m_hWnd, EM_HIDEBALLOONTIP, 0, 0L);
1518+ }
1519+#endif // (_WIN32_WINNT >= 0x0501)
1520+
1521+#if (_WIN32_WINNT >= 0x0600)
1522+ DWORD GetHilite() const
1523+ {
1524+ ATLASSERT(::IsWindow(m_hWnd));
1525+ return (DWORD)::SendMessage(m_hWnd, EM_GETHILITE, 0, 0L);
1526+ }
1527+
1528+ void GetHilite(int& nStartChar, int& nEndChar) const
1529+ {
1530+ ATLASSERT(::IsWindow(m_hWnd));
1531+ DWORD dwRet = (DWORD)::SendMessage(m_hWnd, EM_GETHILITE, 0, 0L);
1532+ nStartChar = (int)(short)LOWORD(dwRet);
1533+ nEndChar = (int)(short)HIWORD(dwRet);
1534+ }
1535+
1536+ void SetHilite(int nStartChar, int nEndChar)
1537+ {
1538+ ATLASSERT(::IsWindow(m_hWnd));
1539+ ::SendMessage(m_hWnd, EM_SETHILITE, nStartChar, nEndChar);
1540+ }
1541+#endif // (_WIN32_WINNT >= 0x0600)
1542+
1543+ // Clipboard operations
1544+ BOOL Undo()
1545+ {
1546+ ATLASSERT(::IsWindow(m_hWnd));
1547+ return (BOOL)::SendMessage(m_hWnd, EM_UNDO, 0, 0L);
1548+ }
1549+
1550+ void Clear()
1551+ {
1552+ ATLASSERT(::IsWindow(m_hWnd));
1553+ ::SendMessage(m_hWnd, WM_CLEAR, 0, 0L);
1554+ }
1555+
1556+ void Copy()
1557+ {
1558+ ATLASSERT(::IsWindow(m_hWnd));
1559+ ::SendMessage(m_hWnd, WM_COPY, 0, 0L);
1560+ }
1561+
1562+ void Cut()
1563+ {
1564+ ATLASSERT(::IsWindow(m_hWnd));
1565+ ::SendMessage(m_hWnd, WM_CUT, 0, 0L);
1566+ }
1567+
1568+ void Paste()
1569+ {
1570+ ATLASSERT(::IsWindow(m_hWnd));
1571+ ::SendMessage(m_hWnd, WM_PASTE, 0, 0L);
1572+ }
1573+
1574+#ifdef WIN32_PLATFORM_WFSP // SmartPhone only messages
1575+ DWORD GetExtendedStyle()
1576+ {
1577+ return SendMessage(EM_GETEXTENDEDSTYLE);
1578+ }
1579+
1580+ DWORD SetExtendedStyle(DWORD dwMask, DWORD dwExStyle)
1581+ {
1582+ return SendMessage(EM_SETEXTENDEDSTYLE, (WPARAM)dwMask, (LPARAM)dwExStyle);
1583+ }
1584+
1585+ DWORD GetInputMode(BOOL bCurrentMode = TRUE)
1586+ {
1587+ return SendMessage(EM_GETINPUTMODE, 0, (LPARAM)bCurrentMode);
1588+ }
1589+
1590+ BOOL SetInputMode(DWORD dwMode)
1591+ {
1592+ return SendMessage(EM_SETINPUTMODE, 0, (LPARAM)dwMode);
1593+ }
1594+
1595+ BOOL SetSymbols(LPCTSTR szSymbols)
1596+ {
1597+ return SendMessage(EM_SETSYMBOLS, 0, (LPARAM)szSymbols);
1598+ }
1599+
1600+ BOOL ResetSymbols()
1601+ {
1602+ return SendMessage(EM_SETSYMBOLS);
1603+ }
1604+#endif // WIN32_PLATFORM_WFSP
1605+};
1606+
1607+typedef CEditT<ATL::CWindow> CEdit;
1608+
1609+
1610+///////////////////////////////////////////////////////////////////////////////
1611+// CEditCommands - message handlers for standard EDIT commands
1612+
1613+// Chain to CEditCommands message map. Your class must also derive from CEdit.
1614+// Example:
1615+// class CMyEdit : public CWindowImpl<CMyEdit, CEdit>,
1616+// public CEditCommands<CMyEdit>
1617+// {
1618+// public:
1619+// BEGIN_MSG_MAP(CMyEdit)
1620+// // your handlers...
1621+// CHAIN_MSG_MAP_ALT(CEditCommands<CMyEdit>, 1)
1622+// END_MSG_MAP()
1623+// // other stuff...
1624+// };
1625+
1626+template <class T>
1627+class CEditCommands
1628+{
1629+public:
1630+ BEGIN_MSG_MAP(CEditCommands< T >)
1631+ ALT_MSG_MAP(1)
1632+ COMMAND_ID_HANDLER(ID_EDIT_CLEAR, OnEditClear)
1633+ COMMAND_ID_HANDLER(ID_EDIT_CLEAR_ALL, OnEditClearAll)
1634+ COMMAND_ID_HANDLER(ID_EDIT_COPY, OnEditCopy)
1635+ COMMAND_ID_HANDLER(ID_EDIT_CUT, OnEditCut)
1636+ COMMAND_ID_HANDLER(ID_EDIT_PASTE, OnEditPaste)
1637+ COMMAND_ID_HANDLER(ID_EDIT_SELECT_ALL, OnEditSelectAll)
1638+ COMMAND_ID_HANDLER(ID_EDIT_UNDO, OnEditUndo)
1639+ END_MSG_MAP()
1640+
1641+ LRESULT OnEditClear(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
1642+ {
1643+ T* pT = static_cast<T*>(this);
1644+ pT->Clear();
1645+ return 0;
1646+ }
1647+
1648+ LRESULT OnEditClearAll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
1649+ {
1650+ T* pT = static_cast<T*>(this);
1651+ pT->SetSel(0, -1);
1652+ pT->Clear();
1653+ return 0;
1654+ }
1655+
1656+ LRESULT OnEditCopy(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
1657+ {
1658+ T* pT = static_cast<T*>(this);
1659+ pT->Copy();
1660+ return 0;
1661+ }
1662+
1663+ LRESULT OnEditCut(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
1664+ {
1665+ T* pT = static_cast<T*>(this);
1666+ pT->Cut();
1667+ return 0;
1668+ }
1669+
1670+ LRESULT OnEditPaste(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
1671+ {
1672+ T* pT = static_cast<T*>(this);
1673+ pT->Paste();
1674+ return 0;
1675+ }
1676+
1677+ LRESULT OnEditSelectAll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
1678+ {
1679+ T* pT = static_cast<T*>(this);
1680+ pT->SetSel(0, -1);
1681+ return 0;
1682+ }
1683+
1684+ LRESULT OnEditUndo(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
1685+ {
1686+ T* pT = static_cast<T*>(this);
1687+ pT->Undo();
1688+ return 0;
1689+ }
1690+
1691+// State (update UI) helpers
1692+ BOOL CanCut() const
1693+ { return HasSelection(); }
1694+
1695+ BOOL CanCopy() const
1696+ { return HasSelection(); }
1697+
1698+ BOOL CanClear() const
1699+ { return HasSelection(); }
1700+
1701+ BOOL CanSelectAll() const
1702+ { return HasText(); }
1703+
1704+ BOOL CanFind() const
1705+ { return HasText(); }
1706+
1707+ BOOL CanRepeat() const
1708+ { return HasText(); }
1709+
1710+ BOOL CanReplace() const
1711+ { return HasText(); }
1712+
1713+ BOOL CanClearAll() const
1714+ { return HasText(); }
1715+
1716+// Implementation
1717+ BOOL HasSelection() const
1718+ {
1719+ const T* pT = static_cast<const T*>(this);
1720+ int nMin, nMax;
1721+ ::SendMessage(pT->m_hWnd, EM_GETSEL, (WPARAM)&nMin, (LPARAM)&nMax);
1722+ return (nMin != nMax);
1723+ }
1724+
1725+ BOOL HasText() const
1726+ {
1727+ const T* pT = static_cast<const T*>(this);
1728+ return (pT->GetWindowTextLength() > 0);
1729+ }
1730+};
1731+
1732+
1733+///////////////////////////////////////////////////////////////////////////////
1734+// CScrollBar - client side for a Windows SCROLLBAR control
1735+
1736+template <class TBase>
1737+class CScrollBarT : public TBase
1738+{
1739+public:
1740+// Constructors
1741+ CScrollBarT(HWND hWnd = NULL) : TBase(hWnd)
1742+ { }
1743+
1744+ CScrollBarT< TBase >& operator =(HWND hWnd)
1745+ {
1746+ m_hWnd = hWnd;
1747+ return *this;
1748+ }
1749+
1750+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
1751+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
1752+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
1753+ {
1754+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
1755+ }
1756+
1757+// Attributes
1758+ static LPCTSTR GetWndClassName()
1759+ {
1760+ return _T("SCROLLBAR");
1761+ }
1762+
1763+#ifndef _WIN32_WCE
1764+ int GetScrollPos() const
1765+ {
1766+ ATLASSERT(::IsWindow(m_hWnd));
1767+ return ::GetScrollPos(m_hWnd, SB_CTL);
1768+ }
1769+#endif // !_WIN32_WCE
1770+
1771+ int SetScrollPos(int nPos, BOOL bRedraw = TRUE)
1772+ {
1773+ ATLASSERT(::IsWindow(m_hWnd));
1774+ return ::SetScrollPos(m_hWnd, SB_CTL, nPos, bRedraw);
1775+ }
1776+
1777+#ifndef _WIN32_WCE
1778+ void GetScrollRange(LPINT lpMinPos, LPINT lpMaxPos) const
1779+ {
1780+ ATLASSERT(::IsWindow(m_hWnd));
1781+ ::GetScrollRange(m_hWnd, SB_CTL, lpMinPos, lpMaxPos);
1782+ }
1783+#endif // !_WIN32_WCE
1784+
1785+ void SetScrollRange(int nMinPos, int nMaxPos, BOOL bRedraw = TRUE)
1786+ {
1787+ ATLASSERT(::IsWindow(m_hWnd));
1788+ ::SetScrollRange(m_hWnd, SB_CTL, nMinPos, nMaxPos, bRedraw);
1789+ }
1790+
1791+ BOOL GetScrollInfo(LPSCROLLINFO lpScrollInfo) const
1792+ {
1793+ ATLASSERT(::IsWindow(m_hWnd));
1794+ return ::GetScrollInfo(m_hWnd, SB_CTL, lpScrollInfo);
1795+ }
1796+
1797+ int SetScrollInfo(LPSCROLLINFO lpScrollInfo, BOOL bRedraw = TRUE)
1798+ {
1799+ ATLASSERT(::IsWindow(m_hWnd));
1800+ return ::SetScrollInfo(m_hWnd, SB_CTL, lpScrollInfo, bRedraw);
1801+ }
1802+
1803+#ifndef _WIN32_WCE
1804+ int GetScrollLimit() const
1805+ {
1806+ int nMin = 0, nMax = 0;
1807+ ::GetScrollRange(m_hWnd, SB_CTL, &nMin, &nMax);
1808+ SCROLLINFO info = { 0 };
1809+ info.cbSize = sizeof(SCROLLINFO);
1810+ info.fMask = SIF_PAGE;
1811+ if(::GetScrollInfo(m_hWnd, SB_CTL, &info))
1812+ nMax -= ((info.nPage - 1) > 0) ? (info.nPage - 1) : 0;
1813+
1814+ return nMax;
1815+ }
1816+
1817+#if (WINVER >= 0x0500)
1818+ BOOL GetScrollBarInfo(PSCROLLBARINFO pScrollBarInfo) const
1819+ {
1820+ ATLASSERT(::IsWindow(m_hWnd));
1821+#if (_WIN32_WINNT >= 0x0501)
1822+ return (BOOL)::SendMessage(m_hWnd, SBM_GETSCROLLBARINFO, 0, (LPARAM)pScrollBarInfo);
1823+#else // !(_WIN32_WINNT >= 0x0501)
1824+ return ::GetScrollBarInfo(m_hWnd, OBJID_CLIENT, pScrollBarInfo);
1825+#endif // !(_WIN32_WINNT >= 0x0501)
1826+ }
1827+#endif // (WINVER >= 0x0500)
1828+
1829+// Operations
1830+ void ShowScrollBar(BOOL bShow = TRUE)
1831+ {
1832+ ATLASSERT(::IsWindow(m_hWnd));
1833+ ::ShowScrollBar(m_hWnd, SB_CTL, bShow);
1834+ }
1835+
1836+ BOOL EnableScrollBar(UINT nArrowFlags = ESB_ENABLE_BOTH)
1837+ {
1838+ ATLASSERT(::IsWindow(m_hWnd));
1839+ return ::EnableScrollBar(m_hWnd, SB_CTL, nArrowFlags);
1840+ }
1841+#endif // !_WIN32_WCE
1842+};
1843+
1844+typedef CScrollBarT<ATL::CWindow> CScrollBar;
1845+
1846+
1847+// --- Windows Common Controls ---
1848+
1849+///////////////////////////////////////////////////////////////////////////////
1850+// CImageList
1851+
1852+class CImageList
1853+{
1854+public:
1855+ HIMAGELIST m_hImageList;
1856+
1857+// Constructor
1858+ CImageList(HIMAGELIST hImageList = NULL) : m_hImageList(hImageList)
1859+ { }
1860+
1861+// Operators, etc.
1862+ CImageList& operator =(HIMAGELIST hImageList)
1863+ {
1864+ m_hImageList = hImageList;
1865+ return *this;
1866+ }
1867+
1868+ operator HIMAGELIST() const { return m_hImageList; }
1869+
1870+ void Attach(HIMAGELIST hImageList)
1871+ {
1872+ ATLASSERT(m_hImageList == NULL);
1873+ ATLASSERT(hImageList != NULL);
1874+ m_hImageList = hImageList;
1875+ }
1876+
1877+ HIMAGELIST Detach()
1878+ {
1879+ HIMAGELIST hImageList = m_hImageList;
1880+ m_hImageList = NULL;
1881+ return hImageList;
1882+ }
1883+
1884+ bool IsNull() const { return (m_hImageList == NULL); }
1885+
1886+// Attributes
1887+ int GetImageCount() const
1888+ {
1889+ ATLASSERT(m_hImageList != NULL);
1890+ return ImageList_GetImageCount(m_hImageList);
1891+ }
1892+
1893+ COLORREF GetBkColor() const
1894+ {
1895+ ATLASSERT(m_hImageList != NULL);
1896+ return ImageList_GetBkColor(m_hImageList);
1897+ }
1898+
1899+ COLORREF SetBkColor(COLORREF cr)
1900+ {
1901+ ATLASSERT(m_hImageList != NULL);
1902+ return ImageList_SetBkColor(m_hImageList, cr);
1903+ }
1904+
1905+ BOOL GetImageInfo(int nImage, IMAGEINFO* pImageInfo) const
1906+ {
1907+ ATLASSERT(m_hImageList != NULL);
1908+ return ImageList_GetImageInfo(m_hImageList, nImage, pImageInfo);
1909+ }
1910+
1911+ HICON GetIcon(int nIndex, UINT uFlags = ILD_NORMAL) const
1912+ {
1913+ ATLASSERT(m_hImageList != NULL);
1914+ return ImageList_GetIcon(m_hImageList, nIndex, uFlags);
1915+ }
1916+
1917+ BOOL GetIconSize(int& cx, int& cy) const
1918+ {
1919+ ATLASSERT(m_hImageList != NULL);
1920+ return ImageList_GetIconSize(m_hImageList, &cx, &cy);
1921+ }
1922+
1923+ BOOL GetIconSize(SIZE& size) const
1924+ {
1925+ ATLASSERT(m_hImageList != NULL);
1926+ return ImageList_GetIconSize(m_hImageList, (int*)&size.cx, (int*)&size.cy);
1927+ }
1928+
1929+ BOOL SetIconSize(int cx, int cy)
1930+ {
1931+ ATLASSERT(m_hImageList != NULL);
1932+ return ImageList_SetIconSize(m_hImageList, cx, cy);
1933+ }
1934+
1935+ BOOL SetIconSize(SIZE size)
1936+ {
1937+ ATLASSERT(m_hImageList != NULL);
1938+ return ImageList_SetIconSize(m_hImageList, size.cx, size.cy);
1939+ }
1940+
1941+ BOOL SetImageCount(UINT uNewCount)
1942+ {
1943+ ATLASSERT(m_hImageList != NULL);
1944+ return ImageList_SetImageCount(m_hImageList, uNewCount);
1945+ }
1946+
1947+ BOOL SetOverlayImage(int nImage, int nOverlay)
1948+ {
1949+ ATLASSERT(m_hImageList != NULL);
1950+ return ImageList_SetOverlayImage(m_hImageList, nImage, nOverlay);
1951+ }
1952+
1953+// Operations
1954+ BOOL Create(int cx, int cy, UINT nFlags, int nInitial, int nGrow)
1955+ {
1956+ ATLASSERT(m_hImageList == NULL);
1957+ m_hImageList = ImageList_Create(cx, cy, nFlags, nInitial, nGrow);
1958+ return (m_hImageList != NULL) ? TRUE : FALSE;
1959+ }
1960+
1961+ BOOL Create(ATL::_U_STRINGorID bitmap, int cx, int nGrow, COLORREF crMask)
1962+ {
1963+ ATLASSERT(m_hImageList == NULL);
1964+ m_hImageList = ImageList_LoadBitmap(ModuleHelper::GetResourceInstance(), bitmap.m_lpstr, cx, nGrow, crMask);
1965+ return (m_hImageList != NULL) ? TRUE : FALSE;
1966+ }
1967+
1968+ BOOL CreateFromImage(ATL::_U_STRINGorID image, int cx, int nGrow, COLORREF crMask, UINT uType, UINT uFlags = LR_DEFAULTCOLOR | LR_DEFAULTSIZE)
1969+ {
1970+ ATLASSERT(m_hImageList == NULL);
1971+ m_hImageList = ImageList_LoadImage(ModuleHelper::GetResourceInstance(), image.m_lpstr, cx, nGrow, crMask, uType, uFlags);
1972+ return (m_hImageList != NULL) ? TRUE : FALSE;
1973+ }
1974+
1975+ BOOL Merge(HIMAGELIST hImageList1, int nImage1, HIMAGELIST hImageList2, int nImage2, int dx, int dy)
1976+ {
1977+ ATLASSERT(m_hImageList == NULL);
1978+ m_hImageList = ImageList_Merge(hImageList1, nImage1, hImageList2, nImage2, dx, dy);
1979+ return (m_hImageList != NULL) ? TRUE : FALSE;
1980+ }
1981+
1982+#ifndef _WIN32_WCE
1983+#ifdef __IStream_INTERFACE_DEFINED__
1984+ BOOL CreateFromStream(LPSTREAM lpStream)
1985+ {
1986+ ATLASSERT(m_hImageList == NULL);
1987+ m_hImageList = ImageList_Read(lpStream);
1988+ return (m_hImageList != NULL) ? TRUE : FALSE;
1989+ }
1990+#endif // __IStream_INTERFACE_DEFINED__
1991+#endif // !_WIN32_WCE
1992+
1993+ BOOL Destroy()
1994+ {
1995+ if (m_hImageList == NULL)
1996+ return FALSE;
1997+ BOOL bRet = ImageList_Destroy(m_hImageList);
1998+ if(bRet)
1999+ m_hImageList = NULL;
2000+ return bRet;
2001+ }
2002+
2003+ int Add(HBITMAP hBitmap, HBITMAP hBitmapMask = NULL)
2004+ {
2005+ ATLASSERT(m_hImageList != NULL);
2006+ return ImageList_Add(m_hImageList, hBitmap, hBitmapMask);
2007+ }
2008+
2009+ int Add(HBITMAP hBitmap, COLORREF crMask)
2010+ {
2011+ ATLASSERT(m_hImageList != NULL);
2012+ return ImageList_AddMasked(m_hImageList, hBitmap, crMask);
2013+ }
2014+
2015+ BOOL Remove(int nImage)
2016+ {
2017+ ATLASSERT(m_hImageList != NULL);
2018+ return ImageList_Remove(m_hImageList, nImage);
2019+ }
2020+
2021+ BOOL RemoveAll()
2022+ {
2023+ ATLASSERT(m_hImageList != NULL);
2024+ return ImageList_RemoveAll(m_hImageList);
2025+ }
2026+
2027+ BOOL Replace(int nImage, HBITMAP hBitmap, HBITMAP hBitmapMask)
2028+ {
2029+ ATLASSERT(m_hImageList != NULL);
2030+ return ImageList_Replace(m_hImageList, nImage, hBitmap, hBitmapMask);
2031+ }
2032+
2033+ int AddIcon(HICON hIcon)
2034+ {
2035+ ATLASSERT(m_hImageList != NULL);
2036+ return ImageList_AddIcon(m_hImageList, hIcon);
2037+ }
2038+
2039+ int ReplaceIcon(int nImage, HICON hIcon)
2040+ {
2041+ ATLASSERT(m_hImageList != NULL);
2042+ return ImageList_ReplaceIcon(m_hImageList, nImage, hIcon);
2043+ }
2044+
2045+ HICON ExtractIcon(int nImage)
2046+ {
2047+ ATLASSERT(m_hImageList != NULL);
2048+ return ImageList_ExtractIcon(NULL, m_hImageList, nImage);
2049+ }
2050+
2051+ BOOL Draw(HDC hDC, int nImage, int x, int y, UINT nStyle)
2052+ {
2053+ ATLASSERT(m_hImageList != NULL);
2054+ ATLASSERT(hDC != NULL);
2055+ return ImageList_Draw(m_hImageList, nImage, hDC, x, y, nStyle);
2056+ }
2057+
2058+ BOOL Draw(HDC hDC, int nImage, POINT pt, UINT nStyle)
2059+ {
2060+ ATLASSERT(m_hImageList != NULL);
2061+ ATLASSERT(hDC != NULL);
2062+ return ImageList_Draw(m_hImageList, nImage, hDC, pt.x, pt.y, nStyle);
2063+ }
2064+
2065+ BOOL DrawEx(int nImage, HDC hDC, int x, int y, int dx, int dy, COLORREF rgbBk, COLORREF rgbFg, UINT fStyle)
2066+ {
2067+ ATLASSERT(m_hImageList != NULL);
2068+ ATLASSERT(hDC != NULL);
2069+ return ImageList_DrawEx(m_hImageList, nImage, hDC, x, y, dx, dy, rgbBk, rgbFg, fStyle);
2070+ }
2071+
2072+ BOOL DrawEx(int nImage, HDC hDC, RECT& rect, COLORREF rgbBk, COLORREF rgbFg, UINT fStyle)
2073+ {
2074+ ATLASSERT(m_hImageList != NULL);
2075+ ATLASSERT(hDC != NULL);
2076+ return ImageList_DrawEx(m_hImageList, nImage, hDC, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, rgbBk, rgbFg, fStyle);
2077+ }
2078+
2079+ static BOOL DrawIndirect(IMAGELISTDRAWPARAMS* pimldp)
2080+ {
2081+ return ImageList_DrawIndirect(pimldp);
2082+ }
2083+
2084+ BOOL Copy(int nSrc, int nDst, UINT uFlags = ILCF_MOVE)
2085+ {
2086+ ATLASSERT(m_hImageList != NULL);
2087+ return ImageList_Copy(m_hImageList, nDst, m_hImageList, nSrc, uFlags);
2088+ }
2089+
2090+#ifdef __IStream_INTERFACE_DEFINED__
2091+#ifndef _WIN32_WCE
2092+ static HIMAGELIST Read(LPSTREAM lpStream)
2093+ {
2094+ return ImageList_Read(lpStream);
2095+ }
2096+
2097+ BOOL Write(LPSTREAM lpStream)
2098+ {
2099+ ATLASSERT(m_hImageList != NULL);
2100+ return ImageList_Write(m_hImageList, lpStream);
2101+ }
2102+#endif // !_WIN32_WCE
2103+
2104+#if (_WIN32_WINNT >= 0x0501)
2105+ static HRESULT ReadEx(DWORD dwFlags, LPSTREAM lpStream, REFIID riid, PVOID* ppv)
2106+ {
2107+ return ImageList_ReadEx(dwFlags, lpStream, riid, ppv);
2108+ }
2109+
2110+ HRESULT WriteEx(DWORD dwFlags, LPSTREAM lpStream)
2111+ {
2112+ ATLASSERT(m_hImageList != NULL);
2113+ return ImageList_WriteEx(m_hImageList, dwFlags, lpStream);
2114+ }
2115+#endif // (_WIN32_WINNT >= 0x0501)
2116+#endif // __IStream_INTERFACE_DEFINED__
2117+
2118+ // Drag operations
2119+ BOOL BeginDrag(int nImage, POINT ptHotSpot)
2120+ {
2121+ ATLASSERT(m_hImageList != NULL);
2122+ return ImageList_BeginDrag(m_hImageList, nImage, ptHotSpot.x, ptHotSpot.y);
2123+ }
2124+
2125+ BOOL BeginDrag(int nImage, int xHotSpot, int yHotSpot)
2126+ {
2127+ ATLASSERT(m_hImageList != NULL);
2128+ return ImageList_BeginDrag(m_hImageList, nImage, xHotSpot, yHotSpot);
2129+ }
2130+
2131+ static void EndDrag()
2132+ {
2133+ ImageList_EndDrag();
2134+ }
2135+
2136+ static BOOL DragMove(POINT pt)
2137+ {
2138+ return ImageList_DragMove(pt.x, pt.y);
2139+ }
2140+
2141+ static BOOL DragMove(int x, int y)
2142+ {
2143+ return ImageList_DragMove(x, y);
2144+ }
2145+
2146+ BOOL SetDragCursorImage(int nDrag, POINT ptHotSpot)
2147+ {
2148+ ATLASSERT(m_hImageList != NULL);
2149+ return ImageList_SetDragCursorImage(m_hImageList, nDrag, ptHotSpot.x, ptHotSpot.y);
2150+ }
2151+
2152+ BOOL SetDragCursorImage(int nDrag, int xHotSpot, int yHotSpot)
2153+ {
2154+ ATLASSERT(m_hImageList != NULL);
2155+ return ImageList_SetDragCursorImage(m_hImageList, nDrag, xHotSpot, yHotSpot);
2156+ }
2157+
2158+ static BOOL DragShowNolock(BOOL bShow = TRUE)
2159+ {
2160+ return ImageList_DragShowNolock(bShow);
2161+ }
2162+
2163+ static CImageList GetDragImage(LPPOINT lpPoint, LPPOINT lpPointHotSpot)
2164+ {
2165+ return CImageList(ImageList_GetDragImage(lpPoint, lpPointHotSpot));
2166+ }
2167+
2168+ static BOOL DragEnter(HWND hWnd, POINT point)
2169+ {
2170+ return ImageList_DragEnter(hWnd, point.x, point.y);
2171+ }
2172+
2173+ static BOOL DragEnter(HWND hWnd, int x, int y)
2174+ {
2175+ return ImageList_DragEnter(hWnd, x, y);
2176+ }
2177+
2178+ static BOOL DragLeave(HWND hWnd)
2179+ {
2180+ return ImageList_DragLeave(hWnd);
2181+ }
2182+
2183+#if (_WIN32_IE >= 0x0400)
2184+ CImageList Duplicate() const
2185+ {
2186+ ATLASSERT(m_hImageList != NULL);
2187+ return CImageList(ImageList_Duplicate(m_hImageList));
2188+ }
2189+
2190+ static CImageList Duplicate(HIMAGELIST hImageList)
2191+ {
2192+ ATLASSERT(hImageList != NULL);
2193+ return CImageList(ImageList_Duplicate(hImageList));
2194+ }
2195+#endif // (_WIN32_IE >= 0x0400)
2196+};
2197+
2198+
2199+///////////////////////////////////////////////////////////////////////////////
2200+// CToolTipCtrl
2201+
2202+#ifndef _WIN32_WCE
2203+
2204+class CToolInfo : public TOOLINFO
2205+{
2206+public:
2207+ CToolInfo(UINT nFlags, HWND hWnd, UINT nIDTool = 0, LPRECT lpRect = NULL, LPTSTR lpstrText = LPSTR_TEXTCALLBACK, LPARAM lUserParam = NULL)
2208+ {
2209+ Init(nFlags, hWnd, nIDTool, lpRect, lpstrText, lUserParam);
2210+ }
2211+
2212+ operator LPTOOLINFO() { return this; }
2213+
2214+ operator LPARAM() { return (LPARAM)this; }
2215+
2216+ void Init(UINT nFlags, HWND hWnd, UINT nIDTool = 0, LPRECT lpRect = NULL, LPTSTR lpstrText = LPSTR_TEXTCALLBACK, LPARAM lUserParam = NULL)
2217+ {
2218+ ATLASSERT(::IsWindow(hWnd));
2219+ memset(this, 0, sizeof(TOOLINFO));
2220+ cbSize = sizeof(TOOLINFO);
2221+ uFlags = nFlags;
2222+ if(nIDTool == 0)
2223+ {
2224+ hwnd = ::GetParent(hWnd);
2225+ uFlags |= TTF_IDISHWND;
2226+ uId = (UINT_PTR)hWnd;
2227+ }
2228+ else
2229+ {
2230+ hwnd = hWnd;
2231+ uId = nIDTool;
2232+ }
2233+ if(lpRect != NULL)
2234+ rect = *lpRect;
2235+ hinst = ModuleHelper::GetResourceInstance();
2236+ lpszText = lpstrText;
2237+ lParam = lUserParam;
2238+ }
2239+};
2240+
2241+template <class TBase>
2242+class CToolTipCtrlT : public TBase
2243+{
2244+public:
2245+// Constructors
2246+ CToolTipCtrlT(HWND hWnd = NULL) : TBase(hWnd)
2247+ { }
2248+
2249+ CToolTipCtrlT< TBase >& operator =(HWND hWnd)
2250+ {
2251+ m_hWnd = hWnd;
2252+ return *this;
2253+ }
2254+
2255+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
2256+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
2257+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
2258+ {
2259+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
2260+ }
2261+
2262+// Attributes
2263+ static LPCTSTR GetWndClassName()
2264+ {
2265+ return TOOLTIPS_CLASS;
2266+ }
2267+
2268+ void GetText(LPTOOLINFO lpToolInfo) const
2269+ {
2270+ ATLASSERT(::IsWindow(m_hWnd));
2271+ ::SendMessage(m_hWnd, TTM_GETTEXT, 0, (LPARAM)&lpToolInfo);
2272+ }
2273+
2274+ void GetText(LPTSTR lpstrText, HWND hWnd, UINT nIDTool = 0) const
2275+ {
2276+ ATLASSERT(::IsWindow(m_hWnd));
2277+ ATLASSERT(hWnd != NULL);
2278+ CToolInfo ti(0, hWnd, nIDTool, NULL, lpstrText);
2279+ ::SendMessage(m_hWnd, TTM_GETTEXT, 0, ti);
2280+ }
2281+
2282+ BOOL GetToolInfo(LPTOOLINFO lpToolInfo) const
2283+ {
2284+ ATLASSERT(::IsWindow(m_hWnd));
2285+ return (BOOL)::SendMessage(m_hWnd, TTM_GETTOOLINFO, 0, (LPARAM)lpToolInfo);
2286+ }
2287+
2288+ BOOL GetToolInfo(HWND hWnd, UINT nIDTool, UINT* puFlags, LPRECT lpRect, LPTSTR lpstrText) const
2289+ {
2290+ ATLASSERT(::IsWindow(m_hWnd));
2291+ ATLASSERT(hWnd != NULL);
2292+ ATLASSERT(puFlags != NULL);
2293+ ATLASSERT(lpRect != NULL);
2294+ CToolInfo ti(0, hWnd, nIDTool, NULL, lpstrText);
2295+ BOOL bRet = (BOOL)::SendMessage(m_hWnd, TTM_GETTOOLINFO, 0, ti);
2296+ if(bRet != FALSE)
2297+ {
2298+ *puFlags = ti.uFlags;
2299+ *lpRect = ti.rect;
2300+ }
2301+ return bRet;
2302+ }
2303+
2304+ void SetToolInfo(LPTOOLINFO lpToolInfo)
2305+ {
2306+ ATLASSERT(::IsWindow(m_hWnd));
2307+ ::SendMessage(m_hWnd, TTM_SETTOOLINFO, 0, (LPARAM)lpToolInfo);
2308+ }
2309+
2310+ void SetToolRect(LPTOOLINFO lpToolInfo)
2311+ {
2312+ ATLASSERT(::IsWindow(m_hWnd));
2313+ ::SendMessage(m_hWnd, TTM_NEWTOOLRECT, 0, (LPARAM)lpToolInfo);
2314+ }
2315+
2316+ void SetToolRect(HWND hWnd, UINT nIDTool, LPCRECT lpRect)
2317+ {
2318+ ATLASSERT(::IsWindow(m_hWnd));
2319+ ATLASSERT(hWnd != NULL);
2320+ ATLASSERT(nIDTool != 0);
2321+
2322+ CToolInfo ti(0, hWnd, nIDTool, (LPRECT)lpRect, NULL);
2323+ ::SendMessage(m_hWnd, TTM_NEWTOOLRECT, 0, ti);
2324+ }
2325+
2326+ int GetToolCount() const
2327+ {
2328+ ATLASSERT(::IsWindow(m_hWnd));
2329+ return (int)::SendMessage(m_hWnd, TTM_GETTOOLCOUNT, 0, 0L);
2330+ }
2331+
2332+ int GetDelayTime(DWORD dwType) const
2333+ {
2334+ ATLASSERT(::IsWindow(m_hWnd));
2335+ return (int)::SendMessage(m_hWnd, TTM_GETDELAYTIME, dwType, 0L);
2336+ }
2337+
2338+ void SetDelayTime(DWORD dwType, int nTime)
2339+ {
2340+ ATLASSERT(::IsWindow(m_hWnd));
2341+ ::SendMessage(m_hWnd, TTM_SETDELAYTIME, dwType, MAKELPARAM(nTime, 0));
2342+ }
2343+
2344+ void GetMargin(LPRECT lpRect) const
2345+ {
2346+ ATLASSERT(::IsWindow(m_hWnd));
2347+ ::SendMessage(m_hWnd, TTM_GETMARGIN, 0, (LPARAM)lpRect);
2348+ }
2349+
2350+ void SetMargin(LPRECT lpRect)
2351+ {
2352+ ATLASSERT(::IsWindow(m_hWnd));
2353+ ::SendMessage(m_hWnd, TTM_SETMARGIN, 0, (LPARAM)lpRect);
2354+ }
2355+
2356+ int GetMaxTipWidth() const
2357+ {
2358+ ATLASSERT(::IsWindow(m_hWnd));
2359+ return (int)::SendMessage(m_hWnd, TTM_GETMAXTIPWIDTH, 0, 0L);
2360+ }
2361+
2362+ int SetMaxTipWidth(int nWidth)
2363+ {
2364+ ATLASSERT(::IsWindow(m_hWnd));
2365+ return (int)::SendMessage(m_hWnd, TTM_SETMAXTIPWIDTH, 0, nWidth);
2366+ }
2367+
2368+ COLORREF GetTipBkColor() const
2369+ {
2370+ ATLASSERT(::IsWindow(m_hWnd));
2371+ return (COLORREF)::SendMessage(m_hWnd, TTM_GETTIPBKCOLOR, 0, 0L);
2372+ }
2373+
2374+ void SetTipBkColor(COLORREF clr)
2375+ {
2376+ ATLASSERT(::IsWindow(m_hWnd));
2377+ ::SendMessage(m_hWnd, TTM_SETTIPBKCOLOR, (WPARAM)clr, 0L);
2378+ }
2379+
2380+ COLORREF GetTipTextColor() const
2381+ {
2382+ ATLASSERT(::IsWindow(m_hWnd));
2383+ return (COLORREF)::SendMessage(m_hWnd, TTM_GETTIPTEXTCOLOR, 0, 0L);
2384+ }
2385+
2386+ void SetTipTextColor(COLORREF clr)
2387+ {
2388+ ATLASSERT(::IsWindow(m_hWnd));
2389+ ::SendMessage(m_hWnd, TTM_SETTIPTEXTCOLOR, (WPARAM)clr, 0L);
2390+ }
2391+
2392+ BOOL GetCurrentTool(LPTOOLINFO lpToolInfo) const
2393+ {
2394+ ATLASSERT(::IsWindow(m_hWnd));
2395+ return (BOOL)::SendMessage(m_hWnd, TTM_GETCURRENTTOOL, 0, (LPARAM)lpToolInfo);
2396+ }
2397+
2398+#if (_WIN32_IE >= 0x0500)
2399+ SIZE GetBubbleSize(LPTOOLINFO lpToolInfo) const
2400+ {
2401+ ATLASSERT(::IsWindow(m_hWnd));
2402+ DWORD dwRet = (DWORD)::SendMessage(m_hWnd, TTM_GETBUBBLESIZE, 0, (LPARAM)lpToolInfo);
2403+ SIZE size = { GET_X_LPARAM(dwRet), GET_Y_LPARAM(dwRet) };
2404+ return size;
2405+ }
2406+
2407+ BOOL SetTitle(UINT uIcon, LPCTSTR lpstrTitle)
2408+ {
2409+ ATLASSERT(::IsWindow(m_hWnd));
2410+ return (BOOL)::SendMessage(m_hWnd, TTM_SETTITLE, uIcon, (LPARAM)lpstrTitle);
2411+ }
2412+#endif // (_WIN32_IE >= 0x0500)
2413+
2414+#if (_WIN32_WINNT >= 0x0501)
2415+ void GetTitle(PTTGETTITLE pTTGetTitle) const
2416+ {
2417+ ATLASSERT(::IsWindow(m_hWnd));
2418+ ::SendMessage(m_hWnd, TTM_GETTITLE, 0, (LPARAM)pTTGetTitle);
2419+ }
2420+
2421+ void SetWindowTheme(LPCWSTR lpstrTheme)
2422+ {
2423+ ATLASSERT(::IsWindow(m_hWnd));
2424+ ::SendMessage(m_hWnd, TTM_SETWINDOWTHEME, 0, (LPARAM)lpstrTheme);
2425+ }
2426+#endif // (_WIN32_WINNT >= 0x0501)
2427+
2428+// Operations
2429+ void Activate(BOOL bActivate)
2430+ {
2431+ ATLASSERT(::IsWindow(m_hWnd));
2432+ ::SendMessage(m_hWnd, TTM_ACTIVATE, bActivate, 0L);
2433+ }
2434+
2435+ BOOL AddTool(LPTOOLINFO lpToolInfo)
2436+ {
2437+ ATLASSERT(::IsWindow(m_hWnd));
2438+ return (BOOL)::SendMessage(m_hWnd, TTM_ADDTOOL, 0, (LPARAM)lpToolInfo);
2439+ }
2440+
2441+ BOOL AddTool(HWND hWnd, ATL::_U_STRINGorID text = LPSTR_TEXTCALLBACK, LPCRECT lpRectTool = NULL, UINT nIDTool = 0)
2442+ {
2443+ ATLASSERT(::IsWindow(m_hWnd));
2444+ ATLASSERT(hWnd != NULL);
2445+ // the toolrect and toolid must both be zero or both valid
2446+ ATLASSERT((lpRectTool != NULL && nIDTool != 0) || (lpRectTool == NULL && nIDTool == 0));
2447+
2448+ CToolInfo ti(0, hWnd, nIDTool, (LPRECT)lpRectTool, (LPTSTR)text.m_lpstr);
2449+ return (BOOL)::SendMessage(m_hWnd, TTM_ADDTOOL, 0, ti);
2450+ }
2451+
2452+ void DelTool(LPTOOLINFO lpToolInfo)
2453+ {
2454+ ATLASSERT(::IsWindow(m_hWnd));
2455+ ::SendMessage(m_hWnd, TTM_DELTOOL, 0, (LPARAM)lpToolInfo);
2456+ }
2457+
2458+ void DelTool(HWND hWnd, UINT nIDTool = 0)
2459+ {
2460+ ATLASSERT(::IsWindow(m_hWnd));
2461+ ATLASSERT(hWnd != NULL);
2462+
2463+ CToolInfo ti(0, hWnd, nIDTool, NULL, NULL);
2464+ ::SendMessage(m_hWnd, TTM_DELTOOL, 0, ti);
2465+ }
2466+
2467+ BOOL HitTest(LPTTHITTESTINFO lpHitTestInfo) const
2468+ {
2469+ ATLASSERT(::IsWindow(m_hWnd));
2470+ return (BOOL)::SendMessage(m_hWnd, TTM_HITTEST, 0, (LPARAM)lpHitTestInfo);
2471+ }
2472+
2473+ BOOL HitTest(HWND hWnd, POINT pt, LPTOOLINFO lpToolInfo) const
2474+ {
2475+ ATLASSERT(::IsWindow(m_hWnd));
2476+ ATLASSERT(hWnd != NULL);
2477+ ATLASSERT(lpToolInfo != NULL);
2478+
2479+ TTHITTESTINFO hti = { 0 };
2480+ hti.ti.cbSize = sizeof(TOOLINFO);
2481+ hti.hwnd = hWnd;
2482+ hti.pt.x = pt.x;
2483+ hti.pt.y = pt.y;
2484+ if((BOOL)::SendMessage(m_hWnd, TTM_HITTEST, 0, (LPARAM)&hti) != FALSE)
2485+ {
2486+ *lpToolInfo = hti.ti;
2487+ return TRUE;
2488+ }
2489+ return FALSE;
2490+ }
2491+
2492+ void RelayEvent(LPMSG lpMsg)
2493+ {
2494+ ATLASSERT(::IsWindow(m_hWnd));
2495+ ::SendMessage(m_hWnd, TTM_RELAYEVENT, 0, (LPARAM)lpMsg);
2496+ }
2497+
2498+ void UpdateTipText(LPTOOLINFO lpToolInfo)
2499+ {
2500+ ATLASSERT(::IsWindow(m_hWnd));
2501+ ::SendMessage(m_hWnd, TTM_UPDATETIPTEXT, 0, (LPARAM)lpToolInfo);
2502+ }
2503+
2504+ void UpdateTipText(ATL::_U_STRINGorID text, HWND hWnd, UINT nIDTool = 0)
2505+ {
2506+ ATLASSERT(::IsWindow(m_hWnd));
2507+ ATLASSERT(hWnd != NULL);
2508+
2509+ CToolInfo ti(0, hWnd, nIDTool, NULL, (LPTSTR)text.m_lpstr);
2510+ ::SendMessage(m_hWnd, TTM_UPDATETIPTEXT, 0, ti);
2511+ }
2512+
2513+ BOOL EnumTools(UINT nTool, LPTOOLINFO lpToolInfo) const
2514+ {
2515+ ATLASSERT(::IsWindow(m_hWnd));
2516+ return (BOOL)::SendMessage(m_hWnd, TTM_ENUMTOOLS, nTool, (LPARAM)lpToolInfo);
2517+ }
2518+
2519+ void Pop()
2520+ {
2521+ ATLASSERT(::IsWindow(m_hWnd));
2522+ ::SendMessage(m_hWnd, TTM_POP, 0, 0L);
2523+ }
2524+
2525+ void TrackActivate(LPTOOLINFO lpToolInfo, BOOL bActivate)
2526+ {
2527+ ATLASSERT(::IsWindow(m_hWnd));
2528+ ::SendMessage(m_hWnd, TTM_TRACKACTIVATE, bActivate, (LPARAM)lpToolInfo);
2529+ }
2530+
2531+ void TrackPosition(int xPos, int yPos)
2532+ {
2533+ ATLASSERT(::IsWindow(m_hWnd));
2534+ ::SendMessage(m_hWnd, TTM_TRACKPOSITION, 0, MAKELPARAM(xPos, yPos));
2535+ }
2536+
2537+#if (_WIN32_IE >= 0x0400)
2538+ void Update()
2539+ {
2540+ ATLASSERT(::IsWindow(m_hWnd));
2541+ ::SendMessage(m_hWnd, TTM_UPDATE, 0, 0L);
2542+ }
2543+#endif // (_WIN32_IE >= 0x0400)
2544+
2545+#if (_WIN32_IE >= 0x0500)
2546+ BOOL AdjustRect(LPRECT lpRect, BOOL bLarger /*= TRUE*/)
2547+ {
2548+ ATLASSERT(::IsWindow(m_hWnd));
2549+ return (BOOL)::SendMessage(m_hWnd, TTM_ADJUSTRECT, bLarger, (LPARAM)lpRect);
2550+ }
2551+#endif // (_WIN32_IE >= 0x0500)
2552+
2553+#if (_WIN32_WINNT >= 0x0501)
2554+ void Popup()
2555+ {
2556+ ATLASSERT(::IsWindow(m_hWnd));
2557+ ::SendMessage(m_hWnd, TTM_POPUP, 0, 0L);
2558+ }
2559+#endif // (_WIN32_WINNT >= 0x0501)
2560+};
2561+
2562+typedef CToolTipCtrlT<ATL::CWindow> CToolTipCtrl;
2563+
2564+#endif // !_WIN32_WCE
2565+
2566+
2567+///////////////////////////////////////////////////////////////////////////////
2568+// CHeaderCtrl
2569+
2570+template <class TBase>
2571+class CHeaderCtrlT : public TBase
2572+{
2573+public:
2574+// Constructors
2575+ CHeaderCtrlT(HWND hWnd = NULL) : TBase(hWnd)
2576+ { }
2577+
2578+ CHeaderCtrlT< TBase >& operator =(HWND hWnd)
2579+ {
2580+ m_hWnd = hWnd;
2581+ return *this;
2582+ }
2583+
2584+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
2585+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
2586+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
2587+ {
2588+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
2589+ }
2590+
2591+// Attributes
2592+ static LPCTSTR GetWndClassName()
2593+ {
2594+ return WC_HEADER;
2595+ }
2596+
2597+ int GetItemCount() const
2598+ {
2599+ ATLASSERT(::IsWindow(m_hWnd));
2600+ return (int)::SendMessage(m_hWnd, HDM_GETITEMCOUNT, 0, 0L);
2601+ }
2602+
2603+ BOOL GetItem(int nIndex, LPHDITEM pHeaderItem) const
2604+ {
2605+ ATLASSERT(::IsWindow(m_hWnd));
2606+ return (BOOL)::SendMessage(m_hWnd, HDM_GETITEM, nIndex, (LPARAM)pHeaderItem);
2607+ }
2608+
2609+ BOOL SetItem(int nIndex, LPHDITEM pHeaderItem)
2610+ {
2611+ ATLASSERT(::IsWindow(m_hWnd));
2612+ return (BOOL)::SendMessage(m_hWnd, HDM_SETITEM, nIndex, (LPARAM)pHeaderItem);
2613+ }
2614+
2615+ CImageList GetImageList() const
2616+ {
2617+ ATLASSERT(::IsWindow(m_hWnd));
2618+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, HDM_GETIMAGELIST, 0, 0L));
2619+ }
2620+
2621+ CImageList SetImageList(HIMAGELIST hImageList)
2622+ {
2623+ ATLASSERT(::IsWindow(m_hWnd));
2624+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, HDM_SETIMAGELIST, 0, (LPARAM)hImageList));
2625+ }
2626+
2627+ BOOL GetOrderArray(int nSize, int* lpnArray) const
2628+ {
2629+ ATLASSERT(::IsWindow(m_hWnd));
2630+ return (BOOL)::SendMessage(m_hWnd, HDM_GETORDERARRAY, nSize, (LPARAM)lpnArray);
2631+ }
2632+
2633+ BOOL SetOrderArray(int nSize, int* lpnArray)
2634+ {
2635+ ATLASSERT(::IsWindow(m_hWnd));
2636+ return (BOOL)::SendMessage(m_hWnd, HDM_SETORDERARRAY, nSize, (LPARAM)lpnArray);
2637+ }
2638+
2639+ BOOL GetItemRect(int nIndex, LPRECT lpItemRect) const
2640+ {
2641+ ATLASSERT(::IsWindow(m_hWnd));
2642+ return (BOOL)::SendMessage(m_hWnd, HDM_GETITEMRECT, nIndex, (LPARAM)lpItemRect);
2643+ }
2644+
2645+ int SetHotDivider(BOOL bPos, DWORD dwInputValue)
2646+ {
2647+ ATLASSERT(::IsWindow(m_hWnd));
2648+ return (int)::SendMessage(m_hWnd, HDM_SETHOTDIVIDER, bPos, dwInputValue);
2649+ }
2650+
2651+#if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
2652+ BOOL GetUnicodeFormat() const
2653+ {
2654+ ATLASSERT(::IsWindow(m_hWnd));
2655+ return (BOOL)::SendMessage(m_hWnd, HDM_GETUNICODEFORMAT, 0, 0L);
2656+ }
2657+
2658+ BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
2659+ {
2660+ ATLASSERT(::IsWindow(m_hWnd));
2661+ return (BOOL)::SendMessage(m_hWnd, HDM_SETUNICODEFORMAT, bUnicode, 0L);
2662+ }
2663+#endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
2664+
2665+#if (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
2666+ int GetBitmapMargin() const
2667+ {
2668+ ATLASSERT(::IsWindow(m_hWnd));
2669+ return (int)::SendMessage(m_hWnd, HDM_GETBITMAPMARGIN, 0, 0L);
2670+ }
2671+
2672+ int SetBitmapMargin(int nWidth)
2673+ {
2674+ ATLASSERT(::IsWindow(m_hWnd));
2675+ return (int)::SendMessage(m_hWnd, HDM_SETBITMAPMARGIN, nWidth, 0L);
2676+ }
2677+
2678+ int SetFilterChangeTimeout(DWORD dwTimeOut)
2679+ {
2680+ ATLASSERT(::IsWindow(m_hWnd));
2681+ return (int)::SendMessage(m_hWnd, HDM_SETFILTERCHANGETIMEOUT, 0, dwTimeOut);
2682+ }
2683+#endif // (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
2684+
2685+#if (_WIN32_WINNT >= 0x0600)
2686+ BOOL GetItemDropDownRect(int nIndex, LPRECT lpRect) const
2687+ {
2688+ ATLASSERT(::IsWindow(m_hWnd));
2689+ return (BOOL)::SendMessage(m_hWnd, HDM_GETITEMDROPDOWNRECT, nIndex, (LPARAM)lpRect);
2690+ }
2691+
2692+ BOOL GetOverflowRect(LPRECT lpRect) const
2693+ {
2694+ ATLASSERT(::IsWindow(m_hWnd));
2695+ return (BOOL)::SendMessage(m_hWnd, HDM_GETOVERFLOWRECT, 0, (LPARAM)lpRect);
2696+ }
2697+
2698+ int GetFocusedItem() const
2699+ {
2700+ ATLASSERT(::IsWindow(m_hWnd));
2701+ return (int)::SendMessage(m_hWnd, HDM_GETFOCUSEDITEM, 0, 0L);
2702+ }
2703+
2704+ BOOL SetFocusedItem(int nIndex)
2705+ {
2706+ ATLASSERT(::IsWindow(m_hWnd));
2707+ return (BOOL)::SendMessage(m_hWnd, HDM_SETFOCUSEDITEM, 0, nIndex);
2708+ }
2709+#endif // (_WIN32_WINNT >= 0x0600)
2710+
2711+// Operations
2712+ int InsertItem(int nIndex, LPHDITEM phdi)
2713+ {
2714+ ATLASSERT(::IsWindow(m_hWnd));
2715+ return (int)::SendMessage(m_hWnd, HDM_INSERTITEM, nIndex, (LPARAM)phdi);
2716+ }
2717+
2718+ int AddItem(LPHDITEM phdi)
2719+ {
2720+ return InsertItem(GetItemCount(), phdi);
2721+ }
2722+
2723+ BOOL DeleteItem(int nIndex)
2724+ {
2725+ ATLASSERT(::IsWindow(m_hWnd));
2726+ return (BOOL)::SendMessage(m_hWnd, HDM_DELETEITEM, nIndex, 0L);
2727+ }
2728+
2729+ BOOL Layout(HD_LAYOUT* pHeaderLayout)
2730+ {
2731+ ATLASSERT(::IsWindow(m_hWnd));
2732+ return (BOOL)::SendMessage(m_hWnd, HDM_LAYOUT, 0, (LPARAM)pHeaderLayout);
2733+ }
2734+
2735+ int HitTest(LPHDHITTESTINFO lpHitTestInfo) const
2736+ {
2737+ ATLASSERT(::IsWindow(m_hWnd));
2738+ return (int)::SendMessage(m_hWnd, HDM_HITTEST, 0, (LPARAM)lpHitTestInfo);
2739+ }
2740+
2741+ int OrderToIndex(int nOrder)
2742+ {
2743+ ATLASSERT(::IsWindow(m_hWnd));
2744+ return (int)::SendMessage(m_hWnd, HDM_ORDERTOINDEX, nOrder, 0L);
2745+ }
2746+
2747+ CImageList CreateDragImage(int nIndex)
2748+ {
2749+ ATLASSERT(::IsWindow(m_hWnd));
2750+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, HDM_CREATEDRAGIMAGE, nIndex, 0L));
2751+ }
2752+
2753+#if (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
2754+ int EditFilter(int nColumn, BOOL bDiscardChanges)
2755+ {
2756+ ATLASSERT(::IsWindow(m_hWnd));
2757+ return (int)::SendMessage(m_hWnd, HDM_EDITFILTER, nColumn, MAKELPARAM(bDiscardChanges, 0));
2758+ }
2759+
2760+ int ClearFilter(int nColumn)
2761+ {
2762+ ATLASSERT(::IsWindow(m_hWnd));
2763+ return (int)::SendMessage(m_hWnd, HDM_CLEARFILTER, nColumn, 0L);
2764+ }
2765+
2766+ int ClearAllFilters()
2767+ {
2768+ ATLASSERT(::IsWindow(m_hWnd));
2769+ return (int)::SendMessage(m_hWnd, HDM_CLEARFILTER, (WPARAM)-1, 0L);
2770+ }
2771+#endif // (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
2772+};
2773+
2774+typedef CHeaderCtrlT<ATL::CWindow> CHeaderCtrl;
2775+
2776+
2777+///////////////////////////////////////////////////////////////////////////////
2778+// CListViewCtrl
2779+
2780+template <class TBase>
2781+class CListViewCtrlT : public TBase
2782+{
2783+public:
2784+// Constructors
2785+ CListViewCtrlT(HWND hWnd = NULL) : TBase(hWnd)
2786+ { }
2787+
2788+ CListViewCtrlT< TBase >& operator =(HWND hWnd)
2789+ {
2790+ m_hWnd = hWnd;
2791+ return *this;
2792+ }
2793+
2794+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
2795+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
2796+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
2797+ {
2798+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
2799+ }
2800+
2801+// Attributes
2802+ static LPCTSTR GetWndClassName()
2803+ {
2804+ return WC_LISTVIEW;
2805+ }
2806+
2807+ COLORREF GetBkColor() const
2808+ {
2809+ ATLASSERT(::IsWindow(m_hWnd));
2810+ return (COLORREF)::SendMessage(m_hWnd, LVM_GETBKCOLOR, 0, 0L);
2811+ }
2812+
2813+ BOOL SetBkColor(COLORREF cr)
2814+ {
2815+ ATLASSERT(::IsWindow(m_hWnd));
2816+ return (BOOL)::SendMessage(m_hWnd, LVM_SETBKCOLOR, 0, cr);
2817+ }
2818+
2819+ CImageList GetImageList(int nImageListType) const
2820+ {
2821+ ATLASSERT(::IsWindow(m_hWnd));
2822+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, LVM_GETIMAGELIST, nImageListType, 0L));
2823+ }
2824+
2825+ CImageList SetImageList(HIMAGELIST hImageList, int nImageList)
2826+ {
2827+ ATLASSERT(::IsWindow(m_hWnd));
2828+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, LVM_SETIMAGELIST, nImageList, (LPARAM)hImageList));
2829+ }
2830+
2831+ int GetItemCount() const
2832+ {
2833+ ATLASSERT(::IsWindow(m_hWnd));
2834+ return (int)::SendMessage(m_hWnd, LVM_GETITEMCOUNT, 0, 0L);
2835+ }
2836+
2837+ BOOL SetItemCount(int nItems)
2838+ {
2839+ ATLASSERT(::IsWindow(m_hWnd));
2840+ return (BOOL)::SendMessage(m_hWnd, LVM_SETITEMCOUNT, nItems, 0L);
2841+ }
2842+
2843+ BOOL GetItem(LPLVITEM pItem) const
2844+ {
2845+ ATLASSERT(::IsWindow(m_hWnd));
2846+ return (BOOL)::SendMessage(m_hWnd, LVM_GETITEM, 0, (LPARAM)pItem);
2847+ }
2848+
2849+ BOOL SetItem(const LVITEM* pItem)
2850+ {
2851+ ATLASSERT(::IsWindow(m_hWnd));
2852+ return (BOOL)::SendMessage(m_hWnd, LVM_SETITEM, 0, (LPARAM)pItem);
2853+ }
2854+
2855+ BOOL SetItem(int nItem, int nSubItem, UINT nMask, LPCTSTR lpszItem,
2856+ int nImage, UINT nState, UINT nStateMask, LPARAM lParam)
2857+ {
2858+ ATLASSERT(::IsWindow(m_hWnd));
2859+ LVITEM lvi = { 0 };
2860+ lvi.mask = nMask;
2861+ lvi.iItem = nItem;
2862+ lvi.iSubItem = nSubItem;
2863+ lvi.stateMask = nStateMask;
2864+ lvi.state = nState;
2865+ lvi.pszText = (LPTSTR) lpszItem;
2866+ lvi.iImage = nImage;
2867+ lvi.lParam = lParam;
2868+ return (BOOL)::SendMessage(m_hWnd, LVM_SETITEM, 0, (LPARAM)&lvi);
2869+ }
2870+
2871+ UINT GetItemState(int nItem, UINT nMask) const
2872+ {
2873+ ATLASSERT(::IsWindow(m_hWnd));
2874+ return (UINT)::SendMessage(m_hWnd, LVM_GETITEMSTATE, nItem, nMask);
2875+ }
2876+
2877+ BOOL SetItemState(int nItem, UINT nState, UINT nStateMask)
2878+ {
2879+ ATLASSERT(::IsWindow(m_hWnd));
2880+ LVITEM lvi = { 0 };
2881+ lvi.state = nState;
2882+ lvi.stateMask = nStateMask;
2883+ return (BOOL)::SendMessage(m_hWnd, LVM_SETITEMSTATE, nItem, (LPARAM)&lvi);
2884+ }
2885+
2886+ BOOL SetItemState(int nItem, LPLVITEM pItem)
2887+ {
2888+ ATLASSERT(::IsWindow(m_hWnd));
2889+ return (BOOL)::SendMessage(m_hWnd, LVM_SETITEMSTATE, nItem, (LPARAM)pItem);
2890+ }
2891+
2892+#ifndef _ATL_NO_COM
2893+ BOOL GetItemText(int nItem, int nSubItem, BSTR& bstrText) const
2894+ {
2895+ USES_CONVERSION;
2896+ ATLASSERT(::IsWindow(m_hWnd));
2897+ ATLASSERT(bstrText == NULL);
2898+ LVITEM lvi = { 0 };
2899+ lvi.iSubItem = nSubItem;
2900+
2901+ LPTSTR lpstrText = NULL;
2902+ int nRes = 0;
2903+ for(int nLen = 256; ; nLen *= 2)
2904+ {
2905+ ATLTRY(lpstrText = new TCHAR[nLen]);
2906+ if(lpstrText == NULL)
2907+ break;
2908+ lpstrText[0] = NULL;
2909+ lvi.cchTextMax = nLen;
2910+ lvi.pszText = lpstrText;
2911+ nRes = (int)::SendMessage(m_hWnd, LVM_GETITEMTEXT, (WPARAM)nItem, (LPARAM)&lvi);
2912+ if(nRes < nLen - 1)
2913+ break;
2914+ delete [] lpstrText;
2915+ lpstrText = NULL;
2916+ }
2917+
2918+ if(lpstrText != NULL)
2919+ {
2920+ if(nRes != 0)
2921+ bstrText = ::SysAllocString(T2OLE(lpstrText));
2922+ delete [] lpstrText;
2923+ }
2924+
2925+ return (bstrText != NULL) ? TRUE : FALSE;
2926+ }
2927+#endif // !_ATL_NO_COM
2928+
2929+#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
2930+ int GetItemText(int nItem, int nSubItem, _CSTRING_NS::CString& strText) const
2931+ {
2932+ ATLASSERT(::IsWindow(m_hWnd));
2933+ LVITEM lvi = { 0 };
2934+ lvi.iSubItem = nSubItem;
2935+
2936+ strText.Empty();
2937+ int nRes = 0;
2938+ for(int nLen = 256; ; nLen *= 2)
2939+ {
2940+ lvi.cchTextMax = nLen;
2941+ lvi.pszText = strText.GetBufferSetLength(nLen);
2942+ if(lvi.pszText == NULL)
2943+ {
2944+ nRes = 0;
2945+ break;
2946+ }
2947+ nRes = (int)::SendMessage(m_hWnd, LVM_GETITEMTEXT, (WPARAM)nItem, (LPARAM)&lvi);
2948+ if(nRes < nLen - 1)
2949+ break;
2950+ }
2951+ strText.ReleaseBuffer();
2952+ return nRes;
2953+ }
2954+#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
2955+
2956+ int GetItemText(int nItem, int nSubItem, LPTSTR lpszText, int nLen) const
2957+ {
2958+ ATLASSERT(::IsWindow(m_hWnd));
2959+ LVITEM lvi = { 0 };
2960+ lvi.iSubItem = nSubItem;
2961+ lvi.cchTextMax = nLen;
2962+ lvi.pszText = lpszText;
2963+ return (int)::SendMessage(m_hWnd, LVM_GETITEMTEXT, (WPARAM)nItem, (LPARAM)&lvi);
2964+ }
2965+
2966+ BOOL SetItemText(int nItem, int nSubItem, LPCTSTR lpszText)
2967+ {
2968+ ATLASSERT(::IsWindow(m_hWnd));
2969+ return SetItem(nItem, nSubItem, LVIF_TEXT, lpszText, 0, 0, 0, 0);
2970+ }
2971+
2972+ DWORD_PTR GetItemData(int nItem) const
2973+ {
2974+ ATLASSERT(::IsWindow(m_hWnd));
2975+ LVITEM lvi = { 0 };
2976+ lvi.iItem = nItem;
2977+ lvi.mask = LVIF_PARAM;
2978+ BOOL bRet = (BOOL)::SendMessage(m_hWnd, LVM_GETITEM, 0, (LPARAM)&lvi);
2979+ return (DWORD_PTR)(bRet ? lvi.lParam : NULL);
2980+ }
2981+
2982+ BOOL SetItemData(int nItem, DWORD_PTR dwData)
2983+ {
2984+ ATLASSERT(::IsWindow(m_hWnd));
2985+ return SetItem(nItem, 0, LVIF_PARAM, NULL, 0, 0, 0, (LPARAM)dwData);
2986+ }
2987+
2988+ UINT GetCallbackMask() const
2989+ {
2990+ ATLASSERT(::IsWindow(m_hWnd));
2991+ return (UINT)::SendMessage(m_hWnd, LVM_GETCALLBACKMASK, 0, 0L);
2992+ }
2993+
2994+ BOOL SetCallbackMask(UINT nMask)
2995+ {
2996+ ATLASSERT(::IsWindow(m_hWnd));
2997+ return (BOOL)::SendMessage(m_hWnd, LVM_SETCALLBACKMASK, nMask, 0L);
2998+ }
2999+
3000+ BOOL GetItemPosition(int nItem, LPPOINT lpPoint) const
3001+ {
3002+ ATLASSERT(::IsWindow(m_hWnd));
3003+ return (BOOL)::SendMessage(m_hWnd, LVM_GETITEMPOSITION, nItem, (LPARAM)lpPoint);
3004+ }
3005+
3006+ BOOL SetItemPosition(int nItem, POINT pt)
3007+ {
3008+ ATLASSERT(::IsWindow(m_hWnd));
3009+ ATLASSERT(((GetStyle() & LVS_TYPEMASK) == LVS_ICON) || ((GetStyle() & LVS_TYPEMASK) == LVS_SMALLICON));
3010+ return (BOOL)::SendMessage(m_hWnd, LVM_SETITEMPOSITION32, nItem, (LPARAM)&pt);
3011+ }
3012+
3013+ BOOL SetItemPosition(int nItem, int x, int y)
3014+ {
3015+ ATLASSERT(::IsWindow(m_hWnd));
3016+ ATLASSERT(((GetStyle() & LVS_TYPEMASK) == LVS_ICON) || ((GetStyle() & LVS_TYPEMASK) == LVS_SMALLICON));
3017+ POINT pt = { x, y };
3018+ return (BOOL)::SendMessage(m_hWnd, LVM_SETITEMPOSITION32, nItem, (LPARAM)&pt);
3019+ }
3020+
3021+ int GetStringWidth(LPCTSTR lpsz) const
3022+ {
3023+ ATLASSERT(::IsWindow(m_hWnd));
3024+ return (int)::SendMessage(m_hWnd, LVM_GETSTRINGWIDTH, 0, (LPARAM)lpsz);
3025+ }
3026+
3027+ CEdit GetEditControl() const
3028+ {
3029+ ATLASSERT(::IsWindow(m_hWnd));
3030+ return CEdit((HWND)::SendMessage(m_hWnd, LVM_GETEDITCONTROL, 0, 0L));
3031+ }
3032+
3033+ BOOL GetColumn(int nCol, LVCOLUMN* pColumn) const
3034+ {
3035+ ATLASSERT(::IsWindow(m_hWnd));
3036+ return (BOOL)::SendMessage(m_hWnd, LVM_GETCOLUMN, nCol, (LPARAM)pColumn);
3037+ }
3038+
3039+ BOOL SetColumn(int nCol, const LVCOLUMN* pColumn)
3040+ {
3041+ ATLASSERT(::IsWindow(m_hWnd));
3042+ return (BOOL)::SendMessage(m_hWnd, LVM_SETCOLUMN, nCol, (LPARAM)pColumn);
3043+ }
3044+
3045+ int GetColumnWidth(int nCol) const
3046+ {
3047+ ATLASSERT(::IsWindow(m_hWnd));
3048+ return (int)::SendMessage(m_hWnd, LVM_GETCOLUMNWIDTH, nCol, 0L);
3049+ }
3050+
3051+ BOOL SetColumnWidth(int nCol, int cx)
3052+ {
3053+ ATLASSERT(::IsWindow(m_hWnd));
3054+ return (BOOL)::SendMessage(m_hWnd, LVM_SETCOLUMNWIDTH, nCol, MAKELPARAM(cx, 0));
3055+ }
3056+
3057+ BOOL GetViewRect(LPRECT lpRect) const
3058+ {
3059+ ATLASSERT(::IsWindow(m_hWnd));
3060+ return (BOOL)::SendMessage(m_hWnd, LVM_GETVIEWRECT, 0, (LPARAM)lpRect);
3061+ }
3062+
3063+ COLORREF GetTextColor() const
3064+ {
3065+ ATLASSERT(::IsWindow(m_hWnd));
3066+ return (COLORREF)::SendMessage(m_hWnd, LVM_GETTEXTCOLOR, 0, 0L);
3067+ }
3068+
3069+ BOOL SetTextColor(COLORREF cr)
3070+ {
3071+ ATLASSERT(::IsWindow(m_hWnd));
3072+ return (BOOL)::SendMessage(m_hWnd, LVM_SETTEXTCOLOR, 0, cr);
3073+ }
3074+
3075+ COLORREF GetTextBkColor() const
3076+ {
3077+ ATLASSERT(::IsWindow(m_hWnd));
3078+ return (COLORREF)::SendMessage(m_hWnd, LVM_GETTEXTBKCOLOR, 0, 0L);
3079+ }
3080+
3081+ BOOL SetTextBkColor(COLORREF cr)
3082+ {
3083+ ATLASSERT(::IsWindow(m_hWnd));
3084+ return (BOOL)::SendMessage(m_hWnd, LVM_SETTEXTBKCOLOR, 0, cr);
3085+ }
3086+
3087+ int GetTopIndex() const
3088+ {
3089+ ATLASSERT(::IsWindow(m_hWnd));
3090+ return (int)::SendMessage(m_hWnd, LVM_GETTOPINDEX, 0, 0L);
3091+ }
3092+
3093+ int GetCountPerPage() const
3094+ {
3095+ ATLASSERT(::IsWindow(m_hWnd));
3096+ return (int)::SendMessage(m_hWnd, LVM_GETCOUNTPERPAGE, 0, 0L);
3097+ }
3098+
3099+ BOOL GetOrigin(LPPOINT lpPoint) const
3100+ {
3101+ ATLASSERT(::IsWindow(m_hWnd));
3102+ return (BOOL)::SendMessage(m_hWnd, LVM_GETORIGIN, 0, (LPARAM)lpPoint);
3103+ }
3104+
3105+ UINT GetSelectedCount() const
3106+ {
3107+ ATLASSERT(::IsWindow(m_hWnd));
3108+ return (UINT)::SendMessage(m_hWnd, LVM_GETSELECTEDCOUNT, 0, 0L);
3109+ }
3110+
3111+ BOOL GetItemRect(int nItem, LPRECT lpRect, UINT nCode) const
3112+ {
3113+ ATLASSERT(::IsWindow(m_hWnd));
3114+ lpRect->left = nCode;
3115+ return (BOOL)::SendMessage(m_hWnd, LVM_GETITEMRECT, (WPARAM)nItem, (LPARAM)lpRect);
3116+ }
3117+
3118+#ifndef _WIN32_WCE
3119+ HCURSOR GetHotCursor() const
3120+ {
3121+ ATLASSERT(::IsWindow(m_hWnd));
3122+ return (HCURSOR)::SendMessage(m_hWnd, LVM_GETHOTCURSOR, 0, 0L);
3123+ }
3124+
3125+ HCURSOR SetHotCursor(HCURSOR hHotCursor)
3126+ {
3127+ ATLASSERT(::IsWindow(m_hWnd));
3128+ return (HCURSOR)::SendMessage(m_hWnd, LVM_SETHOTCURSOR, 0, (LPARAM)hHotCursor);
3129+ }
3130+
3131+ int GetHotItem() const
3132+ {
3133+ ATLASSERT(::IsWindow(m_hWnd));
3134+ return (int)::SendMessage(m_hWnd, LVM_GETHOTITEM, 0, 0L);
3135+ }
3136+
3137+ int SetHotItem(int nIndex)
3138+ {
3139+ ATLASSERT(::IsWindow(m_hWnd));
3140+ return (int)::SendMessage(m_hWnd, LVM_SETHOTITEM, nIndex, 0L);
3141+ }
3142+#endif // !_WIN32_WCE
3143+
3144+ BOOL GetColumnOrderArray(int nCount, int* lpnArray) const
3145+ {
3146+ ATLASSERT(::IsWindow(m_hWnd));
3147+ return (BOOL)::SendMessage(m_hWnd, LVM_GETCOLUMNORDERARRAY, nCount, (LPARAM)lpnArray);
3148+ }
3149+
3150+ BOOL SetColumnOrderArray(int nCount, int* lpnArray)
3151+ {
3152+ ATLASSERT(::IsWindow(m_hWnd));
3153+ return (BOOL)::SendMessage(m_hWnd, LVM_SETCOLUMNORDERARRAY, nCount, (LPARAM)lpnArray);
3154+ }
3155+
3156+ CHeaderCtrl GetHeader() const
3157+ {
3158+ ATLASSERT(::IsWindow(m_hWnd));
3159+ return CHeaderCtrl((HWND)::SendMessage(m_hWnd, LVM_GETHEADER, 0, 0L));
3160+ }
3161+
3162+ BOOL GetSubItemRect(int nItem, int nSubItem, int nFlag, LPRECT lpRect) const
3163+ {
3164+ ATLASSERT(::IsWindow(m_hWnd));
3165+ ATLASSERT((GetStyle() & LVS_TYPEMASK) == LVS_REPORT);
3166+ ATLASSERT(lpRect != NULL);
3167+ lpRect->top = nSubItem;
3168+ lpRect->left = nFlag;
3169+ return (BOOL)::SendMessage(m_hWnd, LVM_GETSUBITEMRECT, nItem, (LPARAM)lpRect);
3170+ }
3171+
3172+ DWORD SetIconSpacing(int cx, int cy)
3173+ {
3174+ ATLASSERT(::IsWindow(m_hWnd));
3175+ ATLASSERT((GetStyle() & LVS_TYPEMASK) == LVS_ICON);
3176+ return (DWORD)::SendMessage(m_hWnd, LVM_SETICONSPACING, 0, MAKELPARAM(cx, cy));
3177+ }
3178+
3179+ int GetISearchString(LPTSTR lpstr) const
3180+ {
3181+ ATLASSERT(::IsWindow(m_hWnd));
3182+ return (int)::SendMessage(m_hWnd, LVM_GETISEARCHSTRING, 0, (LPARAM)lpstr);
3183+ }
3184+
3185+ void GetItemSpacing(SIZE& sizeSpacing, BOOL bSmallIconView = FALSE) const
3186+ {
3187+ ATLASSERT(::IsWindow(m_hWnd));
3188+ DWORD dwRet = (DWORD)::SendMessage(m_hWnd, LVM_GETITEMSPACING, bSmallIconView, 0L);
3189+ sizeSpacing.cx = GET_X_LPARAM(dwRet);
3190+ sizeSpacing.cy = GET_Y_LPARAM(dwRet);
3191+ }
3192+
3193+#if (_WIN32_WCE >= 410)
3194+ void SetItemSpacing(INT cySpacing)
3195+ {
3196+ ATLASSERT(::IsWindow(m_hWnd));
3197+ ListView_SetItemSpacing(m_hWnd, cySpacing);
3198+ }
3199+#endif // (_WIN32_WCE >= 410)
3200+
3201+ // single-selection only
3202+ int GetSelectedIndex() const
3203+ {
3204+ ATLASSERT(::IsWindow(m_hWnd));
3205+ ATLASSERT((GetStyle() & LVS_SINGLESEL) != 0);
3206+ return (int)::SendMessage(m_hWnd, LVM_GETNEXTITEM, (WPARAM)-1, MAKELPARAM(LVNI_ALL | LVNI_SELECTED, 0));
3207+ }
3208+
3209+ BOOL GetSelectedItem(LPLVITEM pItem) const
3210+ {
3211+ ATLASSERT(::IsWindow(m_hWnd));
3212+ ATLASSERT((GetStyle() & LVS_SINGLESEL) != 0);
3213+ ATLASSERT(pItem != NULL);
3214+ pItem->iItem = (int)::SendMessage(m_hWnd, LVM_GETNEXTITEM, (WPARAM)-1, MAKELPARAM(LVNI_ALL | LVNI_SELECTED, 0));
3215+ if(pItem->iItem == -1)
3216+ return FALSE;
3217+ return (BOOL)::SendMessage(m_hWnd, LVM_GETITEM, 0, (LPARAM)pItem);
3218+ }
3219+
3220+ // extended list view styles
3221+ DWORD GetExtendedListViewStyle() const
3222+ {
3223+ ATLASSERT(::IsWindow(m_hWnd));
3224+ return (DWORD)::SendMessage(m_hWnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0L);
3225+ }
3226+
3227+ // dwExMask = 0 means all styles
3228+ DWORD SetExtendedListViewStyle(DWORD dwExStyle, DWORD dwExMask = 0)
3229+ {
3230+ ATLASSERT(::IsWindow(m_hWnd));
3231+ return (DWORD)::SendMessage(m_hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, dwExMask, dwExStyle);
3232+ }
3233+
3234+ // checkboxes only
3235+ BOOL GetCheckState(int nIndex) const
3236+ {
3237+ ATLASSERT(::IsWindow(m_hWnd));
3238+ ATLASSERT((GetExtendedListViewStyle() & LVS_EX_CHECKBOXES) != 0);
3239+ UINT uRet = GetItemState(nIndex, LVIS_STATEIMAGEMASK);
3240+ return (uRet >> 12) - 1;
3241+ }
3242+
3243+ BOOL SetCheckState(int nItem, BOOL bCheck)
3244+ {
3245+ int nCheck = bCheck ? 2 : 1; // one based index
3246+ return SetItemState(nItem, INDEXTOSTATEIMAGEMASK(nCheck), LVIS_STATEIMAGEMASK);
3247+ }
3248+
3249+ // view type
3250+ DWORD GetViewType() const
3251+ {
3252+ ATLASSERT(::IsWindow(m_hWnd));
3253+ return (GetStyle() & LVS_TYPEMASK);
3254+ }
3255+
3256+ DWORD SetViewType(DWORD dwType)
3257+ {
3258+ ATLASSERT(::IsWindow(m_hWnd));
3259+ ATLASSERT(dwType == LVS_ICON || dwType == LVS_SMALLICON || dwType == LVS_LIST || dwType == LVS_REPORT);
3260+ DWORD dwOldType = GetViewType();
3261+ if(dwType != dwOldType)
3262+ ModifyStyle(LVS_TYPEMASK, (dwType & LVS_TYPEMASK));
3263+ return dwOldType;
3264+ }
3265+
3266+#if (_WIN32_IE >= 0x0400)
3267+#ifndef _WIN32_WCE
3268+ BOOL GetBkImage(LPLVBKIMAGE plvbki) const
3269+ {
3270+ ATLASSERT(::IsWindow(m_hWnd));
3271+ return (BOOL)::SendMessage(m_hWnd, LVM_GETBKIMAGE, 0, (LPARAM)plvbki);
3272+ }
3273+
3274+ BOOL SetBkImage(LPLVBKIMAGE plvbki)
3275+ {
3276+ ATLASSERT(::IsWindow(m_hWnd));
3277+ return (BOOL)::SendMessage(m_hWnd, LVM_SETBKIMAGE, 0, (LPARAM)plvbki);
3278+ }
3279+#endif // !_WIN32_WCE
3280+
3281+ int GetSelectionMark() const
3282+ {
3283+ ATLASSERT(::IsWindow(m_hWnd));
3284+ return (int)::SendMessage(m_hWnd, LVM_GETSELECTIONMARK, 0, 0L);
3285+ }
3286+
3287+ int SetSelectionMark(int nIndex)
3288+ {
3289+ ATLASSERT(::IsWindow(m_hWnd));
3290+ return (int)::SendMessage(m_hWnd, LVM_SETSELECTIONMARK, 0, nIndex);
3291+ }
3292+
3293+#ifndef _WIN32_WCE
3294+ BOOL GetWorkAreas(int nWorkAreas, LPRECT lpRect) const
3295+ {
3296+ ATLASSERT(::IsWindow(m_hWnd));
3297+ return (BOOL)::SendMessage(m_hWnd, LVM_GETWORKAREAS, nWorkAreas, (LPARAM)lpRect);
3298+ }
3299+
3300+ BOOL SetWorkAreas(int nWorkAreas, LPRECT lpRect)
3301+ {
3302+ ATLASSERT(::IsWindow(m_hWnd));
3303+ return (BOOL)::SendMessage(m_hWnd, LVM_SETWORKAREAS, nWorkAreas, (LPARAM)lpRect);
3304+ }
3305+
3306+ DWORD GetHoverTime() const
3307+ {
3308+ ATLASSERT(::IsWindow(m_hWnd));
3309+ ATLASSERT((GetExtendedListViewStyle() & (LVS_EX_TRACKSELECT | LVS_EX_ONECLICKACTIVATE | LVS_EX_TWOCLICKACTIVATE)) != 0);
3310+ return (DWORD)::SendMessage(m_hWnd, LVM_GETHOVERTIME, 0, 0L);
3311+ }
3312+
3313+ DWORD SetHoverTime(DWORD dwHoverTime)
3314+ {
3315+ ATLASSERT(::IsWindow(m_hWnd));
3316+ ATLASSERT((GetExtendedListViewStyle() & (LVS_EX_TRACKSELECT | LVS_EX_ONECLICKACTIVATE | LVS_EX_TWOCLICKACTIVATE)) != 0);
3317+ return (DWORD)::SendMessage(m_hWnd, LVM_SETHOVERTIME, 0, dwHoverTime);
3318+ }
3319+
3320+ BOOL GetNumberOfWorkAreas(int* pnWorkAreas) const
3321+ {
3322+ ATLASSERT(::IsWindow(m_hWnd));
3323+ return (BOOL)::SendMessage(m_hWnd, LVM_GETNUMBEROFWORKAREAS, 0, (LPARAM)pnWorkAreas);
3324+ }
3325+#endif // !_WIN32_WCE
3326+
3327+ BOOL SetItemCountEx(int nItems, DWORD dwFlags)
3328+ {
3329+ ATLASSERT(::IsWindow(m_hWnd));
3330+ ATLASSERT(((GetStyle() & LVS_OWNERDATA) != 0) && (((GetStyle() & LVS_TYPEMASK) == LVS_REPORT) || ((GetStyle() & LVS_TYPEMASK) == LVS_LIST)));
3331+ return (BOOL)::SendMessage(m_hWnd, LVM_SETITEMCOUNT, nItems, dwFlags);
3332+ }
3333+
3334+#ifndef _WIN32_WCE
3335+ CToolTipCtrl GetToolTips() const
3336+ {
3337+ ATLASSERT(::IsWindow(m_hWnd));
3338+ return CToolTipCtrl((HWND)::SendMessage(m_hWnd, LVM_GETTOOLTIPS, 0, 0L));
3339+ }
3340+
3341+ CToolTipCtrl SetToolTips(HWND hWndTT)
3342+ {
3343+ ATLASSERT(::IsWindow(m_hWnd));
3344+ return CToolTipCtrl((HWND)::SendMessage(m_hWnd, LVM_SETTOOLTIPS, (WPARAM)hWndTT, 0L));
3345+ }
3346+
3347+ BOOL GetUnicodeFormat() const
3348+ {
3349+ ATLASSERT(::IsWindow(m_hWnd));
3350+ return (BOOL)::SendMessage(m_hWnd, LVM_GETUNICODEFORMAT, 0, 0L);
3351+ }
3352+
3353+ BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
3354+ {
3355+ ATLASSERT(::IsWindow(m_hWnd));
3356+ return (BOOL)::SendMessage(m_hWnd, LVM_SETUNICODEFORMAT, bUnicode, 0L);
3357+ }
3358+#endif // !_WIN32_WCE
3359+#endif // (_WIN32_IE >= 0x0400)
3360+
3361+#if (_WIN32_WINNT >= 0x0501)
3362+ int GetSelectedColumn() const
3363+ {
3364+ ATLASSERT(::IsWindow(m_hWnd));
3365+ return (int)::SendMessage(m_hWnd, LVM_GETSELECTEDCOLUMN, 0, 0L);
3366+ }
3367+
3368+ void SetSelectedColumn(int nColumn)
3369+ {
3370+ ATLASSERT(::IsWindow(m_hWnd));
3371+ ::SendMessage(m_hWnd, LVM_SETSELECTEDCOLUMN, nColumn, 0L);
3372+ }
3373+
3374+ DWORD GetView() const
3375+ {
3376+ ATLASSERT(::IsWindow(m_hWnd));
3377+ return (DWORD)::SendMessage(m_hWnd, LVM_GETVIEW, 0, 0L);
3378+ }
3379+
3380+ int SetView(DWORD dwView)
3381+ {
3382+ ATLASSERT(::IsWindow(m_hWnd));
3383+ return (int)::SendMessage(m_hWnd, LVM_SETVIEW, dwView, 0L);
3384+ }
3385+
3386+ BOOL IsGroupViewEnabled() const
3387+ {
3388+ ATLASSERT(::IsWindow(m_hWnd));
3389+ return (BOOL)::SendMessage(m_hWnd, LVM_ISGROUPVIEWENABLED, 0, 0L);
3390+ }
3391+
3392+ int GetGroupInfo(int nGroupID, PLVGROUP pGroup) const
3393+ {
3394+ ATLASSERT(::IsWindow(m_hWnd));
3395+ return (int)::SendMessage(m_hWnd, LVM_GETGROUPINFO, nGroupID, (LPARAM)pGroup);
3396+ }
3397+
3398+ int SetGroupInfo(int nGroupID, PLVGROUP pGroup)
3399+ {
3400+ ATLASSERT(::IsWindow(m_hWnd));
3401+ return (int)::SendMessage(m_hWnd, LVM_SETGROUPINFO, nGroupID, (LPARAM)pGroup);
3402+ }
3403+
3404+ void GetGroupMetrics(PLVGROUPMETRICS pGroupMetrics) const
3405+ {
3406+ ATLASSERT(::IsWindow(m_hWnd));
3407+ ::SendMessage(m_hWnd, LVM_GETGROUPMETRICS, 0, (LPARAM)pGroupMetrics);
3408+ }
3409+
3410+ void SetGroupMetrics(PLVGROUPMETRICS pGroupMetrics)
3411+ {
3412+ ATLASSERT(::IsWindow(m_hWnd));
3413+ ::SendMessage(m_hWnd, LVM_SETGROUPMETRICS, 0, (LPARAM)pGroupMetrics);
3414+ }
3415+
3416+ void GetTileViewInfo(PLVTILEVIEWINFO pTileViewInfo) const
3417+ {
3418+ ATLASSERT(::IsWindow(m_hWnd));
3419+ ::SendMessage(m_hWnd, LVM_GETTILEVIEWINFO, 0, (LPARAM)pTileViewInfo);
3420+ }
3421+
3422+ BOOL SetTileViewInfo(PLVTILEVIEWINFO pTileViewInfo)
3423+ {
3424+ ATLASSERT(::IsWindow(m_hWnd));
3425+ return (BOOL)::SendMessage(m_hWnd, LVM_SETTILEVIEWINFO, 0, (LPARAM)pTileViewInfo);
3426+ }
3427+
3428+ void GetTileInfo(PLVTILEINFO pTileInfo) const
3429+ {
3430+ ATLASSERT(::IsWindow(m_hWnd));
3431+ ::SendMessage(m_hWnd, LVM_GETTILEINFO, 0, (LPARAM)pTileInfo);
3432+ }
3433+
3434+ BOOL SetTileInfo(PLVTILEINFO pTileInfo)
3435+ {
3436+ ATLASSERT(::IsWindow(m_hWnd));
3437+ return (BOOL)::SendMessage(m_hWnd, LVM_SETTILEINFO, 0, (LPARAM)pTileInfo);
3438+ }
3439+
3440+ BOOL GetInsertMark(LPLVINSERTMARK pInsertMark) const
3441+ {
3442+ ATLASSERT(::IsWindow(m_hWnd));
3443+ return (BOOL)::SendMessage(m_hWnd, LVM_GETINSERTMARK, 0, (LPARAM)pInsertMark);
3444+ }
3445+
3446+ BOOL SetInsertMark(LPLVINSERTMARK pInsertMark)
3447+ {
3448+ ATLASSERT(::IsWindow(m_hWnd));
3449+ return (BOOL)::SendMessage(m_hWnd, LVM_SETINSERTMARK, 0, (LPARAM)pInsertMark);
3450+ }
3451+
3452+ int GetInsertMarkRect(LPRECT lpRect) const
3453+ {
3454+ ATLASSERT(::IsWindow(m_hWnd));
3455+ return (int)::SendMessage(m_hWnd, LVM_GETINSERTMARKRECT, 0, (LPARAM)lpRect);
3456+ }
3457+
3458+ COLORREF GetInsertMarkColor() const
3459+ {
3460+ ATLASSERT(::IsWindow(m_hWnd));
3461+ return (COLORREF)::SendMessage(m_hWnd, LVM_GETINSERTMARKCOLOR, 0, 0L);
3462+ }
3463+
3464+ COLORREF SetInsertMarkColor(COLORREF clr)
3465+ {
3466+ ATLASSERT(::IsWindow(m_hWnd));
3467+ return (COLORREF)::SendMessage(m_hWnd, LVM_SETINSERTMARKCOLOR, 0, clr);
3468+ }
3469+
3470+ COLORREF GetOutlineColor() const
3471+ {
3472+ ATLASSERT(::IsWindow(m_hWnd));
3473+ return (COLORREF)::SendMessage(m_hWnd, LVM_GETOUTLINECOLOR, 0, 0L);
3474+ }
3475+
3476+ COLORREF SetOutlineColor(COLORREF clr)
3477+ {
3478+ ATLASSERT(::IsWindow(m_hWnd));
3479+ return (COLORREF)::SendMessage(m_hWnd, LVM_SETOUTLINECOLOR, 0, clr);
3480+ }
3481+#endif // (_WIN32_WINNT >= 0x0501)
3482+
3483+#if (_WIN32_WINNT >= 0x0600)
3484+ int GetGroupCount() const
3485+ {
3486+ ATLASSERT(::IsWindow(m_hWnd));
3487+ return (int)::SendMessage(m_hWnd, LVM_GETGROUPCOUNT, 0, 0L);
3488+ }
3489+
3490+ BOOL GetGroupInfoByIndex(int nIndex, PLVGROUP pGroup) const
3491+ {
3492+ ATLASSERT(::IsWindow(m_hWnd));
3493+ return (BOOL)::SendMessage(m_hWnd, LVM_GETGROUPINFOBYINDEX, nIndex, (LPARAM)pGroup);
3494+ }
3495+
3496+ BOOL GetGroupRect(int nGroupID, int nType, LPRECT lpRect) const
3497+ {
3498+ ATLASSERT(::IsWindow(m_hWnd));
3499+ ATLASSERT(lpRect != NULL);
3500+ if(lpRect != NULL)
3501+ lpRect->top = nType;
3502+ return (BOOL)::SendMessage(m_hWnd, LVM_GETGROUPRECT, nGroupID, (LPARAM)lpRect);
3503+ }
3504+
3505+ UINT GetGroupState(int nGroupID, UINT uMask) const
3506+ {
3507+ ATLASSERT(::IsWindow(m_hWnd));
3508+ return (UINT)::SendMessage(m_hWnd, LVM_GETGROUPSTATE, nGroupID, (LPARAM)uMask);
3509+ }
3510+
3511+ int GetFocusedGroup() const
3512+ {
3513+ ATLASSERT(::IsWindow(m_hWnd));
3514+ return (int)::SendMessage(m_hWnd, LVM_GETFOCUSEDGROUP, 0, 0L);
3515+ }
3516+
3517+ BOOL GetEmptyText(LPWSTR lpstrText, int cchText) const
3518+ {
3519+ ATLASSERT(::IsWindow(m_hWnd));
3520+ return (BOOL)::SendMessage(m_hWnd, LVM_GETEMPTYTEXT, cchText, (LPARAM)lpstrText);
3521+ }
3522+
3523+ BOOL GetFooterRect(LPRECT lpRect) const
3524+ {
3525+ ATLASSERT(::IsWindow(m_hWnd));
3526+ return (BOOL)::SendMessage(m_hWnd, LVM_GETFOOTERRECT, 0, (LPARAM)lpRect);
3527+ }
3528+
3529+ BOOL GetFooterInfo(LPLVFOOTERINFO lpFooterInfo) const
3530+ {
3531+ ATLASSERT(::IsWindow(m_hWnd));
3532+ return (BOOL)::SendMessage(m_hWnd, LVM_GETFOOTERINFO, 0, (LPARAM)lpFooterInfo);
3533+ }
3534+
3535+ BOOL GetFooterItemRect(int nItem, LPRECT lpRect) const
3536+ {
3537+ ATLASSERT(::IsWindow(m_hWnd));
3538+ return (BOOL)::SendMessage(m_hWnd, LVM_GETFOOTERITEMRECT, nItem, (LPARAM)lpRect);
3539+ }
3540+
3541+ BOOL GetFooterItem(int nItem, LPLVFOOTERITEM lpFooterItem) const
3542+ {
3543+ ATLASSERT(::IsWindow(m_hWnd));
3544+ return (BOOL)::SendMessage(m_hWnd, LVM_GETFOOTERITEM, nItem, (LPARAM)lpFooterItem);
3545+ }
3546+
3547+ BOOL GetItemIndexRect(PLVITEMINDEX pItemIndex, int nSubItem, int nType, LPRECT lpRect) const
3548+ {
3549+ ATLASSERT(::IsWindow(m_hWnd));
3550+ ATLASSERT(pItemIndex != NULL);
3551+ ATLASSERT(lpRect != NULL);
3552+ if(lpRect != NULL)
3553+ {
3554+ lpRect->top = nSubItem;
3555+ lpRect->left = nType;
3556+ }
3557+ return (BOOL)::SendMessage(m_hWnd, LVM_GETITEMINDEXRECT, (WPARAM)pItemIndex, (LPARAM)lpRect);
3558+ }
3559+
3560+ BOOL SetItemIndexState(PLVITEMINDEX pItemIndex, UINT uState, UINT dwMask)
3561+ {
3562+ ATLASSERT(::IsWindow(m_hWnd));
3563+ LVITEM lvi = { 0 };
3564+ lvi.state = uState;
3565+ lvi.stateMask = dwMask;
3566+ return (BOOL)::SendMessage(m_hWnd, LVM_SETITEMINDEXSTATE, (WPARAM)pItemIndex, (LPARAM)&lvi);
3567+ }
3568+
3569+ BOOL GetNextItemIndex(PLVITEMINDEX pItemIndex, WORD wFlags) const
3570+ {
3571+ ATLASSERT(::IsWindow(m_hWnd));
3572+ return (BOOL)::SendMessage(m_hWnd, LVM_GETNEXTITEMINDEX, (WPARAM)pItemIndex, MAKELPARAM(wFlags, 0));
3573+ }
3574+#endif // (_WIN32_WINNT >= 0x0600)
3575+
3576+// Operations
3577+ int InsertColumn(int nCol, const LVCOLUMN* pColumn)
3578+ {
3579+ ATLASSERT(::IsWindow(m_hWnd));
3580+ return (int)::SendMessage(m_hWnd, LVM_INSERTCOLUMN, nCol, (LPARAM)pColumn);
3581+ }
3582+
3583+ int InsertColumn(int nCol, LPCTSTR lpszColumnHeading, int nFormat = LVCFMT_LEFT,
3584+ int nWidth = -1, int nSubItem = -1, int iImage = -1, int iOrder = -1)
3585+ {
3586+ LVCOLUMN column = { 0 };
3587+ column.mask = LVCF_TEXT|LVCF_FMT;
3588+ column.pszText = (LPTSTR)lpszColumnHeading;
3589+ column.fmt = nFormat;
3590+ if (nWidth != -1)
3591+ {
3592+ column.mask |= LVCF_WIDTH;
3593+ column.cx = nWidth;
3594+ }
3595+ if (nSubItem != -1)
3596+ {
3597+ column.mask |= LVCF_SUBITEM;
3598+ column.iSubItem = nSubItem;
3599+ }
3600+ if (iImage != -1)
3601+ {
3602+ column.mask |= LVCF_IMAGE;
3603+ column.iImage = iImage;
3604+ }
3605+ if (iOrder != -1)
3606+ {
3607+ column.mask |= LVCF_ORDER;
3608+ column.iOrder = iOrder;
3609+ }
3610+ return InsertColumn(nCol, &column);
3611+ }
3612+
3613+ BOOL DeleteColumn(int nCol)
3614+ {
3615+ ATLASSERT(::IsWindow(m_hWnd));
3616+ return (BOOL)::SendMessage(m_hWnd, LVM_DELETECOLUMN, nCol, 0L);
3617+ }
3618+
3619+ int InsertItem(UINT nMask, int nItem, LPCTSTR lpszItem, UINT nState, UINT nStateMask, int nImage, LPARAM lParam)
3620+ {
3621+ ATLASSERT(::IsWindow(m_hWnd));
3622+ LVITEM item = { 0 };
3623+ item.mask = nMask;
3624+ item.iItem = nItem;
3625+ item.iSubItem = 0;
3626+ item.pszText = (LPTSTR)lpszItem;
3627+ item.state = nState;
3628+ item.stateMask = nStateMask;
3629+ item.iImage = nImage;
3630+ item.lParam = lParam;
3631+ return InsertItem(&item);
3632+ }
3633+
3634+ int InsertItem(const LVITEM* pItem)
3635+ {
3636+ ATLASSERT(::IsWindow(m_hWnd));
3637+ return (int)::SendMessage(m_hWnd, LVM_INSERTITEM, 0, (LPARAM)pItem);
3638+ }
3639+
3640+ int InsertItem(int nItem, LPCTSTR lpszItem)
3641+ {
3642+ ATLASSERT(::IsWindow(m_hWnd));
3643+ return InsertItem(LVIF_TEXT, nItem, lpszItem, 0, 0, 0, 0);
3644+ }
3645+
3646+ int InsertItem(int nItem, LPCTSTR lpszItem, int nImage)
3647+ {
3648+ ATLASSERT(::IsWindow(m_hWnd));
3649+ return InsertItem(LVIF_TEXT|LVIF_IMAGE, nItem, lpszItem, 0, 0, nImage, 0);
3650+ }
3651+
3652+ int GetNextItem(int nItem, int nFlags) const
3653+ {
3654+ ATLASSERT(::IsWindow(m_hWnd));
3655+ return (int)::SendMessage(m_hWnd, LVM_GETNEXTITEM, nItem, MAKELPARAM(nFlags, 0));
3656+ }
3657+
3658+ BOOL DeleteItem(int nItem)
3659+ {
3660+ ATLASSERT(::IsWindow(m_hWnd));
3661+ return (BOOL)::SendMessage(m_hWnd, LVM_DELETEITEM, nItem, 0L);
3662+ }
3663+
3664+ BOOL DeleteAllItems()
3665+ {
3666+ ATLASSERT(::IsWindow(m_hWnd));
3667+ return (BOOL)::SendMessage(m_hWnd, LVM_DELETEALLITEMS, 0, 0L);
3668+ }
3669+
3670+ int FindItem(LVFINDINFO* pFindInfo, int nStart) const
3671+ {
3672+ ATLASSERT(::IsWindow(m_hWnd));
3673+ return (int)::SendMessage(m_hWnd, LVM_FINDITEM, nStart, (LPARAM)pFindInfo);
3674+ }
3675+
3676+ int HitTest(LVHITTESTINFO* pHitTestInfo) const
3677+ {
3678+ ATLASSERT(::IsWindow(m_hWnd));
3679+ return (int)::SendMessage(m_hWnd, LVM_HITTEST, 0, (LPARAM)pHitTestInfo);
3680+ }
3681+
3682+ int HitTest(POINT pt, UINT* pFlags) const
3683+ {
3684+ ATLASSERT(::IsWindow(m_hWnd));
3685+ LVHITTESTINFO hti = { 0 };
3686+ hti.pt = pt;
3687+ int nRes = (int)::SendMessage(m_hWnd, LVM_HITTEST, 0, (LPARAM)&hti);
3688+ if (pFlags != NULL)
3689+ *pFlags = hti.flags;
3690+ return nRes;
3691+ }
3692+
3693+ BOOL EnsureVisible(int nItem, BOOL bPartialOK)
3694+ {
3695+ ATLASSERT(::IsWindow(m_hWnd));
3696+ return (BOOL)::SendMessage(m_hWnd, LVM_ENSUREVISIBLE, nItem, MAKELPARAM(bPartialOK, 0));
3697+ }
3698+
3699+ BOOL Scroll(SIZE size)
3700+ {
3701+ ATLASSERT(::IsWindow(m_hWnd));
3702+ return (BOOL)::SendMessage(m_hWnd, LVM_SCROLL, size.cx, size.cy);
3703+ }
3704+
3705+ BOOL RedrawItems(int nFirst, int nLast)
3706+ {
3707+ ATLASSERT(::IsWindow(m_hWnd));
3708+ return (BOOL)::SendMessage(m_hWnd, LVM_REDRAWITEMS, nFirst, nLast);
3709+ }
3710+
3711+ BOOL Arrange(UINT nCode)
3712+ {
3713+ ATLASSERT(::IsWindow(m_hWnd));
3714+ return (BOOL)::SendMessage(m_hWnd, LVM_ARRANGE, nCode, 0L);
3715+ }
3716+
3717+ CEdit EditLabel(int nItem)
3718+ {
3719+ ATLASSERT(::IsWindow(m_hWnd));
3720+ return CEdit((HWND)::SendMessage(m_hWnd, LVM_EDITLABEL, nItem, 0L));
3721+ }
3722+
3723+ BOOL Update(int nItem)
3724+ {
3725+ ATLASSERT(::IsWindow(m_hWnd));
3726+ return (BOOL)::SendMessage(m_hWnd, LVM_UPDATE, nItem, 0L);
3727+ }
3728+
3729+ BOOL SortItems(PFNLVCOMPARE pfnCompare, LPARAM lParamSort)
3730+ {
3731+ ATLASSERT(::IsWindow(m_hWnd));
3732+ return (BOOL)::SendMessage(m_hWnd, LVM_SORTITEMS, (WPARAM)lParamSort, (LPARAM)pfnCompare);
3733+ }
3734+
3735+ CImageList RemoveImageList(int nImageList)
3736+ {
3737+ ATLASSERT(::IsWindow(m_hWnd));
3738+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, LVM_SETIMAGELIST, (WPARAM)nImageList, NULL));
3739+ }
3740+
3741+ CImageList CreateDragImage(int nItem, LPPOINT lpPoint)
3742+ {
3743+ ATLASSERT(::IsWindow(m_hWnd));
3744+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, LVM_CREATEDRAGIMAGE, nItem, (LPARAM)lpPoint));
3745+ }
3746+
3747+ DWORD ApproximateViewRect(int cx = -1, int cy = -1, int nCount = -1)
3748+ {
3749+ ATLASSERT(::IsWindow(m_hWnd));
3750+ return (DWORD)::SendMessage(m_hWnd, LVM_APPROXIMATEVIEWRECT, nCount, MAKELPARAM(cx, cy));
3751+ }
3752+
3753+ int SubItemHitTest(LPLVHITTESTINFO lpInfo) const
3754+ {
3755+ ATLASSERT(::IsWindow(m_hWnd));
3756+ return (int)::SendMessage(m_hWnd, LVM_SUBITEMHITTEST, 0, (LPARAM)lpInfo);
3757+ }
3758+
3759+ int AddColumn(LPCTSTR strItem, int nItem, int nSubItem = -1,
3760+ int nMask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM,
3761+ int nFmt = LVCFMT_LEFT)
3762+ {
3763+ const int cxOffset = 15;
3764+ ATLASSERT(::IsWindow(m_hWnd));
3765+ LVCOLUMN lvc = { 0 };
3766+ lvc.mask = nMask;
3767+ lvc.fmt = nFmt;
3768+ lvc.pszText = (LPTSTR)strItem;
3769+ lvc.cx = GetStringWidth(lvc.pszText) + cxOffset;
3770+ if(nMask & LVCF_SUBITEM)
3771+ lvc.iSubItem = (nSubItem != -1) ? nSubItem : nItem;
3772+ return InsertColumn(nItem, &lvc);
3773+ }
3774+
3775+ int AddItem(int nItem, int nSubItem, LPCTSTR strItem, int nImageIndex = -1)
3776+ {
3777+ ATLASSERT(::IsWindow(m_hWnd));
3778+ LVITEM lvItem = { 0 };
3779+ lvItem.mask = LVIF_TEXT;
3780+ lvItem.iItem = nItem;
3781+ lvItem.iSubItem = nSubItem;
3782+ lvItem.pszText = (LPTSTR)strItem;
3783+ if(nImageIndex != -1)
3784+ {
3785+ lvItem.mask |= LVIF_IMAGE;
3786+ lvItem.iImage = nImageIndex;
3787+ }
3788+ if(nSubItem == 0)
3789+ return InsertItem(&lvItem);
3790+ return SetItem(&lvItem) ? nItem : -1;
3791+ }
3792+
3793+#if (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
3794+ BOOL SortItemsEx(PFNLVCOMPARE pfnCompare, LPARAM lParamSort)
3795+ {
3796+ ATLASSERT(::IsWindow(m_hWnd));
3797+ return (BOOL)::SendMessage(m_hWnd, LVM_SORTITEMSEX, (WPARAM)lParamSort, (LPARAM)pfnCompare);
3798+ }
3799+#endif // (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
3800+
3801+#if (_WIN32_WINNT >= 0x0501)
3802+ int InsertGroup(int nItem, PLVGROUP pGroup)
3803+ {
3804+ ATLASSERT(::IsWindow(m_hWnd));
3805+ return (int)::SendMessage(m_hWnd, LVM_INSERTGROUP, nItem, (LPARAM)pGroup);
3806+ }
3807+
3808+ int AddGroup(PLVGROUP pGroup)
3809+ {
3810+ return InsertGroup(-1, pGroup);
3811+ }
3812+
3813+ int RemoveGroup(int nGroupID)
3814+ {
3815+ ATLASSERT(::IsWindow(m_hWnd));
3816+ return (int)::SendMessage(m_hWnd, LVM_REMOVEGROUP, nGroupID, 0L);
3817+ }
3818+
3819+ void MoveGroup(int nGroupID, int nItem)
3820+ {
3821+ ATLASSERT(::IsWindow(m_hWnd));
3822+ ::SendMessage(m_hWnd, LVM_MOVEGROUP, nGroupID, nItem);
3823+ }
3824+
3825+ void MoveItemToGroup(int nItem, int nGroupID)
3826+ {
3827+ ATLASSERT(::IsWindow(m_hWnd));
3828+ ::SendMessage(m_hWnd, LVM_MOVEITEMTOGROUP, nItem, nGroupID);
3829+ }
3830+
3831+ int EnableGroupView(BOOL bEnable)
3832+ {
3833+ ATLASSERT(::IsWindow(m_hWnd));
3834+ return (int)::SendMessage(m_hWnd, LVM_ENABLEGROUPVIEW, bEnable, 0L);
3835+ }
3836+
3837+ int SortGroups(PFNLVGROUPCOMPARE pCompareFunc, LPVOID lpVoid = NULL)
3838+ {
3839+ ATLASSERT(::IsWindow(m_hWnd));
3840+ return (int)::SendMessage(m_hWnd, LVM_SORTGROUPS, (WPARAM)pCompareFunc, (LPARAM)lpVoid);
3841+ }
3842+
3843+ void InsertGroupSorted(PLVINSERTGROUPSORTED pInsertGroupSorted)
3844+ {
3845+ ATLASSERT(::IsWindow(m_hWnd));
3846+ ::SendMessage(m_hWnd, LVM_INSERTGROUPSORTED, (WPARAM)pInsertGroupSorted, 0L);
3847+ }
3848+
3849+ void RemoveAllGroups()
3850+ {
3851+ ATLASSERT(::IsWindow(m_hWnd));
3852+ ::SendMessage(m_hWnd, LVM_REMOVEALLGROUPS, 0, 0L);
3853+ }
3854+
3855+ BOOL HasGroup(int nGroupID)
3856+ {
3857+ ATLASSERT(::IsWindow(m_hWnd));
3858+ return (BOOL)::SendMessage(m_hWnd, LVM_HASGROUP, nGroupID, 0L);
3859+ }
3860+
3861+ BOOL InsertMarkHitTest(LPPOINT lpPoint, LPLVINSERTMARK pInsertMark) const
3862+ {
3863+ ATLASSERT(::IsWindow(m_hWnd));
3864+ return (BOOL)::SendMessage(m_hWnd, LVM_INSERTMARKHITTEST, (WPARAM)lpPoint, (LPARAM)pInsertMark);
3865+ }
3866+
3867+ BOOL SetInfoTip(PLVSETINFOTIP pSetInfoTip)
3868+ {
3869+ ATLASSERT(::IsWindow(m_hWnd));
3870+ return (BOOL)::SendMessage(m_hWnd, LVM_SETINFOTIP, 0, (LPARAM)pSetInfoTip);
3871+ }
3872+
3873+ void CancelEditLabel()
3874+ {
3875+ ATLASSERT(::IsWindow(m_hWnd));
3876+ ::SendMessage(m_hWnd, LVM_CANCELEDITLABEL, 0, 0L);
3877+ }
3878+
3879+ UINT MapIndexToID(int nIndex) const
3880+ {
3881+ ATLASSERT(::IsWindow(m_hWnd));
3882+ return (UINT)::SendMessage(m_hWnd, LVM_MAPINDEXTOID, nIndex, 0L);
3883+ }
3884+
3885+ int MapIDToIndex(UINT uID) const
3886+ {
3887+ ATLASSERT(::IsWindow(m_hWnd));
3888+ return (int)::SendMessage(m_hWnd, LVM_MAPIDTOINDEX, uID, 0L);
3889+ }
3890+#endif // (_WIN32_WINNT >= 0x0501)
3891+
3892+#if (_WIN32_WINNT >= 0x0600)
3893+ int HitTestEx(LPLVHITTESTINFO lpHitTestInfo) const
3894+ {
3895+ ATLASSERT(::IsWindow(m_hWnd));
3896+ return (int)::SendMessage(m_hWnd, LVM_HITTEST, (WPARAM)-1, (LPARAM)lpHitTestInfo);
3897+ }
3898+
3899+ int HitTestEx(POINT pt, UINT* pFlags) const
3900+ {
3901+ ATLASSERT(::IsWindow(m_hWnd));
3902+ LVHITTESTINFO hti = { 0 };
3903+ hti.pt = pt;
3904+ int nRes = (int)::SendMessage(m_hWnd, LVM_HITTEST, (WPARAM)-1, (LPARAM)&hti);
3905+ if (pFlags != NULL)
3906+ *pFlags = hti.flags;
3907+ return nRes;
3908+ }
3909+
3910+ int SubItemHitTestEx(LPLVHITTESTINFO lpHitTestInfo) const
3911+ {
3912+ ATLASSERT(::IsWindow(m_hWnd));
3913+ return (int)::SendMessage(m_hWnd, LVM_SUBITEMHITTEST, (WPARAM)-1, (LPARAM)lpHitTestInfo);
3914+ }
3915+#endif // (_WIN32_WINNT >= 0x0600)
3916+
3917+ // Note: selects only one item
3918+ BOOL SelectItem(int nIndex)
3919+ {
3920+ ATLASSERT(::IsWindow(m_hWnd));
3921+
3922+ // multi-selection only: de-select all items
3923+ if((GetStyle() & LVS_SINGLESEL) == 0)
3924+ SetItemState(-1, 0, LVIS_SELECTED);
3925+
3926+ BOOL bRet = SetItemState(nIndex, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
3927+ if(bRet)
3928+ bRet = EnsureVisible(nIndex, FALSE);
3929+
3930+ return bRet;
3931+ }
3932+};
3933+
3934+typedef CListViewCtrlT<ATL::CWindow> CListViewCtrl;
3935+
3936+
3937+///////////////////////////////////////////////////////////////////////////////
3938+// CTreeViewCtrl
3939+
3940+template <class TBase>
3941+class CTreeViewCtrlT : public TBase
3942+{
3943+public:
3944+// Constructors
3945+ CTreeViewCtrlT(HWND hWnd = NULL) : TBase(hWnd)
3946+ { }
3947+
3948+ CTreeViewCtrlT< TBase >& operator =(HWND hWnd)
3949+ {
3950+ m_hWnd = hWnd;
3951+ return *this;
3952+ }
3953+
3954+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
3955+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
3956+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
3957+ {
3958+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
3959+ }
3960+
3961+// Attributes
3962+ static LPCTSTR GetWndClassName()
3963+ {
3964+ return WC_TREEVIEW;
3965+ }
3966+
3967+ UINT GetCount() const
3968+ {
3969+ ATLASSERT(::IsWindow(m_hWnd));
3970+ return (UINT)::SendMessage(m_hWnd, TVM_GETCOUNT, 0, 0L);
3971+ }
3972+
3973+ UINT GetIndent() const
3974+ {
3975+ ATLASSERT(::IsWindow(m_hWnd));
3976+ return (UINT)::SendMessage(m_hWnd, TVM_GETINDENT, 0, 0L);
3977+ }
3978+
3979+ void SetIndent(UINT nIndent)
3980+ {
3981+ ATLASSERT(::IsWindow(m_hWnd));
3982+ ::SendMessage(m_hWnd, TVM_SETINDENT, nIndent, 0L);
3983+ }
3984+
3985+ CImageList GetImageList(int nImageListType = TVSIL_NORMAL) const
3986+ {
3987+ ATLASSERT(::IsWindow(m_hWnd));
3988+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TVM_GETIMAGELIST, (WPARAM)nImageListType, 0L));
3989+ }
3990+
3991+ CImageList SetImageList(HIMAGELIST hImageList, int nImageListType = TVSIL_NORMAL)
3992+ {
3993+ ATLASSERT(::IsWindow(m_hWnd));
3994+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TVM_SETIMAGELIST, (WPARAM)nImageListType, (LPARAM)hImageList));
3995+ }
3996+
3997+ BOOL GetItem(LPTVITEM pItem) const
3998+ {
3999+ ATLASSERT(::IsWindow(m_hWnd));
4000+ return (BOOL)::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)pItem);
4001+ }
4002+
4003+ BOOL SetItem(LPTVITEM pItem)
4004+ {
4005+ ATLASSERT(::IsWindow(m_hWnd));
4006+ return (BOOL)::SendMessage(m_hWnd, TVM_SETITEM, 0, (LPARAM)pItem);
4007+ }
4008+
4009+ BOOL SetItem(HTREEITEM hItem, UINT nMask, LPCTSTR lpszItem, int nImage,
4010+ int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam)
4011+ {
4012+ ATLASSERT(::IsWindow(m_hWnd));
4013+ TVITEM item = { 0 };
4014+ item.hItem = hItem;
4015+ item.mask = nMask;
4016+ item.pszText = (LPTSTR) lpszItem;
4017+ item.iImage = nImage;
4018+ item.iSelectedImage = nSelectedImage;
4019+ item.state = nState;
4020+ item.stateMask = nStateMask;
4021+ item.lParam = lParam;
4022+ return (BOOL)::SendMessage(m_hWnd, TVM_SETITEM, 0, (LPARAM)&item);
4023+ }
4024+
4025+ BOOL GetItemText(HTREEITEM hItem, LPTSTR lpstrText, int nLen) const
4026+ {
4027+ ATLASSERT(::IsWindow(m_hWnd));
4028+ ATLASSERT(lpstrText != NULL);
4029+
4030+ TVITEM item = { 0 };
4031+ item.hItem = hItem;
4032+ item.mask = TVIF_TEXT;
4033+ item.pszText = lpstrText;
4034+ item.cchTextMax = nLen;
4035+
4036+ return (BOOL)::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
4037+ }
4038+
4039+#ifndef _ATL_NO_COM
4040+ BOOL GetItemText(HTREEITEM hItem, BSTR& bstrText) const
4041+ {
4042+ USES_CONVERSION;
4043+ ATLASSERT(::IsWindow(m_hWnd));
4044+ ATLASSERT(bstrText == NULL);
4045+ TVITEM item = { 0 };
4046+ item.hItem = hItem;
4047+ item.mask = TVIF_TEXT;
4048+
4049+ LPTSTR lpstrText = NULL;
4050+ BOOL bRet = FALSE;
4051+ for(int nLen = 256; ; nLen *= 2)
4052+ {
4053+ ATLTRY(lpstrText = new TCHAR[nLen]);
4054+ if(lpstrText == NULL)
4055+ break;
4056+ lpstrText[0] = NULL;
4057+ item.pszText = lpstrText;
4058+ item.cchTextMax = nLen;
4059+ bRet = (BOOL)::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
4060+ if(!bRet || (lstrlen(item.pszText) < nLen - 1))
4061+ break;
4062+ delete [] lpstrText;
4063+ lpstrText = NULL;
4064+ }
4065+
4066+ if(lpstrText != NULL)
4067+ {
4068+ if(bRet)
4069+ bstrText = ::SysAllocString(T2OLE(lpstrText));
4070+ delete [] lpstrText;
4071+ }
4072+
4073+ return (bstrText != NULL) ? TRUE : FALSE;
4074+ }
4075+#endif // !_ATL_NO_COM
4076+
4077+#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
4078+ BOOL GetItemText(HTREEITEM hItem, _CSTRING_NS::CString& strText) const
4079+ {
4080+ ATLASSERT(::IsWindow(m_hWnd));
4081+ TVITEM item = { 0 };
4082+ item.hItem = hItem;
4083+ item.mask = TVIF_TEXT;
4084+
4085+ strText.Empty();
4086+ BOOL bRet = FALSE;
4087+ for(int nLen = 256; ; nLen *= 2)
4088+ {
4089+ item.pszText = strText.GetBufferSetLength(nLen);
4090+ if(item.pszText == NULL)
4091+ {
4092+ bRet = FALSE;
4093+ break;
4094+ }
4095+ item.cchTextMax = nLen;
4096+ bRet = (BOOL)::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
4097+ if(!bRet || (lstrlen(item.pszText) < nLen - 1))
4098+ break;
4099+ }
4100+ strText.ReleaseBuffer();
4101+ return bRet;
4102+ }
4103+#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
4104+
4105+ BOOL SetItemText(HTREEITEM hItem, LPCTSTR lpszItem)
4106+ {
4107+ ATLASSERT(::IsWindow(m_hWnd));
4108+ return SetItem(hItem, TVIF_TEXT, lpszItem, 0, 0, 0, 0, NULL);
4109+ }
4110+
4111+ BOOL GetItemImage(HTREEITEM hItem, int& nImage, int& nSelectedImage) const
4112+ {
4113+ ATLASSERT(::IsWindow(m_hWnd));
4114+ TVITEM item = { 0 };
4115+ item.hItem = hItem;
4116+ item.mask = TVIF_IMAGE|TVIF_SELECTEDIMAGE;
4117+ BOOL bRes = (BOOL)::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
4118+ if (bRes)
4119+ {
4120+ nImage = item.iImage;
4121+ nSelectedImage = item.iSelectedImage;
4122+ }
4123+ return bRes;
4124+ }
4125+
4126+ BOOL SetItemImage(HTREEITEM hItem, int nImage, int nSelectedImage)
4127+ {
4128+ ATLASSERT(::IsWindow(m_hWnd));
4129+ return SetItem(hItem, TVIF_IMAGE|TVIF_SELECTEDIMAGE, NULL, nImage, nSelectedImage, 0, 0, NULL);
4130+ }
4131+
4132+ UINT GetItemState(HTREEITEM hItem, UINT nStateMask) const
4133+ {
4134+ ATLASSERT(::IsWindow(m_hWnd));
4135+#if (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
4136+ return (((UINT)::SendMessage(m_hWnd, TVM_GETITEMSTATE, (WPARAM)hItem, (LPARAM)nStateMask)) & nStateMask);
4137+#else // !((_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE))
4138+ TVITEM item = { 0 };
4139+ item.hItem = hItem;
4140+ item.mask = TVIF_STATE;
4141+ item.state = 0;
4142+ item.stateMask = nStateMask;
4143+ ::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
4144+ return (item.state & nStateMask);
4145+#endif // !((_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE))
4146+ }
4147+
4148+ BOOL SetItemState(HTREEITEM hItem, UINT nState, UINT nStateMask)
4149+ {
4150+ ATLASSERT(::IsWindow(m_hWnd));
4151+ return SetItem(hItem, TVIF_STATE, NULL, 0, 0, nState, nStateMask, NULL);
4152+ }
4153+
4154+ DWORD_PTR GetItemData(HTREEITEM hItem) const
4155+ {
4156+ ATLASSERT(::IsWindow(m_hWnd));
4157+ TVITEM item = { 0 };
4158+ item.hItem = hItem;
4159+ item.mask = TVIF_PARAM;
4160+ BOOL bRet = (BOOL)::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
4161+ return (DWORD_PTR)(bRet ? item.lParam : NULL);
4162+ }
4163+
4164+ BOOL SetItemData(HTREEITEM hItem, DWORD_PTR dwData)
4165+ {
4166+ ATLASSERT(::IsWindow(m_hWnd));
4167+ return SetItem(hItem, TVIF_PARAM, NULL, 0, 0, 0, 0, (LPARAM)dwData);
4168+ }
4169+
4170+ CEdit GetEditControl() const
4171+ {
4172+ ATLASSERT(::IsWindow(m_hWnd));
4173+ return CEdit((HWND)::SendMessage(m_hWnd, TVM_GETEDITCONTROL, 0, 0L));
4174+ }
4175+
4176+ UINT GetVisibleCount() const
4177+ {
4178+ ATLASSERT(::IsWindow(m_hWnd));
4179+ return (UINT)::SendMessage(m_hWnd, TVM_GETVISIBLECOUNT, 0, 0L);
4180+ }
4181+
4182+ BOOL GetItemRect(HTREEITEM hItem, LPRECT lpRect, BOOL bTextOnly) const
4183+ {
4184+ ATLASSERT(::IsWindow(m_hWnd));
4185+ *(HTREEITEM*)lpRect = hItem;
4186+ return (BOOL)::SendMessage(m_hWnd, TVM_GETITEMRECT, (WPARAM)bTextOnly, (LPARAM)lpRect);
4187+ }
4188+
4189+ BOOL ItemHasChildren(HTREEITEM hItem) const
4190+ {
4191+ ATLASSERT(::IsWindow(m_hWnd));
4192+ TVITEM item = { 0 };
4193+ item.hItem = hItem;
4194+ item.mask = TVIF_CHILDREN;
4195+ ::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
4196+ return item.cChildren;
4197+ }
4198+
4199+#ifndef _WIN32_WCE
4200+ CToolTipCtrl GetToolTips() const
4201+ {
4202+ ATLASSERT(::IsWindow(m_hWnd));
4203+ return CToolTipCtrl((HWND)::SendMessage(m_hWnd, TVM_GETTOOLTIPS, 0, 0L));
4204+ }
4205+
4206+ CToolTipCtrl SetToolTips(HWND hWndTT)
4207+ {
4208+ ATLASSERT(::IsWindow(m_hWnd));
4209+ return CToolTipCtrl((HWND)::SendMessage(m_hWnd, TVM_SETTOOLTIPS, (WPARAM)hWndTT, 0L));
4210+ }
4211+#endif // !_WIN32_WCE
4212+
4213+ int GetISearchString(LPTSTR lpstr) const
4214+ {
4215+ ATLASSERT(::IsWindow(m_hWnd));
4216+ return (int)::SendMessage(m_hWnd, TVM_GETISEARCHSTRING, 0, (LPARAM)lpstr);
4217+ }
4218+
4219+ // checkboxes only
4220+ BOOL GetCheckState(HTREEITEM hItem) const
4221+ {
4222+ ATLASSERT(::IsWindow(m_hWnd));
4223+ ATLASSERT((GetStyle() & TVS_CHECKBOXES) != 0);
4224+ UINT uRet = GetItemState(hItem, TVIS_STATEIMAGEMASK);
4225+ return (uRet >> 12) - 1;
4226+ }
4227+
4228+ BOOL SetCheckState(HTREEITEM hItem, BOOL bCheck)
4229+ {
4230+ int nCheck = bCheck ? 2 : 1; // one based index
4231+ return SetItemState(hItem, INDEXTOSTATEIMAGEMASK(nCheck), TVIS_STATEIMAGEMASK);
4232+ }
4233+
4234+#if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
4235+ COLORREF GetBkColor() const
4236+ {
4237+ ATLASSERT(::IsWindow(m_hWnd));
4238+ return (COLORREF)::SendMessage(m_hWnd, TVM_GETBKCOLOR, 0, 0L);
4239+ }
4240+
4241+ COLORREF SetBkColor(COLORREF clr)
4242+ {
4243+ ATLASSERT(::IsWindow(m_hWnd));
4244+ return (COLORREF)::SendMessage(m_hWnd, TVM_SETBKCOLOR, 0, (LPARAM)clr);
4245+ }
4246+
4247+ COLORREF GetInsertMarkColor() const
4248+ {
4249+ ATLASSERT(::IsWindow(m_hWnd));
4250+ return (COLORREF)::SendMessage(m_hWnd, TVM_GETINSERTMARKCOLOR, 0, 0L);
4251+ }
4252+
4253+ COLORREF SetInsertMarkColor(COLORREF clr)
4254+ {
4255+ ATLASSERT(::IsWindow(m_hWnd));
4256+ return (COLORREF)::SendMessage(m_hWnd, TVM_SETINSERTMARKCOLOR, 0, (LPARAM)clr);
4257+ }
4258+
4259+ int GetItemHeight() const
4260+ {
4261+ ATLASSERT(::IsWindow(m_hWnd));
4262+ return (int)::SendMessage(m_hWnd, TVM_GETITEMHEIGHT, 0, 0L);
4263+ }
4264+
4265+ int SetItemHeight(int cyHeight)
4266+ {
4267+ ATLASSERT(::IsWindow(m_hWnd));
4268+ return (int)::SendMessage(m_hWnd, TVM_SETITEMHEIGHT, cyHeight, 0L);
4269+ }
4270+
4271+ int GetScrollTime() const
4272+ {
4273+ ATLASSERT(::IsWindow(m_hWnd));
4274+ return (int)::SendMessage(m_hWnd, TVM_GETSCROLLTIME, 0, 0L);
4275+ }
4276+
4277+ int SetScrollTime(int nScrollTime)
4278+ {
4279+ ATLASSERT(::IsWindow(m_hWnd));
4280+ return (int)::SendMessage(m_hWnd, TVM_SETSCROLLTIME, nScrollTime, 0L);
4281+ }
4282+
4283+ COLORREF GetTextColor() const
4284+ {
4285+ ATLASSERT(::IsWindow(m_hWnd));
4286+ return (COLORREF)::SendMessage(m_hWnd, TVM_GETTEXTCOLOR, 0, 0L);
4287+ }
4288+
4289+ COLORREF SetTextColor(COLORREF clr)
4290+ {
4291+ ATLASSERT(::IsWindow(m_hWnd));
4292+ return (COLORREF)::SendMessage(m_hWnd, TVM_SETTEXTCOLOR, 0, (LPARAM)clr);
4293+ }
4294+
4295+ BOOL GetUnicodeFormat() const
4296+ {
4297+ ATLASSERT(::IsWindow(m_hWnd));
4298+ return (BOOL)::SendMessage(m_hWnd, TVM_GETUNICODEFORMAT, 0, 0L);
4299+ }
4300+
4301+ BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
4302+ {
4303+ ATLASSERT(::IsWindow(m_hWnd));
4304+ return (BOOL)::SendMessage(m_hWnd, TVM_SETUNICODEFORMAT, bUnicode, 0L);
4305+ }
4306+#endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
4307+
4308+#if (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
4309+ COLORREF GetLineColor() const
4310+ {
4311+ ATLASSERT(::IsWindow(m_hWnd));
4312+ return (COLORREF)::SendMessage(m_hWnd, TVM_GETLINECOLOR, 0, 0L);
4313+ }
4314+
4315+ COLORREF SetLineColor(COLORREF clrNew /*= CLR_DEFAULT*/)
4316+ {
4317+ ATLASSERT(::IsWindow(m_hWnd));
4318+ return (COLORREF)::SendMessage(m_hWnd, TVM_SETLINECOLOR, 0, (LPARAM)clrNew);
4319+ }
4320+#endif // (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
4321+
4322+#if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
4323+ BOOL GetItem(LPTVITEMEX pItem) const
4324+ {
4325+ ATLASSERT(::IsWindow(m_hWnd));
4326+ return (BOOL)::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)pItem);
4327+ }
4328+
4329+ BOOL SetItem(LPTVITEMEX pItem)
4330+ {
4331+ ATLASSERT(::IsWindow(m_hWnd));
4332+ return (BOOL)::SendMessage(m_hWnd, TVM_SETITEM, 0, (LPARAM)pItem);
4333+ }
4334+#endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
4335+
4336+ DWORD GetExtendedStyle() const
4337+ {
4338+#ifndef TVM_GETEXTENDEDSTYLE
4339+ const UINT TVM_GETEXTENDEDSTYLE = (TV_FIRST + 45);
4340+#endif
4341+ ATLASSERT(::IsWindow(m_hWnd));
4342+ return (DWORD)::SendMessage(m_hWnd, TVM_GETEXTENDEDSTYLE, 0, 0L);
4343+ }
4344+
4345+ DWORD SetExtendedStyle(DWORD dwStyle, DWORD dwMask)
4346+ {
4347+#ifndef TVM_SETEXTENDEDSTYLE
4348+ const UINT TVM_SETEXTENDEDSTYLE = (TV_FIRST + 44);
4349+#endif
4350+ ATLASSERT(::IsWindow(m_hWnd));
4351+ return (DWORD)::SendMessage(m_hWnd, TVM_SETEXTENDEDSTYLE, dwMask, dwStyle);
4352+ }
4353+
4354+#if (_WIN32_WINNT >= 0x0600)
4355+ BOOL SetAutoScrollInfo(UINT uPixPerSec, UINT uUpdateTime)
4356+ {
4357+ ATLASSERT(::IsWindow(m_hWnd));
4358+ return (BOOL)::SendMessage(m_hWnd, TVM_SETAUTOSCROLLINFO, (WPARAM)uPixPerSec, (LPARAM)uUpdateTime);
4359+ }
4360+
4361+ DWORD GetSelectedCount() const
4362+ {
4363+ ATLASSERT(::IsWindow(m_hWnd));
4364+ return (DWORD)::SendMessage(m_hWnd, TVM_GETSELECTEDCOUNT, 0, 0L);
4365+ }
4366+
4367+ BOOL GetItemPartRect(HTREEITEM hItem, TVITEMPART partID, LPRECT lpRect) const
4368+ {
4369+ ATLASSERT(::IsWindow(m_hWnd));
4370+ TVGETITEMPARTRECTINFO gipri = { hItem, lpRect, partID };
4371+ return (BOOL)::SendMessage(m_hWnd, TVM_GETITEMPARTRECT, 0, (LPARAM)&gipri);
4372+ }
4373+#endif // (_WIN32_WINNT >= 0x0600)
4374+
4375+// Operations
4376+ HTREEITEM InsertItem(LPTVINSERTSTRUCT lpInsertStruct)
4377+ {
4378+ ATLASSERT(::IsWindow(m_hWnd));
4379+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_INSERTITEM, 0, (LPARAM)lpInsertStruct);
4380+ }
4381+
4382+ HTREEITEM InsertItem(LPCTSTR lpszItem, int nImage,
4383+ int nSelectedImage, HTREEITEM hParent, HTREEITEM hInsertAfter)
4384+ {
4385+ ATLASSERT(::IsWindow(m_hWnd));
4386+ return InsertItem(TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE, lpszItem, nImage, nSelectedImage, 0, 0, 0, hParent, hInsertAfter);
4387+ }
4388+
4389+ HTREEITEM InsertItem(LPCTSTR lpszItem, HTREEITEM hParent, HTREEITEM hInsertAfter)
4390+ {
4391+ ATLASSERT(::IsWindow(m_hWnd));
4392+ return InsertItem(TVIF_TEXT, lpszItem, 0, 0, 0, 0, 0, hParent, hInsertAfter);
4393+ }
4394+
4395+ HTREEITEM InsertItem(UINT nMask, LPCTSTR lpszItem, int nImage,
4396+ int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam,
4397+ HTREEITEM hParent, HTREEITEM hInsertAfter)
4398+ {
4399+ ATLASSERT(::IsWindow(m_hWnd));
4400+ TVINSERTSTRUCT tvis = { 0 };
4401+ tvis.hParent = hParent;
4402+ tvis.hInsertAfter = hInsertAfter;
4403+ tvis.item.mask = nMask;
4404+ tvis.item.pszText = (LPTSTR) lpszItem;
4405+ tvis.item.iImage = nImage;
4406+ tvis.item.iSelectedImage = nSelectedImage;
4407+ tvis.item.state = nState;
4408+ tvis.item.stateMask = nStateMask;
4409+ tvis.item.lParam = lParam;
4410+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_INSERTITEM, 0, (LPARAM)&tvis);
4411+ }
4412+
4413+ BOOL DeleteItem(HTREEITEM hItem)
4414+ {
4415+ ATLASSERT(::IsWindow(m_hWnd));
4416+ return (BOOL)::SendMessage(m_hWnd, TVM_DELETEITEM, 0, (LPARAM)hItem);
4417+ }
4418+
4419+ BOOL DeleteAllItems()
4420+ {
4421+ ATLASSERT(::IsWindow(m_hWnd));
4422+ return (BOOL)::SendMessage(m_hWnd, TVM_DELETEITEM, 0, (LPARAM)TVI_ROOT);
4423+ }
4424+
4425+ BOOL Expand(HTREEITEM hItem, UINT nCode = TVE_EXPAND)
4426+ {
4427+ ATLASSERT(::IsWindow(m_hWnd));
4428+ return (BOOL)::SendMessage(m_hWnd, TVM_EXPAND, nCode, (LPARAM)hItem);
4429+ }
4430+
4431+ HTREEITEM GetNextItem(HTREEITEM hItem, UINT nCode) const
4432+ {
4433+ ATLASSERT(::IsWindow(m_hWnd));
4434+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, nCode, (LPARAM)hItem);
4435+ }
4436+
4437+ HTREEITEM GetChildItem(HTREEITEM hItem) const
4438+ {
4439+ ATLASSERT(::IsWindow(m_hWnd));
4440+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hItem);
4441+ }
4442+
4443+ HTREEITEM GetNextSiblingItem(HTREEITEM hItem) const
4444+ {
4445+ ATLASSERT(::IsWindow(m_hWnd));
4446+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)hItem);
4447+ }
4448+
4449+ HTREEITEM GetPrevSiblingItem(HTREEITEM hItem) const
4450+ {
4451+ ATLASSERT(::IsWindow(m_hWnd));
4452+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_PREVIOUS, (LPARAM)hItem);
4453+ }
4454+
4455+ HTREEITEM GetParentItem(HTREEITEM hItem) const
4456+ {
4457+ ATLASSERT(::IsWindow(m_hWnd));
4458+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_PARENT, (LPARAM)hItem);
4459+ }
4460+
4461+ HTREEITEM GetFirstVisibleItem() const
4462+ {
4463+ ATLASSERT(::IsWindow(m_hWnd));
4464+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_FIRSTVISIBLE, 0L);
4465+ }
4466+
4467+ HTREEITEM GetNextVisibleItem(HTREEITEM hItem) const
4468+ {
4469+ ATLASSERT(::IsWindow(m_hWnd));
4470+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_NEXTVISIBLE, (LPARAM)hItem);
4471+ }
4472+
4473+ HTREEITEM GetPrevVisibleItem(HTREEITEM hItem) const
4474+ {
4475+ ATLASSERT(::IsWindow(m_hWnd));
4476+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_PREVIOUSVISIBLE, (LPARAM)hItem);
4477+ }
4478+
4479+ HTREEITEM GetSelectedItem() const
4480+ {
4481+ ATLASSERT(::IsWindow(m_hWnd));
4482+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_CARET, 0L);
4483+ }
4484+
4485+ HTREEITEM GetDropHilightItem() const
4486+ {
4487+ ATLASSERT(::IsWindow(m_hWnd));
4488+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_DROPHILITE, 0L);
4489+ }
4490+
4491+ HTREEITEM GetRootItem() const
4492+ {
4493+ ATLASSERT(::IsWindow(m_hWnd));
4494+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_ROOT, 0L);
4495+ }
4496+
4497+#if !defined(_WIN32_WCE) && (_WIN32_IE >= 0x0400)
4498+ HTREEITEM GetLastVisibleItem() const
4499+ {
4500+ ATLASSERT(::IsWindow(m_hWnd));
4501+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_LASTVISIBLE, 0L);
4502+ }
4503+#endif // !defined(_WIN32_WCE) && (_WIN32_IE >= 0x0400)
4504+
4505+#if (_WIN32_IE >= 0x0600)
4506+ HTREEITEM GetNextSelectedItem() const
4507+ {
4508+ ATLASSERT(::IsWindow(m_hWnd));
4509+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_NEXTSELECTED, 0L);
4510+ }
4511+#endif // (_WIN32_IE >= 0x0600)
4512+
4513+ BOOL Select(HTREEITEM hItem, UINT nCode)
4514+ {
4515+ ATLASSERT(::IsWindow(m_hWnd));
4516+ return (BOOL)::SendMessage(m_hWnd, TVM_SELECTITEM, nCode, (LPARAM)hItem);
4517+ }
4518+
4519+ BOOL SelectItem(HTREEITEM hItem)
4520+ {
4521+ ATLASSERT(::IsWindow(m_hWnd));
4522+ return (BOOL)::SendMessage(m_hWnd, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hItem);
4523+ }
4524+
4525+ BOOL SelectDropTarget(HTREEITEM hItem)
4526+ {
4527+ ATLASSERT(::IsWindow(m_hWnd));
4528+ return (BOOL)::SendMessage(m_hWnd, TVM_SELECTITEM, TVGN_DROPHILITE, (LPARAM)hItem);
4529+ }
4530+
4531+ BOOL SelectSetFirstVisible(HTREEITEM hItem)
4532+ {
4533+ ATLASSERT(::IsWindow(m_hWnd));
4534+ return (BOOL)::SendMessage(m_hWnd, TVM_SELECTITEM, TVGN_FIRSTVISIBLE, (LPARAM)hItem);
4535+ }
4536+
4537+ CEdit EditLabel(HTREEITEM hItem)
4538+ {
4539+ ATLASSERT(::IsWindow(m_hWnd));
4540+ return CEdit((HWND)::SendMessage(m_hWnd, TVM_EDITLABEL, 0, (LPARAM)hItem));
4541+ }
4542+
4543+ BOOL EndEditLabelNow(BOOL bCancel)
4544+ {
4545+ ATLASSERT(::IsWindow(m_hWnd));
4546+ return (BOOL)::SendMessage(m_hWnd, TVM_ENDEDITLABELNOW, bCancel, 0L);
4547+ }
4548+
4549+ HTREEITEM HitTest(TVHITTESTINFO* pHitTestInfo) const
4550+ {
4551+ ATLASSERT(::IsWindow(m_hWnd));
4552+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_HITTEST, 0, (LPARAM)pHitTestInfo);
4553+ }
4554+
4555+ HTREEITEM HitTest(POINT pt, UINT* pFlags) const
4556+ {
4557+ ATLASSERT(::IsWindow(m_hWnd));
4558+ TVHITTESTINFO hti = { 0 };
4559+ hti.pt = pt;
4560+ HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_HITTEST, 0, (LPARAM)&hti);
4561+ if (pFlags != NULL)
4562+ *pFlags = hti.flags;
4563+ return hTreeItem;
4564+ }
4565+
4566+ BOOL SortChildren(HTREEITEM hItem, BOOL bRecurse = FALSE)
4567+ {
4568+ ATLASSERT(::IsWindow(m_hWnd));
4569+ return (BOOL)::SendMessage(m_hWnd, TVM_SORTCHILDREN, (WPARAM)bRecurse, (LPARAM)hItem);
4570+ }
4571+
4572+ BOOL EnsureVisible(HTREEITEM hItem)
4573+ {
4574+ ATLASSERT(::IsWindow(m_hWnd));
4575+ return (BOOL)::SendMessage(m_hWnd, TVM_ENSUREVISIBLE, 0, (LPARAM)hItem);
4576+ }
4577+
4578+ BOOL SortChildrenCB(LPTVSORTCB pSort, BOOL bRecurse = FALSE)
4579+ {
4580+ ATLASSERT(::IsWindow(m_hWnd));
4581+ return (BOOL)::SendMessage(m_hWnd, TVM_SORTCHILDRENCB, (WPARAM)bRecurse, (LPARAM)pSort);
4582+ }
4583+
4584+ CImageList RemoveImageList(int nImageList)
4585+ {
4586+ ATLASSERT(::IsWindow(m_hWnd));
4587+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TVM_SETIMAGELIST, (WPARAM)nImageList, NULL));
4588+ }
4589+
4590+ CImageList CreateDragImage(HTREEITEM hItem)
4591+ {
4592+ ATLASSERT(::IsWindow(m_hWnd));
4593+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TVM_CREATEDRAGIMAGE, 0, (LPARAM)hItem));
4594+ }
4595+
4596+#if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
4597+ BOOL SetInsertMark(HTREEITEM hTreeItem, BOOL bAfter)
4598+ {
4599+ ATLASSERT(::IsWindow(m_hWnd));
4600+ return (BOOL)::SendMessage(m_hWnd, TVM_SETINSERTMARK, bAfter, (LPARAM)hTreeItem);
4601+ }
4602+
4603+ BOOL RemoveInsertMark()
4604+ {
4605+ ATLASSERT(::IsWindow(m_hWnd));
4606+ return (BOOL)::SendMessage(m_hWnd, TVM_SETINSERTMARK, 0, 0L);
4607+ }
4608+#endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
4609+
4610+#if (_WIN32_WINNT >= 0x0501)
4611+ HTREEITEM MapAccIDToHTREEITEM(UINT uID) const
4612+ {
4613+ ATLASSERT(::IsWindow(m_hWnd));
4614+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_MAPACCIDTOHTREEITEM, uID, 0L);
4615+ }
4616+
4617+ UINT MapHTREEITEMToAccID(HTREEITEM hTreeItem) const