1 // Windows Template Library - WTL version 8.0
\r
2 // Copyright (C) Microsoft Corporation. All rights reserved.
\r
4 // This file is a part of the Windows Template Library.
\r
5 // The use and distribution terms for this software are covered by the
\r
6 // Common Public License 1.0 (http://opensource.org/osi3.0/licenses/cpl1.0.php)
\r
7 // which can be found in the file CPL.TXT at the root of this distribution.
\r
8 // By using this software in any fashion, you are agreeing to be bound by
\r
9 // the terms of this license. You must not remove this notice, or
\r
10 // any other, from this software.
\r
12 #ifndef __ATLAPP_H__
\r
13 #define __ATLAPP_H__
\r
18 #error ATL requires C++ compilation (use a .cpp suffix)
\r
21 #ifndef __ATLBASE_H__
\r
22 #error atlapp.h requires atlbase.h to be included first
\r
26 #if (WINVER < 0x0400)
\r
27 #error WTL requires Windows version 4.0 or higher
\r
30 #if (_WIN32_IE < 0x0300)
\r
31 #error WTL requires IE version 3.0 or higher
\r
35 #ifdef _ATL_NO_COMMODULE
\r
36 #error WTL requires that _ATL_NO_COMMODULE is not defined
\r
37 #endif // _ATL_NO_COMMODULE
\r
39 #if defined(_WIN32_WCE) && defined(_ATL_MIN_CRT)
\r
40 #pragma message("Warning: WTL for Windows CE doesn't use _ATL_MIN_CRT")
\r
41 #endif // defined(_WIN32_WCE) && defined(_ATL_MIN_CRT)
\r
44 #if !defined(_ATL_MIN_CRT) && defined(_MT) && !defined(_WIN32_WCE)
\r
45 #include <process.h> // for _beginthreadex
\r
48 #if (_ATL_VER < 0x0800) && !defined(_DEBUG)
\r
52 #include <commctrl.h>
\r
54 #pragma comment(lib, "comctl32.lib")
\r
55 #endif // !_WIN32_WCE
\r
59 #else // CE specific
\r
60 #include "atlresce.h"
\r
61 #endif // _WIN32_WCE
\r
63 // We need to disable this warning because of template class arguments
\r
64 #pragma warning(disable: 4127)
\r
67 ///////////////////////////////////////////////////////////////////////////////
\r
68 // WTL version number
\r
70 #define _WTL_VER 0x0800
\r
73 ///////////////////////////////////////////////////////////////////////////////
\r
74 // Classes in this file:
\r
83 // Global functions:
\r
84 // AtlGetDefaultGuiFont()
\r
85 // AtlCreateBoldFont()
\r
86 // AtlInitCommonControls()
\r
89 ///////////////////////////////////////////////////////////////////////////////
\r
90 // Global support for Windows CE
\r
94 #ifndef SW_SHOWDEFAULT
\r
95 #define SW_SHOWDEFAULT SW_SHOWNORMAL
\r
96 #endif // !SW_SHOWDEFAULT
\r
98 // These get's OR-ed in a constant and will have no effect.
\r
99 // Defining them reduces the number of #ifdefs required for CE.
\r
100 #define LR_DEFAULTSIZE 0
\r
101 #define LR_LOADFROMFILE 0
\r
103 #ifndef SM_CXCURSOR
\r
104 #define SM_CXCURSOR 13
\r
106 #ifndef SM_CYCURSOR
\r
107 #define SM_CYCURSOR 14
\r
110 inline BOOL IsMenu(HMENU hMenu)
\r
112 MENUITEMINFO mii = { sizeof(MENUITEMINFO) };
\r
114 BOOL bRet = ::GetMenuItemInfo(hMenu, 0, TRUE, &mii);
\r
116 bRet = (::GetLastError() != ERROR_INVALID_MENU_HANDLE) ? TRUE : FALSE;
\r
120 #if (_WIN32_WCE >= 410)
\r
121 extern "C" void WINAPI ListView_SetItemSpacing(HWND hwndLV, int iHeight);
\r
122 #endif // (_WIN32_WCE >= 410)
\r
124 inline int MulDiv(IN int nNumber, IN int nNumerator, IN int nDenominator)
\r
126 __int64 multiple = nNumber * nNumerator;
\r
127 return static_cast<int>(multiple / nDenominator);
\r
130 #if (_ATL_VER >= 0x0800)
\r
132 #ifndef _WTL_KEEP_WS_OVERLAPPEDWINDOW
\r
133 #ifdef WS_OVERLAPPEDWINDOW
\r
134 #undef WS_OVERLAPPEDWINDOW
\r
135 #define WS_OVERLAPPEDWINDOW 0
\r
136 #endif // WS_OVERLAPPEDWINDOW
\r
137 #endif // !_WTL_KEEP_WS_OVERLAPPEDWINDOW
\r
140 #define RDW_FRAME 0
\r
141 #endif // !RDW_FRAME
\r
143 #ifndef WM_WINDOWPOSCHANGING
\r
144 #define WM_WINDOWPOSCHANGING 0
\r
145 #endif // !WM_WINDOWPOSCHANGING
\r
147 #define FreeResource(x)
\r
148 #define UnlockResource(x)
\r
152 inline HRESULT CComModule::RegisterClassObjects(DWORD /*dwClsContext*/, DWORD /*dwFlags*/) throw()
\r
153 { return E_NOTIMPL; }
\r
154 inline HRESULT CComModule::RevokeClassObjects() throw()
\r
155 { return E_NOTIMPL; }
\r
156 }; // namespace ATL
\r
159 #define lstrlenW (int)ATL::lstrlenW
\r
162 inline int WINAPI lstrlenA(LPCSTR lpszString)
\r
163 { return ATL::lstrlenA(lpszString); }
\r
167 #define lstrcpyn ATL::lstrcpynW
\r
170 #ifndef SetWindowLongPtrW
\r
171 inline LONG_PTR tmp_SetWindowLongPtrW( HWND hWnd, int nIndex, LONG_PTR dwNewLong )
\r
173 return( ::SetWindowLongW( hWnd, nIndex, LONG( dwNewLong ) ) );
\r
175 #define SetWindowLongPtrW tmp_SetWindowLongPtrW
\r
178 #ifndef GetWindowLongPtrW
\r
179 inline LONG_PTR tmp_GetWindowLongPtrW( HWND hWnd, int nIndex )
\r
181 return( ::GetWindowLongW( hWnd, nIndex ) );
\r
183 #define GetWindowLongPtrW tmp_GetWindowLongPtrW
\r
187 #define LongToPtr(x) ((void*)x)
\r
191 #define PtrToInt( p ) ((INT)(INT_PTR) (p) )
\r
194 #else // !(_ATL_VER >= 0x0800)
\r
198 #define lstrlenW (int)::wcslen
\r
201 #define lstrlenA (int)strlen
\r
204 inline LPTSTR lstrcpyn(LPTSTR lpstrDest, LPCTSTR lpstrSrc, int nLength)
\r
206 if(lpstrDest == NULL || lpstrSrc == NULL || nLength <= 0)
\r
208 int nLen = min(lstrlen(lpstrSrc), nLength - 1);
\r
209 LPTSTR lpstrRet = (LPTSTR)memcpy(lpstrDest, lpstrSrc, nLen * sizeof(TCHAR));
\r
210 lpstrDest[nLen] = 0;
\r
213 #endif // !lstrcpyn
\r
216 inline LPWSTR lstrcpynW(LPWSTR lpstrDest, LPCWSTR lpstrSrc, int nLength)
\r
218 return lstrcpyn(lpstrDest, lpstrSrc, nLength); // WinCE is Unicode only
\r
220 #endif // !lstrcpynW
\r
223 inline LPSTR lstrcpynA(LPSTR lpstrDest, LPCSTR lpstrSrc, int nLength)
\r
225 if(lpstrDest == NULL || lpstrSrc == NULL || nLength <= 0)
\r
227 int nLen = min(lstrlenA(lpstrSrc), nLength - 1);
\r
228 LPSTR lpstrRet = (LPSTR)memcpy(lpstrDest, lpstrSrc, nLen * sizeof(char));
\r
229 lpstrDest[nLen] = 0;
\r
232 #endif // !lstrcpyn
\r
234 #ifdef TrackPopupMenu
\r
235 #undef TrackPopupMenu
\r
236 #endif // TrackPopupMenu
\r
238 #define DECLARE_WND_CLASS_EX(WndClassName, style, bkgnd) \
\r
239 static CWndClassInfo& GetWndClassInfo() \
\r
241 static CWndClassInfo wc = \
\r
243 { style, StartWindowProc, \
\r
244 0, 0, NULL, NULL, NULL, (HBRUSH)(bkgnd + 1), NULL, WndClassName }, \
\r
245 NULL, NULL, IDC_ARROW, TRUE, 0, _T("") \
\r
251 #define _MAX_FNAME _MAX_PATH
\r
252 #endif // _MAX_FNAME
\r
254 #if (_WIN32_WCE < 400)
\r
255 #define MAKEINTATOM(i) (LPTSTR)((ULONG_PTR)((WORD)(i)))
\r
256 #endif // (_WIN32_WCE < 400)
\r
258 #if (_WIN32_WCE < 410)
\r
259 #define WHEEL_PAGESCROLL (UINT_MAX)
\r
260 #define WHEEL_DELTA 120
\r
261 #endif // (_WIN32_WCE < 410)
\r
268 #define VARCMP_LT 0
\r
271 #define VARCMP_EQ 1
\r
274 #define VARCMP_GT 2
\r
276 #ifndef VARCMP_NULL
\r
277 #define VARCMP_NULL 3
\r
280 #ifndef RDW_ALLCHILDREN
\r
281 #define RDW_ALLCHILDREN 0
\r
284 #endif // !(_ATL_VER >= 0x0800)
\r
286 #endif // _WIN32_WCE
\r
289 ///////////////////////////////////////////////////////////////////////////////
\r
290 // Global support for using original VC++ 6.0 headers with WTL
\r
292 #ifndef _ATL_NO_OLD_HEADERS_WIN64
\r
293 #if !defined(_WIN64) && (_ATL_VER < 0x0700)
\r
295 #ifndef PSM_INSERTPAGE
\r
296 #define PSM_INSERTPAGE (WM_USER + 119)
\r
297 #endif // !PSM_INSERTPAGE
\r
299 #ifndef GetClassLongPtr
\r
300 #define GetClassLongPtrA GetClassLongA
\r
301 #define GetClassLongPtrW GetClassLongW
\r
303 #define GetClassLongPtr GetClassLongPtrW
\r
305 #define GetClassLongPtr GetClassLongPtrA
\r
307 #endif // !GetClassLongPtr
\r
309 #ifndef GCLP_HICONSM
\r
310 #define GCLP_HICONSM (-34)
\r
311 #endif // !GCLP_HICONSM
\r
313 #ifndef GetWindowLongPtr
\r
314 #define GetWindowLongPtrA GetWindowLongA
\r
315 #define GetWindowLongPtrW GetWindowLongW
\r
317 #define GetWindowLongPtr GetWindowLongPtrW
\r
319 #define GetWindowLongPtr GetWindowLongPtrA
\r
321 #endif // !GetWindowLongPtr
\r
323 #ifndef SetWindowLongPtr
\r
324 #define SetWindowLongPtrA SetWindowLongA
\r
325 #define SetWindowLongPtrW SetWindowLongW
\r
327 #define SetWindowLongPtr SetWindowLongPtrW
\r
329 #define SetWindowLongPtr SetWindowLongPtrA
\r
331 #endif // !SetWindowLongPtr
\r
333 #ifndef GWLP_WNDPROC
\r
334 #define GWLP_WNDPROC (-4)
\r
336 #ifndef GWLP_HINSTANCE
\r
337 #define GWLP_HINSTANCE (-6)
\r
339 #ifndef GWLP_HWNDPARENT
\r
340 #define GWLP_HWNDPARENT (-8)
\r
342 #ifndef GWLP_USERDATA
\r
343 #define GWLP_USERDATA (-21)
\r
346 #define GWLP_ID (-12)
\r
349 #ifndef DWLP_MSGRESULT
\r
350 #define DWLP_MSGRESULT 0
\r
353 typedef long LONG_PTR;
\r
354 typedef unsigned long ULONG_PTR;
\r
355 typedef ULONG_PTR DWORD_PTR;
\r
357 #ifndef HandleToUlong
\r
358 #define HandleToUlong( h ) ((ULONG)(ULONG_PTR)(h) )
\r
360 #ifndef HandleToLong
\r
361 #define HandleToLong( h ) ((LONG)(LONG_PTR) (h) )
\r
363 #ifndef LongToHandle
\r
364 #define LongToHandle( h) ((HANDLE)(LONG_PTR) (h))
\r
367 #define PtrToUlong( p ) ((ULONG)(ULONG_PTR) (p) )
\r
370 #define PtrToLong( p ) ((LONG)(LONG_PTR) (p) )
\r
373 #define PtrToUint( p ) ((UINT)(UINT_PTR) (p) )
\r
376 #define PtrToInt( p ) ((INT)(INT_PTR) (p) )
\r
378 #ifndef PtrToUshort
\r
379 #define PtrToUshort( p ) ((unsigned short)(ULONG_PTR)(p) )
\r
382 #define PtrToShort( p ) ((short)(LONG_PTR)(p) )
\r
385 #define IntToPtr( i ) ((VOID *)(INT_PTR)((int)i))
\r
388 #define UIntToPtr( ui ) ((VOID *)(UINT_PTR)((unsigned int)ui))
\r
391 #define LongToPtr( l ) ((VOID *)(LONG_PTR)((long)l))
\r
394 #define ULongToPtr( ul ) ((VOID *)(ULONG_PTR)((unsigned long)ul))
\r
397 #endif // !defined(_WIN64) && (_ATL_VER < 0x0700)
\r
398 #endif // !_ATL_NO_OLD_HEADERS_WIN64
\r
401 ///////////////////////////////////////////////////////////////////////////////
\r
402 // Global support for SecureHelper functions
\r
405 #define _TRUNCATE ((size_t)-1)
\r
408 #ifndef _ERRCODE_DEFINED
\r
409 #define _ERRCODE_DEFINED
\r
410 typedef int errno_t;
\r
413 #ifndef _SECURECRT_ERRCODE_VALUES_DEFINED
\r
414 #define _SECURECRT_ERRCODE_VALUES_DEFINED
\r
416 #define STRUNCATE 80
\r
420 #define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0]))
\r
424 ///////////////////////////////////////////////////////////////////////////////
\r
425 // Miscellaneous global support
\r
427 // define useful macros from winuser.h
\r
428 #ifndef IS_INTRESOURCE
\r
429 #define IS_INTRESOURCE(_r) (((ULONG_PTR)(_r) >> 16) == 0)
\r
430 #endif // IS_INTRESOURCE
\r
432 // protect template members from windowsx.h macros
\r
433 #ifdef _INC_WINDOWSX
\r
434 #undef SubclassWindow
\r
435 #endif // _INC_WINDOWSX
\r
437 // define useful macros from windowsx.h
\r
438 #ifndef GET_X_LPARAM
\r
439 #define GET_X_LPARAM(lParam) ((int)(short)LOWORD(lParam))
\r
441 #ifndef GET_Y_LPARAM
\r
442 #define GET_Y_LPARAM(lParam) ((int)(short)HIWORD(lParam))
\r
445 // Dummy structs for compiling with /CLR
\r
446 #if (_MSC_VER >= 1300) && defined(_MANAGED)
\r
447 __if_not_exists(_IMAGELIST::_IMAGELIST) { struct _IMAGELIST { }; }
\r
448 __if_not_exists(_TREEITEM::_TREEITEM) { struct _TREEITEM { }; }
\r
449 __if_not_exists(_PSP::_PSP) { struct _PSP { }; }
\r
452 // Define ATLVERIFY macro for ATL3
\r
453 #if (_ATL_VER < 0x0700)
\r
456 #define ATLVERIFY(expr) ATLASSERT(expr)
\r
458 #define ATLVERIFY(expr) (expr)
\r
460 #endif // ATLVERIFY
\r
461 #endif // (_ATL_VER < 0x0700)
\r
463 // Forward declaration for ATL3 fix
\r
464 #if (_ATL_VER < 0x0700) && defined(_ATL_DLL) && !defined(_WIN32_WCE)
\r
465 namespace ATL { HRESULT AtlGetCommCtrlVersion(LPDWORD pdwMajor, LPDWORD pdwMinor); };
\r
472 #if (_ATL_VER >= 0x0700)
\r
473 DECLARE_TRACE_CATEGORY(atlTraceUI);
\r
475 __declspec(selectany) ATL::CTraceCategory atlTraceUI(_T("atlTraceUI"));
\r
477 #else // !(_ATL_VER >= 0x0700)
\r
480 atlTraceUI = 0x10000000
\r
482 #endif // !(_ATL_VER >= 0x0700)
\r
484 // Windows version helper
\r
485 inline bool AtlIsOldWindows()
\r
487 OSVERSIONINFO ovi = { 0 };
\r
488 ovi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
\r
489 BOOL bRet = ::GetVersionEx(&ovi);
\r
490 return (!bRet || !((ovi.dwMajorVersion >= 5) || (ovi.dwMajorVersion == 4 && ovi.dwMinorVersion >= 90)));
\r
493 // default GUI font helper
\r
494 inline HFONT AtlGetDefaultGuiFont()
\r
497 return (HFONT)::GetStockObject(DEFAULT_GUI_FONT);
\r
498 #else // CE specific
\r
499 return (HFONT)::GetStockObject(SYSTEM_FONT);
\r
500 #endif // _WIN32_WCE
\r
503 // bold font helper (NOTE: Caller owns the font, and should destroy it when done using it)
\r
504 inline HFONT AtlCreateBoldFont(HFONT hFont = NULL)
\r
507 hFont = AtlGetDefaultGuiFont();
\r
508 ATLASSERT(hFont != NULL);
\r
509 HFONT hFontBold = NULL;
\r
510 LOGFONT lf = { 0 };
\r
511 if(::GetObject(hFont, sizeof(LOGFONT), &lf) == sizeof(LOGFONT))
\r
513 lf.lfWeight = FW_BOLD;
\r
514 hFontBold = ::CreateFontIndirect(&lf);
\r
515 ATLASSERT(hFontBold != NULL);
\r
524 // Common Controls initialization helper
\r
525 inline BOOL AtlInitCommonControls(DWORD dwFlags)
\r
527 INITCOMMONCONTROLSEX iccx = { sizeof(INITCOMMONCONTROLSEX), dwFlags };
\r
528 BOOL bRet = ::InitCommonControlsEx(&iccx);
\r
534 ///////////////////////////////////////////////////////////////////////////////
\r
535 // RunTimeHelper - helper functions for Windows version and structure sizes
\r
537 // Not for Windows CE
\r
538 #if defined(_WIN32_WCE) && !defined(_WTL_NO_RUNTIME_STRUCT_SIZE)
\r
539 #define _WTL_NO_RUNTIME_STRUCT_SIZE
\r
542 #ifndef _WTL_NO_RUNTIME_STRUCT_SIZE
\r
544 #ifndef _SIZEOF_STRUCT
\r
545 #define _SIZEOF_STRUCT(structname, member) (((int)((LPBYTE)(&((structname*)0)->member) - ((LPBYTE)((structname*)0)))) + sizeof(((structname*)0)->member))
\r
548 #if (_WIN32_WINNT >= 0x0600) && !defined(REBARBANDINFO_V6_SIZE)
\r
549 #define REBARBANDINFO_V6_SIZE _SIZEOF_STRUCT(REBARBANDINFO, cxHeader)
\r
550 #endif // (_WIN32_WINNT >= 0x0600) && !defined(REBARBANDINFO_V6_SIZE)
\r
552 #if (_WIN32_WINNT >= 0x0600) && !defined(LVGROUP_V5_SIZE)
\r
553 #define LVGROUP_V5_SIZE _SIZEOF_STRUCT(LVGROUP, uAlign)
\r
554 #endif // (_WIN32_WINNT >= 0x0600) && !defined(LVGROUP_V5_SIZE)
\r
556 #if (_WIN32_WINNT >= 0x0600) && !defined(LVTILEINFO_V5_SIZE)
\r
557 #define LVTILEINFO_V5_SIZE _SIZEOF_STRUCT(LVTILEINFO, puColumns)
\r
558 #endif // (_WIN32_WINNT >= 0x0600) && !defined(LVTILEINFO_V5_SIZE)
\r
560 #if defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN) && !defined(MCHITTESTINFO_V1_SIZE)
\r
561 #define MCHITTESTINFO_V1_SIZE _SIZEOF_STRUCT(MCHITTESTINFO, st)
\r
562 #endif // defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN) && !defined(MCHITTESTINFO_V1_SIZE)
\r
564 #if !defined(_WIN32_WCE) && (WINVER >= 0x0600) && !defined(NONCLIENTMETRICS_V1_SIZE)
\r
565 #define NONCLIENTMETRICS_V1_SIZE _SIZEOF_STRUCT(NONCLIENTMETRICS, lfMessageFont)
\r
566 #endif // !defined(_WIN32_WCE) && (WINVER >= 0x0600) && !defined(NONCLIENTMETRICS_V1_SIZE)
\r
568 #endif // !_WTL_NO_RUNTIME_STRUCT_SIZE
\r
570 namespace RunTimeHelper
\r
573 inline bool IsCommCtrl6()
\r
575 DWORD dwMajor = 0, dwMinor = 0;
\r
576 HRESULT hRet = ATL::AtlGetCommCtrlVersion(&dwMajor, &dwMinor);
\r
577 return (SUCCEEDED(hRet) && (dwMajor >= 6));
\r
580 inline bool IsVista()
\r
582 OSVERSIONINFO ovi = { sizeof(OSVERSIONINFO) };
\r
583 BOOL bRet = ::GetVersionEx(&ovi);
\r
584 return ((bRet != FALSE) && (ovi.dwMajorVersion >= 6));
\r
586 #endif // !_WIN32_WCE
\r
588 inline int SizeOf_REBARBANDINFO()
\r
590 int nSize = sizeof(REBARBANDINFO);
\r
591 #if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
\r
592 if(!(IsVista() && IsCommCtrl6()))
\r
593 nSize = REBARBANDINFO_V6_SIZE;
\r
594 #endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
\r
598 #if (_WIN32_WINNT >= 0x501)
\r
599 inline int SizeOf_LVGROUP()
\r
601 int nSize = sizeof(LVGROUP);
\r
602 #if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
\r
604 nSize = LVGROUP_V5_SIZE;
\r
605 #endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
\r
609 inline int SizeOf_LVTILEINFO()
\r
611 int nSize = sizeof(LVTILEINFO);
\r
612 #if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
\r
614 nSize = LVTILEINFO_V5_SIZE;
\r
615 #endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
\r
618 #endif // (_WIN32_WINNT >= 0x501)
\r
620 inline int SizeOf_MCHITTESTINFO()
\r
622 int nSize = sizeof(MCHITTESTINFO);
\r
623 #if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
\r
624 if(!(IsVista() && IsCommCtrl6()))
\r
625 nSize = MCHITTESTINFO_V1_SIZE;
\r
626 #endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
\r
631 inline int SizeOf_NONCLIENTMETRICS()
\r
633 int nSize = sizeof(NONCLIENTMETRICS);
\r
634 #if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (WINVER >= 0x0600)
\r
636 nSize = NONCLIENTMETRICS_V1_SIZE;
\r
637 #endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (WINVER >= 0x0600)
\r
640 #endif // !_WIN32_WCE
\r
644 ///////////////////////////////////////////////////////////////////////////////
\r
645 // ModuleHelper - helper functions for ATL3 and ATL7 module classes
\r
647 namespace ModuleHelper
\r
649 inline HINSTANCE GetModuleInstance()
\r
651 #if (_ATL_VER >= 0x0700)
\r
652 return ATL::_AtlBaseModule.GetModuleInstance();
\r
653 #else // !(_ATL_VER >= 0x0700)
\r
654 return ATL::_pModule->GetModuleInstance();
\r
655 #endif // !(_ATL_VER >= 0x0700)
\r
658 inline HINSTANCE GetResourceInstance()
\r
660 #if (_ATL_VER >= 0x0700)
\r
661 return ATL::_AtlBaseModule.GetResourceInstance();
\r
662 #else // !(_ATL_VER >= 0x0700)
\r
663 return ATL::_pModule->GetResourceInstance();
\r
664 #endif // !(_ATL_VER >= 0x0700)
\r
667 inline void AddCreateWndData(ATL::_AtlCreateWndData* pData, void* pObject)
\r
669 #if (_ATL_VER >= 0x0700)
\r
670 ATL::_AtlWinModule.AddCreateWndData(pData, pObject);
\r
671 #else // !(_ATL_VER >= 0x0700)
\r
672 ATL::_pModule->AddCreateWndData(pData, pObject);
\r
673 #endif // !(_ATL_VER >= 0x0700)
\r
676 inline void* ExtractCreateWndData()
\r
678 #if (_ATL_VER >= 0x0700)
\r
679 return ATL::_AtlWinModule.ExtractCreateWndData();
\r
680 #else // !(_ATL_VER >= 0x0700)
\r
681 return ATL::_pModule->ExtractCreateWndData();
\r
682 #endif // !(_ATL_VER >= 0x0700)
\r
687 ///////////////////////////////////////////////////////////////////////////////
\r
688 // SecureHelper - helper functions for VS2005 secure CRT
\r
690 namespace SecureHelper
\r
692 inline void strcpyA_x(char* lpstrDest, size_t cchDest, const char* lpstrSrc)
\r
695 ATL::Checked::strcpy_s(lpstrDest, cchDest, lpstrSrc);
\r
697 if(cchDest > (size_t)lstrlenA(lpstrSrc))
\r
698 ATLVERIFY(lstrcpyA(lpstrDest, lpstrSrc) != NULL);
\r
704 inline void strcpyW_x(wchar_t* lpstrDest, size_t cchDest, const wchar_t* lpstrSrc)
\r
707 ATL::Checked::wcscpy_s(lpstrDest, cchDest, lpstrSrc);
\r
709 if(cchDest > (size_t)lstrlenW(lpstrSrc))
\r
710 ATLVERIFY(lstrcpyW(lpstrDest, lpstrSrc) != NULL);
\r
716 inline void strcpy_x(LPTSTR lpstrDest, size_t cchDest, LPCTSTR lpstrSrc)
\r
719 strcpyW_x(lpstrDest, cchDest, lpstrSrc);
\r
721 strcpyA_x(lpstrDest, cchDest, lpstrSrc);
\r
725 inline errno_t strncpyA_x(char* lpstrDest, size_t cchDest, const char* lpstrSrc, size_t cchCount)
\r
728 return ATL::Checked::strncpy_s(lpstrDest, cchDest, lpstrSrc, cchCount);
\r
731 if(lpstrDest == NULL || cchDest == 0 || lpstrSrc == NULL)
\r
735 else if(cchCount == _TRUNCATE)
\r
737 cchCount = min(cchDest - 1, size_t(lstrlenA(lpstrSrc)));
\r
740 else if(cchDest <= cchCount)
\r
745 if(nRet == 0 || nRet == STRUNCATE)
\r
746 nRet = (lstrcpynA(lpstrDest, lpstrSrc, (int)cchCount + 1) != NULL) ? nRet : EINVAL;
\r
747 ATLASSERT(nRet == 0 || nRet == STRUNCATE);
\r
752 inline errno_t strncpyW_x(wchar_t* lpstrDest, size_t cchDest, const wchar_t* lpstrSrc, size_t cchCount)
\r
755 return ATL::Checked::wcsncpy_s(lpstrDest, cchDest, lpstrSrc, cchCount);
\r
758 if(lpstrDest == NULL || cchDest == 0 || lpstrSrc == NULL)
\r
762 else if(cchCount == _TRUNCATE)
\r
764 cchCount = min(cchDest - 1, size_t(lstrlenW(lpstrSrc)));
\r
767 else if(cchDest <= cchCount)
\r
772 if(nRet == 0 || nRet == STRUNCATE)
\r
773 nRet = (lstrcpynW(lpstrDest, lpstrSrc, (int)cchCount + 1) != NULL) ? nRet : EINVAL;
\r
774 ATLASSERT(nRet == 0 || nRet == STRUNCATE);
\r
779 inline errno_t strncpy_x(LPTSTR lpstrDest, size_t cchDest, LPCTSTR lpstrSrc, size_t cchCount)
\r
782 return strncpyW_x(lpstrDest, cchDest, lpstrSrc, cchCount);
\r
784 return strncpyA_x(lpstrDest, cchDest, lpstrSrc, cchCount);
\r
788 inline void strcatA_x(char* lpstrDest, size_t cchDest, const char* lpstrSrc)
\r
791 ATL::Checked::strcat_s(lpstrDest, cchDest, lpstrSrc);
\r
793 if(cchDest > (size_t)lstrlenA(lpstrSrc))
\r
794 ATLVERIFY(lstrcatA(lpstrDest, lpstrSrc) != NULL);
\r
800 inline void strcatW_x(wchar_t* lpstrDest, size_t cchDest, const wchar_t* lpstrSrc)
\r
803 ATL::Checked::wcscat_s(lpstrDest, cchDest, lpstrSrc);
\r
805 if(cchDest > (size_t)lstrlenW(lpstrSrc))
\r
806 ATLVERIFY(lstrcatW(lpstrDest, lpstrSrc) != NULL);
\r
812 inline void strcat_x(LPTSTR lpstrDest, size_t cchDest, LPCTSTR lpstrSrc)
\r
815 strcatW_x(lpstrDest, cchDest, lpstrSrc);
\r
817 strcatA_x(lpstrDest, cchDest, lpstrSrc);
\r
821 inline void memcpy_x(void* pDest, size_t cbDest, const void* pSrc, size_t cbSrc)
\r
824 ATL::Checked::memcpy_s(pDest, cbDest, pSrc, cbSrc);
\r
826 if(cbDest >= cbSrc)
\r
827 memcpy(pDest, pSrc, cbSrc);
\r
833 inline void memmove_x(void* pDest, size_t cbDest, const void* pSrc, size_t cbSrc)
\r
836 ATL::Checked::memmove_s(pDest, cbDest, pSrc, cbSrc);
\r
838 if(cbDest >= cbSrc)
\r
839 memmove(pDest, pSrc, cbSrc);
\r
845 inline int vsprintf_x(LPTSTR lpstrBuff, size_t cchBuff, LPCTSTR lpstrFormat, va_list args)
\r
847 #if _SECURE_ATL && !defined(_ATL_MIN_CRT) && !defined(_WIN32_WCE)
\r
848 return _vstprintf_s(lpstrBuff, cchBuff, lpstrFormat, args);
\r
850 cchBuff; // Avoid unused argument warning
\r
851 return _vstprintf(lpstrBuff, lpstrFormat, args);
\r
855 inline int wvsprintf_x(LPTSTR lpstrBuff, size_t cchBuff, LPCTSTR lpstrFormat, va_list args)
\r
857 #if _SECURE_ATL && !defined(_ATL_MIN_CRT) && !defined(_WIN32_WCE)
\r
858 return _vstprintf_s(lpstrBuff, cchBuff, lpstrFormat, args);
\r
860 cchBuff; // Avoid unused argument warning
\r
861 return ::wvsprintf(lpstrBuff, lpstrFormat, args);
\r
865 inline int sprintf_x(LPTSTR lpstrBuff, size_t cchBuff, LPCTSTR lpstrFormat, ...)
\r
868 va_start(args, lpstrFormat);
\r
869 int nRes = vsprintf_x(lpstrBuff, cchBuff, lpstrFormat, args);
\r
874 inline int wsprintf_x(LPTSTR lpstrBuff, size_t cchBuff, LPCTSTR lpstrFormat, ...)
\r
877 va_start(args, lpstrFormat);
\r
878 int nRes = wvsprintf_x(lpstrBuff, cchBuff, lpstrFormat, args);
\r
882 }; // namespace SecureHelper
\r
885 ///////////////////////////////////////////////////////////////////////////////
\r
886 // CMessageFilter - Interface for message filter support
\r
888 class CMessageFilter
\r
891 virtual BOOL PreTranslateMessage(MSG* pMsg) = 0;
\r
895 ///////////////////////////////////////////////////////////////////////////////
\r
896 // CIdleHandler - Interface for idle processing
\r
901 virtual BOOL OnIdle() = 0;
\r
904 #ifndef _ATL_NO_OLD_NAMES
\r
905 // for compatilibility with old names only
\r
906 typedef CIdleHandler CUpdateUIObject;
\r
907 #define DoUpdate OnIdle
\r
908 #endif // !_ATL_NO_OLD_NAMES
\r
911 ///////////////////////////////////////////////////////////////////////////////
\r
912 // CMessageLoop - message loop implementation
\r
917 ATL::CSimpleArray<CMessageFilter*> m_aMsgFilter;
\r
918 ATL::CSimpleArray<CIdleHandler*> m_aIdleHandler;
\r
921 // Message filter operations
\r
922 BOOL AddMessageFilter(CMessageFilter* pMessageFilter)
\r
924 return m_aMsgFilter.Add(pMessageFilter);
\r
927 BOOL RemoveMessageFilter(CMessageFilter* pMessageFilter)
\r
929 return m_aMsgFilter.Remove(pMessageFilter);
\r
932 // Idle handler operations
\r
933 BOOL AddIdleHandler(CIdleHandler* pIdleHandler)
\r
935 return m_aIdleHandler.Add(pIdleHandler);
\r
938 BOOL RemoveIdleHandler(CIdleHandler* pIdleHandler)
\r
940 return m_aIdleHandler.Remove(pIdleHandler);
\r
943 #ifndef _ATL_NO_OLD_NAMES
\r
944 // for compatilibility with old names only
\r
945 BOOL AddUpdateUI(CIdleHandler* pIdleHandler)
\r
947 ATLTRACE2(atlTraceUI, 0, _T("CUpdateUIObject and AddUpdateUI are deprecated. Please change your code to use CIdleHandler and OnIdle\n"));
\r
948 return AddIdleHandler(pIdleHandler);
\r
951 BOOL RemoveUpdateUI(CIdleHandler* pIdleHandler)
\r
953 ATLTRACE2(atlTraceUI, 0, _T("CUpdateUIObject and RemoveUpdateUI are deprecated. Please change your code to use CIdleHandler and OnIdle\n"));
\r
954 return RemoveIdleHandler(pIdleHandler);
\r
956 #endif // !_ATL_NO_OLD_NAMES
\r
961 BOOL bDoIdle = TRUE;
\r
962 int nIdleCount = 0;
\r
967 while(bDoIdle && !::PeekMessage(&m_msg, NULL, 0, 0, PM_NOREMOVE))
\r
969 if(!OnIdle(nIdleCount++))
\r
973 bRet = ::GetMessage(&m_msg, NULL, 0, 0);
\r
977 ATLTRACE2(atlTraceUI, 0, _T("::GetMessage returned -1 (error)\n"));
\r
978 continue; // error, don't process
\r
982 ATLTRACE2(atlTraceUI, 0, _T("CMessageLoop::Run - exiting\n"));
\r
983 break; // WM_QUIT, exit message loop
\r
986 if(!PreTranslateMessage(&m_msg))
\r
988 ::TranslateMessage(&m_msg);
\r
989 ::DispatchMessage(&m_msg);
\r
992 if(IsIdleMessage(&m_msg))
\r
999 return (int)m_msg.wParam;
\r
1002 static BOOL IsIdleMessage(MSG* pMsg)
\r
1004 // These messages should NOT cause idle processing
\r
1005 switch(pMsg->message)
\r
1007 case WM_MOUSEMOVE:
\r
1008 #ifndef _WIN32_WCE
\r
1009 case WM_NCMOUSEMOVE:
\r
1010 #endif // !_WIN32_WCE
\r
1012 case 0x0118: // WM_SYSTIMER (caret blink)
\r
1020 // Override to change message filtering
\r
1021 virtual BOOL PreTranslateMessage(MSG* pMsg)
\r
1024 for(int i = m_aMsgFilter.GetSize() - 1; i >= 0; i--)
\r
1026 CMessageFilter* pMessageFilter = m_aMsgFilter[i];
\r
1027 if(pMessageFilter != NULL && pMessageFilter->PreTranslateMessage(pMsg))
\r
1030 return FALSE; // not translated
\r
1033 // override to change idle processing
\r
1034 virtual BOOL OnIdle(int /*nIdleCount*/)
\r
1036 for(int i = 0; i < m_aIdleHandler.GetSize(); i++)
\r
1038 CIdleHandler* pIdleHandler = m_aIdleHandler[i];
\r
1039 if(pIdleHandler != NULL)
\r
1040 pIdleHandler->OnIdle();
\r
1042 return FALSE; // don't continue
\r
1047 ///////////////////////////////////////////////////////////////////////////////
\r
1048 // CStaticDataInitCriticalSectionLock and CWindowCreateCriticalSectionLock
\r
1049 // internal classes to manage critical sections for both ATL3 and ATL7
\r
1051 class CStaticDataInitCriticalSectionLock
\r
1054 #if (_ATL_VER >= 0x0700)
\r
1055 ATL::CComCritSecLock<ATL::CComCriticalSection> m_cslock;
\r
1057 CStaticDataInitCriticalSectionLock() : m_cslock(ATL::_pAtlModule->m_csStaticDataInitAndTypeInfo, false)
\r
1059 #endif // (_ATL_VER >= 0x0700)
\r
1063 #if (_ATL_VER >= 0x0700)
\r
1064 return m_cslock.Lock();
\r
1065 #else // !(_ATL_VER >= 0x0700)
\r
1066 ::EnterCriticalSection(&ATL::_pModule->m_csStaticDataInit);
\r
1068 #endif // !(_ATL_VER >= 0x0700)
\r
1073 #if (_ATL_VER >= 0x0700)
\r
1074 m_cslock.Unlock();
\r
1075 #else // !(_ATL_VER >= 0x0700)
\r
1076 ::LeaveCriticalSection(&ATL::_pModule->m_csStaticDataInit);
\r
1077 #endif // !(_ATL_VER >= 0x0700)
\r
1082 class CWindowCreateCriticalSectionLock
\r
1085 #if (_ATL_VER >= 0x0700)
\r
1086 ATL::CComCritSecLock<ATL::CComCriticalSection> m_cslock;
\r
1088 CWindowCreateCriticalSectionLock() : m_cslock(ATL::_AtlWinModule.m_csWindowCreate, false)
\r
1090 #endif // (_ATL_VER >= 0x0700)
\r
1094 #if (_ATL_VER >= 0x0700)
\r
1095 return m_cslock.Lock();
\r
1096 #else // !(_ATL_VER >= 0x0700)
\r
1097 ::EnterCriticalSection(&ATL::_pModule->m_csWindowCreate);
\r
1099 #endif // !(_ATL_VER >= 0x0700)
\r
1104 #if (_ATL_VER >= 0x0700)
\r
1105 m_cslock.Unlock();
\r
1106 #else // !(_ATL_VER >= 0x0700)
\r
1107 ::LeaveCriticalSection(&ATL::_pModule->m_csWindowCreate);
\r
1108 #endif // !(_ATL_VER >= 0x0700)
\r
1113 ///////////////////////////////////////////////////////////////////////////////
\r
1114 // CTempBuffer - helper class for stack allocations for ATL3
\r
1116 #ifndef _WTL_STACK_ALLOC_THRESHOLD
\r
1117 #define _WTL_STACK_ALLOC_THRESHOLD 512
\r
1120 #if (_ATL_VER >= 0x0700)
\r
1122 using ATL::CTempBuffer;
\r
1124 #else // !(_ATL_VER >= 0x0700)
\r
1128 #define SIZE_MAX _UI64_MAX
\r
1130 #define SIZE_MAX UINT_MAX
\r
1134 #pragma warning(disable: 4284) // warning for operator ->
\r
1136 template<typename T, int t_nFixedBytes = 128>
\r
1140 CTempBuffer() : m_p(NULL)
\r
1144 CTempBuffer(size_t nElements) : m_p(NULL)
\r
1146 Allocate(nElements);
\r
1151 if(m_p != reinterpret_cast<T*>(m_abFixedBuffer))
\r
1155 operator T*() const
\r
1160 T* operator ->() const
\r
1162 ATLASSERT(m_p != NULL);
\r
1166 T* Allocate(size_t nElements)
\r
1168 ATLASSERT(nElements <= (SIZE_MAX / sizeof(T)));
\r
1169 return AllocateBytes(nElements * sizeof(T));
\r
1172 T* AllocateBytes(size_t nBytes)
\r
1174 ATLASSERT(m_p == NULL);
\r
1175 if(nBytes > t_nFixedBytes)
\r
1176 m_p = static_cast<T*>(malloc(nBytes));
\r
1178 m_p = reinterpret_cast<T*>(m_abFixedBuffer);
\r
1185 BYTE m_abFixedBuffer[t_nFixedBytes];
\r
1188 #pragma warning(default: 4284)
\r
1190 #endif // !(_ATL_VER >= 0x0700)
\r
1193 ///////////////////////////////////////////////////////////////////////////////
\r
1194 // CAppModule - module class for an application
\r
1196 class CAppModule : public ATL::CComModule
\r
1199 DWORD m_dwMainThreadID;
\r
1200 ATL::CSimpleMap<DWORD, CMessageLoop*>* m_pMsgLoopMap;
\r
1201 ATL::CSimpleArray<HWND>* m_pSettingChangeNotify;
\r
1203 // Overrides of CComModule::Init and Term
\r
1204 HRESULT Init(ATL::_ATL_OBJMAP_ENTRY* pObjMap, HINSTANCE hInstance, const GUID* pLibID = NULL)
\r
1206 HRESULT hRet = CComModule::Init(pObjMap, hInstance, pLibID);
\r
1210 m_dwMainThreadID = ::GetCurrentThreadId();
\r
1211 typedef ATL::CSimpleMap<DWORD, CMessageLoop*> _mapClass;
\r
1212 m_pMsgLoopMap = NULL;
\r
1213 ATLTRY(m_pMsgLoopMap = new _mapClass);
\r
1214 if(m_pMsgLoopMap == NULL)
\r
1215 return E_OUTOFMEMORY;
\r
1216 m_pSettingChangeNotify = NULL;
\r
1223 TermSettingChangeNotify();
\r
1224 delete m_pMsgLoopMap;
\r
1225 CComModule::Term();
\r
1228 // Message loop map methods
\r
1229 BOOL AddMessageLoop(CMessageLoop* pMsgLoop)
\r
1231 CStaticDataInitCriticalSectionLock lock;
\r
1232 if(FAILED(lock.Lock()))
\r
1234 ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CAppModule::AddMessageLoop.\n"));
\r
1239 ATLASSERT(pMsgLoop != NULL);
\r
1240 ATLASSERT(m_pMsgLoopMap->Lookup(::GetCurrentThreadId()) == NULL); // not in map yet
\r
1242 BOOL bRet = m_pMsgLoopMap->Add(::GetCurrentThreadId(), pMsgLoop);
\r
1249 BOOL RemoveMessageLoop()
\r
1251 CStaticDataInitCriticalSectionLock lock;
\r
1252 if(FAILED(lock.Lock()))
\r
1254 ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CAppModule::RemoveMessageLoop.\n"));
\r
1259 BOOL bRet = m_pMsgLoopMap->Remove(::GetCurrentThreadId());
\r
1266 CMessageLoop* GetMessageLoop(DWORD dwThreadID = ::GetCurrentThreadId()) const
\r
1268 CStaticDataInitCriticalSectionLock lock;
\r
1269 if(FAILED(lock.Lock()))
\r
1271 ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CAppModule::GetMessageLoop.\n"));
\r
1276 CMessageLoop* pLoop = m_pMsgLoopMap->Lookup(dwThreadID);
\r
1283 // Setting change notify methods
\r
1284 // Note: Call this from the main thread for MSDI apps
\r
1285 BOOL InitSettingChangeNotify(DLGPROC pfnDlgProc = _SettingChangeDlgProc)
\r
1287 CStaticDataInitCriticalSectionLock lock;
\r
1288 if(FAILED(lock.Lock()))
\r
1290 ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CAppModule::InitSettingChangeNotify.\n"));
\r
1295 if(m_pSettingChangeNotify == NULL)
\r
1297 typedef ATL::CSimpleArray<HWND> _notifyClass;
\r
1298 ATLTRY(m_pSettingChangeNotify = new _notifyClass);
\r
1299 ATLASSERT(m_pSettingChangeNotify != NULL);
\r
1302 BOOL bRet = (m_pSettingChangeNotify != NULL);
\r
1303 if(bRet && m_pSettingChangeNotify->GetSize() == 0)
\r
1305 // init everything
\r
1306 _ATL_EMPTY_DLGTEMPLATE templ;
\r
1307 HWND hNtfWnd = ::CreateDialogIndirect(GetModuleInstance(), &templ, NULL, pfnDlgProc);
\r
1308 ATLASSERT(::IsWindow(hNtfWnd));
\r
1309 if(::IsWindow(hNtfWnd))
\r
1311 // need conditional code because types don't match in winuser.h
\r
1313 ::SetWindowLongPtr(hNtfWnd, GWLP_USERDATA, (LONG_PTR)this);
\r
1315 ::SetWindowLongPtr(hNtfWnd, GWLP_USERDATA, PtrToLong(this));
\r
1317 bRet = m_pSettingChangeNotify->Add(hNtfWnd);
\r
1330 void TermSettingChangeNotify()
\r
1332 CStaticDataInitCriticalSectionLock lock;
\r
1333 if(FAILED(lock.Lock()))
\r
1335 ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CAppModule::TermSettingChangeNotify.\n"));
\r
1340 if(m_pSettingChangeNotify != NULL && m_pSettingChangeNotify->GetSize() > 0)
\r
1341 ::DestroyWindow((*m_pSettingChangeNotify)[0]);
\r
1342 delete m_pSettingChangeNotify;
\r
1343 m_pSettingChangeNotify = NULL;
\r
1348 BOOL AddSettingChangeNotify(HWND hWnd)
\r
1350 CStaticDataInitCriticalSectionLock lock;
\r
1351 if(FAILED(lock.Lock()))
\r
1353 ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CAppModule::AddSettingChangeNotify.\n"));
\r
1358 ATLASSERT(::IsWindow(hWnd));
\r
1359 BOOL bRet = FALSE;
\r
1360 if(InitSettingChangeNotify() != FALSE)
\r
1361 bRet = m_pSettingChangeNotify->Add(hWnd);
\r
1368 BOOL RemoveSettingChangeNotify(HWND hWnd)
\r
1370 CStaticDataInitCriticalSectionLock lock;
\r
1371 if(FAILED(lock.Lock()))
\r
1373 ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CAppModule::RemoveSettingChangeNotify.\n"));
\r
1378 BOOL bRet = FALSE;
\r
1379 if(m_pSettingChangeNotify != NULL)
\r
1380 bRet = m_pSettingChangeNotify->Remove(hWnd);
\r
1387 // Implementation - setting change notify dialog template and dialog procedure
\r
1388 struct _ATL_EMPTY_DLGTEMPLATE : DLGTEMPLATE
\r
1390 _ATL_EMPTY_DLGTEMPLATE()
\r
1392 memset(this, 0, sizeof(_ATL_EMPTY_DLGTEMPLATE));
\r
1395 WORD wMenu, wClass, wTitle;
\r
1399 static INT_PTR CALLBACK _SettingChangeDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
1401 static BOOL CALLBACK _SettingChangeDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
1404 if(uMsg == WM_SETTINGCHANGE)
\r
1406 // need conditional code because types don't match in winuser.h
\r
1408 CAppModule* pModule = (CAppModule*)::GetWindowLongPtr(hWnd, GWLP_USERDATA);
\r
1410 CAppModule* pModule = (CAppModule*)LongToPtr(::GetWindowLongPtr(hWnd, GWLP_USERDATA));
\r
1412 ATLASSERT(pModule != NULL);
\r
1413 ATLASSERT(pModule->m_pSettingChangeNotify != NULL);
\r
1414 const UINT uTimeout = 1500; // ms
\r
1415 for(int i = 1; i < pModule->m_pSettingChangeNotify->GetSize(); i++)
\r
1417 #if !defined(_WIN32_WCE)
\r
1418 ::SendMessageTimeout((*pModule->m_pSettingChangeNotify)[i], uMsg, wParam, lParam, SMTO_ABORTIFHUNG, uTimeout, NULL);
\r
1419 #elif(_WIN32_WCE >= 400) // CE specific
\r
1420 ::SendMessageTimeout((*pModule->m_pSettingChangeNotify)[i], uMsg, wParam, lParam, SMTO_NORMAL, uTimeout, NULL);
\r
1421 #else // _WIN32_WCE < 400 specific
\r
1423 ::SendMessage((*pModule->m_pSettingChangeNotify)[i], uMsg, wParam, lParam);
\r
1433 ///////////////////////////////////////////////////////////////////////////////
\r
1434 // CServerAppModule - module class for a COM server application
\r
1436 class CServerAppModule : public CAppModule
\r
1439 HANDLE m_hEventShutdown;
\r
1441 DWORD m_dwTimeOut;
\r
1444 // Override of CAppModule::Init
\r
1445 HRESULT Init(ATL::_ATL_OBJMAP_ENTRY* pObjMap, HINSTANCE hInstance, const GUID* pLibID = NULL)
\r
1447 m_dwTimeOut = 5000;
\r
1449 return CAppModule::Init(pObjMap, hInstance, pLibID);
\r
1454 if(m_hEventShutdown != NULL && ::CloseHandle(m_hEventShutdown))
\r
1455 m_hEventShutdown = NULL;
\r
1456 CAppModule::Term();
\r
1459 // COM Server methods
\r
1462 LONG lRet = CComModule::Unlock();
\r
1465 m_bActivity = true;
\r
1466 ::SetEvent(m_hEventShutdown); // tell monitor that we transitioned to zero
\r
1471 void MonitorShutdown()
\r
1475 ::WaitForSingleObject(m_hEventShutdown, INFINITE);
\r
1479 m_bActivity = false;
\r
1480 dwWait = ::WaitForSingleObject(m_hEventShutdown, m_dwTimeOut);
\r
1482 while(dwWait == WAIT_OBJECT_0);
\r
1484 if(!m_bActivity && m_nLockCnt == 0) // if no activity let's really bail
\r
1486 #if ((_WIN32_WINNT >= 0x0400 ) || defined(_WIN32_DCOM)) && defined(_ATL_FREE_THREADED) && !defined(_WIN32_WCE)
\r
1487 ::CoSuspendClassObjects();
\r
1488 if(!m_bActivity && m_nLockCnt == 0)
\r
1493 // This handle should be valid now. If it isn't,
\r
1494 // check if _Module.Term was called first (it shouldn't)
\r
1495 if(::CloseHandle(m_hEventShutdown))
\r
1496 m_hEventShutdown = NULL;
\r
1497 ::PostThreadMessage(m_dwMainThreadID, WM_QUIT, 0, 0);
\r
1500 bool StartMonitor()
\r
1502 m_hEventShutdown = ::CreateEvent(NULL, false, false, NULL);
\r
1503 if(m_hEventShutdown == NULL)
\r
1505 DWORD dwThreadID = 0;
\r
1506 #if !defined(_ATL_MIN_CRT) && defined(_MT) && !defined(_WIN32_WCE)
\r
1507 HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0, (UINT (WINAPI*)(void*))MonitorProc, this, 0, (UINT*)&dwThreadID);
\r
1509 HANDLE hThread = ::CreateThread(NULL, 0, MonitorProc, this, 0, &dwThreadID);
\r
1511 bool bRet = (hThread != NULL);
\r
1513 ::CloseHandle(hThread);
\r
1517 static DWORD WINAPI MonitorProc(void* pv)
\r
1519 CServerAppModule* p = (CServerAppModule*)pv;
\r
1520 p->MonitorShutdown();
\r
1524 #if (_ATL_VER < 0x0700)
\r
1525 // search for an occurence of string p2 in string p1
\r
1526 static LPCTSTR FindOneOf(LPCTSTR p1, LPCTSTR p2)
\r
1528 while(p1 != NULL && *p1 != NULL)
\r
1531 while(p != NULL && *p != NULL)
\r
1534 return ::CharNext(p1);
\r
1535 p = ::CharNext(p);
\r
1537 p1 = ::CharNext(p1);
\r
1541 #endif // (_ATL_VER < 0x0700)
\r
1545 ///////////////////////////////////////////////////////////////////////////////
\r
1546 // CString forward reference (enables CString use in atluser.h and atlgdi.h)
\r
1548 #if defined(_WTL_FORWARD_DECLARE_CSTRING) && !defined(_WTL_USE_CSTRING)
\r
1549 #define _WTL_USE_CSTRING
\r
1550 #endif // defined(_WTL_FORWARD_DECLARE_CSTRING) && !defined(_WTL_USE_CSTRING)
\r
1552 #ifdef _WTL_USE_CSTRING
\r
1553 class CString; // forward declaration (include atlmisc.h for the whole class)
\r
1554 #endif // _WTL_USE_CSTRING
\r
1556 // CString namespace
\r
1557 #ifndef _CSTRING_NS
\r
1558 #ifdef __ATLSTR_H__
\r
1559 #define _CSTRING_NS ATL
\r
1561 #define _CSTRING_NS WTL
\r
1563 #endif // _CSTRING_NS
\r
1565 // Type classes namespace
\r
1566 #ifndef _WTYPES_NS
\r
1567 #ifdef __ATLTYPES_H__
\r
1568 #define _WTYPES_NS
\r
1570 #define _WTYPES_NS WTL
\r
1572 #endif // _WTYPES_NS
\r
1574 }; // namespace WTL
\r
1577 ///////////////////////////////////////////////////////////////////////////////
\r
1578 // General DLL version helpers (excluded from atlbase.h if _ATL_DLL is defined)
\r
1580 #if (_ATL_VER < 0x0700) && defined(_ATL_DLL) && !defined(_WIN32_WCE)
\r
1585 inline HRESULT AtlGetDllVersion(HINSTANCE hInstDLL, DLLVERSIONINFO* pDllVersionInfo)
\r
1587 ATLASSERT(pDllVersionInfo != NULL);
\r
1588 if(pDllVersionInfo == NULL)
\r
1589 return E_INVALIDARG;
\r
1591 // We must get this function explicitly because some DLLs don't implement it.
\r
1592 DLLGETVERSIONPROC pfnDllGetVersion = (DLLGETVERSIONPROC)::GetProcAddress(hInstDLL, "DllGetVersion");
\r
1593 if(pfnDllGetVersion == NULL)
\r
1596 return (*pfnDllGetVersion)(pDllVersionInfo);
\r
1599 inline HRESULT AtlGetDllVersion(LPCTSTR lpstrDllName, DLLVERSIONINFO* pDllVersionInfo)
\r
1601 HINSTANCE hInstDLL = ::LoadLibrary(lpstrDllName);
\r
1602 if(hInstDLL == NULL)
\r
1604 HRESULT hRet = AtlGetDllVersion(hInstDLL, pDllVersionInfo);
\r
1605 ::FreeLibrary(hInstDLL);
\r
1609 // Common Control Versions:
\r
1610 // Win95/WinNT 4.0 maj=4 min=00
\r
1611 // IE 3.x maj=4 min=70
\r
1612 // IE 4.0 maj=4 min=71
\r
1613 inline HRESULT AtlGetCommCtrlVersion(LPDWORD pdwMajor, LPDWORD pdwMinor)
\r
1615 ATLASSERT(pdwMajor != NULL && pdwMinor != NULL);
\r
1616 if(pdwMajor == NULL || pdwMinor == NULL)
\r
1617 return E_INVALIDARG;
\r
1619 DLLVERSIONINFO dvi;
\r
1620 ::ZeroMemory(&dvi, sizeof(dvi));
\r
1621 dvi.cbSize = sizeof(dvi);
\r
1622 HRESULT hRet = AtlGetDllVersion(_T("comctl32.dll"), &dvi);
\r
1624 if(SUCCEEDED(hRet))
\r
1626 *pdwMajor = dvi.dwMajorVersion;
\r
1627 *pdwMinor = dvi.dwMinorVersion;
\r
1629 else if(hRet == E_NOTIMPL)
\r
1631 // If DllGetVersion is not there, then the DLL is a version
\r
1632 // previous to the one shipped with IE 3.x
\r
1641 // Shell Versions:
\r
1642 // Win95/WinNT 4.0 maj=4 min=00
\r
1643 // IE 3.x, IE 4.0 without Web Integrated Desktop maj=4 min=00
\r
1644 // IE 4.0 with Web Integrated Desktop maj=4 min=71
\r
1645 // IE 4.01 with Web Integrated Desktop maj=4 min=72
\r
1646 inline HRESULT AtlGetShellVersion(LPDWORD pdwMajor, LPDWORD pdwMinor)
\r
1648 ATLASSERT(pdwMajor != NULL && pdwMinor != NULL);
\r
1649 if(pdwMajor == NULL || pdwMinor == NULL)
\r
1650 return E_INVALIDARG;
\r
1652 DLLVERSIONINFO dvi;
\r
1653 ::ZeroMemory(&dvi, sizeof(dvi));
\r
1654 dvi.cbSize = sizeof(dvi);
\r
1655 HRESULT hRet = AtlGetDllVersion(_T("shell32.dll"), &dvi);
\r
1657 if(SUCCEEDED(hRet))
\r
1659 *pdwMajor = dvi.dwMajorVersion;
\r
1660 *pdwMinor = dvi.dwMinorVersion;
\r
1662 else if(hRet == E_NOTIMPL)
\r
1664 // If DllGetVersion is not there, then the DLL is a version
\r
1665 // previous to the one shipped with IE 4.x
\r
1674 }; // namespace ATL
\r
1676 #endif // (_ATL_VER < 0x0700) && defined(_ATL_DLL) && !defined(_WIN32_WCE)
\r
1679 // These are always included
\r
1680 #include "atlwinx.h"
\r
1681 #include "atluser.h"
\r
1682 #include "atlgdi.h"
\r
1684 #ifndef _WTL_NO_AUTOMATIC_NAMESPACE
\r
1685 using namespace WTL;
\r
1686 #endif // !_WTL_NO_AUTOMATIC_NAMESPACE
\r
1688 #endif // __ATLAPP_H__
\r