15 #error WTL requires C++ compilation (use a .cpp suffix) 19 #error atlapp.h requires atlbase.h to be included first 24 #error WTL requires Windows version 4.0 or higher 27 #if (_WIN32_IE < 0x0300) 28 #error WTL requires IE version 3.0 or higher 32 #ifdef _ATL_NO_COMMODULE 33 #error WTL requires that _ATL_NO_COMMODULE is not defined 36 #if (_ATL_VER >= 0x0900) && defined(_ATL_MIN_CRT) 37 #error _ATL_MIN_CRT is not supported with ATL 9.0 and higher 40 #if defined(_WIN32_WCE) && defined(_ATL_MIN_CRT) 41 #pragma message("Warning: WTL for Windows CE doesn't use _ATL_MIN_CRT") 45 #if !defined(_ATL_MIN_CRT) && defined(_MT) && !defined(_WIN32_WCE) 49 #if (_ATL_VER < 0x0800) && !defined(_DEBUG) 55 #pragma comment(lib, "comctl32.lib") 58 #if defined(_SYSINFOAPI_H_) && defined(NOT_BUILD_WINDOWS_DEPRECATE) && (_WIN32_WINNT >= 0x0501) 59 #include <VersionHelpers.h> 69 #pragma warning(disable: 4127) 71 #if (_ATL_VER >= 0x0900) && !defined(_SECURE_ATL) 79 #define _WTL_VER 0x0910 106 #ifndef SW_SHOWDEFAULT 107 #define SW_SHOWDEFAULT SW_SHOWNORMAL 108 #endif // !SW_SHOWDEFAULT 112 #define LR_DEFAULTSIZE 0 113 #define LR_LOADFROMFILE 0 116 #define SM_CXCURSOR 13 119 #define SM_CYCURSOR 14 122 inline BOOL IsMenu(HMENU hMenu)
124 MENUITEMINFO mii = {
sizeof(MENUITEMINFO) };
126 BOOL bRet = ::GetMenuItemInfo(hMenu, 0, TRUE, &mii);
128 bRet = (::GetLastError() != ERROR_INVALID_MENU_HANDLE) ? TRUE : FALSE;
132 #if (_WIN32_WCE >= 410) 133 extern "C" void WINAPI ListView_SetItemSpacing(HWND hwndLV,
int iHeight);
134 #endif // (_WIN32_WCE >= 410) 136 inline int MulDiv(IN
int nNumber, IN
int nNumerator, IN
int nDenominator)
138 __int64 multiple = nNumber * nNumerator;
139 return static_cast<int>(multiple / nDenominator);
142 #if (_ATL_VER >= 0x0800) 144 #ifndef _WTL_KEEP_WS_OVERLAPPEDWINDOW 145 #ifdef WS_OVERLAPPEDWINDOW 146 #undef WS_OVERLAPPEDWINDOW 147 #define WS_OVERLAPPEDWINDOW 0 148 #endif // WS_OVERLAPPEDWINDOW 149 #endif // !_WTL_KEEP_WS_OVERLAPPEDWINDOW 155 #ifndef WM_WINDOWPOSCHANGING 156 #define WM_WINDOWPOSCHANGING 0 157 #endif // !WM_WINDOWPOSCHANGING 159 #define FreeResource(x) 160 #define UnlockResource(x) 164 inline HRESULT CComModule::RegisterClassObjects(DWORD , DWORD ) throw()
165 {
return E_NOTIMPL; }
166 inline HRESULT CComModule::RevokeClassObjects() throw()
167 {
return E_NOTIMPL; }
171 #define lstrlenW (int)ATL::lstrlenW 174 inline int WINAPI lstrlenA(LPCSTR lpszString)
175 {
return ATL::lstrlenA(lpszString); }
179 #define lstrcpyn ATL::lstrcpynW 182 #ifndef SetWindowLongPtrW 183 inline LONG_PTR tmp_SetWindowLongPtrW( HWND hWnd,
int nIndex, LONG_PTR dwNewLong )
185 return( ::SetWindowLongW( hWnd, nIndex, LONG( dwNewLong ) ) );
187 #define SetWindowLongPtrW tmp_SetWindowLongPtrW 190 #ifndef GetWindowLongPtrW 191 inline LONG_PTR tmp_GetWindowLongPtrW( HWND hWnd,
int nIndex )
193 return( ::GetWindowLongW( hWnd, nIndex ) );
195 #define GetWindowLongPtrW tmp_GetWindowLongPtrW 199 #define LongToPtr(x) ((void*)x) 203 #define PtrToInt( p ) ((INT)(INT_PTR) (p) ) 206 #else // !(_ATL_VER >= 0x0800) 210 #define lstrlenW (int)::wcslen 213 #define lstrlenA (int)strlen 216 inline LPTSTR lstrcpyn(LPTSTR lpstrDest, LPCTSTR lpstrSrc,
int nLength)
218 if(lpstrDest == NULL || lpstrSrc == NULL || nLength <= 0)
220 int nLen = __min(lstrlen(lpstrSrc), nLength - 1);
221 LPTSTR lpstrRet = (LPTSTR)memcpy(lpstrDest, lpstrSrc, nLen *
sizeof(TCHAR));
228 inline LPWSTR lstrcpynW(LPWSTR lpstrDest, LPCWSTR lpstrSrc,
int nLength)
230 return lstrcpyn(lpstrDest, lpstrSrc, nLength);
235 inline LPSTR lstrcpynA(LPSTR lpstrDest, LPCSTR lpstrSrc,
int nLength)
237 if(lpstrDest == NULL || lpstrSrc == NULL || nLength <= 0)
239 int nLen = __min(lstrlenA(lpstrSrc), nLength - 1);
240 LPSTR lpstrRet = (LPSTR)memcpy(lpstrDest, lpstrSrc, nLen *
sizeof(
char));
246 #ifdef TrackPopupMenu 247 #undef TrackPopupMenu 248 #endif // TrackPopupMenu 250 #define DECLARE_WND_CLASS_EX(WndClassName, style, bkgnd) \ 251 static CWndClassInfo& GetWndClassInfo() \ 253 static CWndClassInfo wc = \ 255 { style, StartWindowProc, \ 256 0, 0, NULL, NULL, NULL, (HBRUSH)(bkgnd + 1), NULL, WndClassName }, \ 257 NULL, NULL, IDC_ARROW, TRUE, 0, _T("") \ 263 #define _MAX_FNAME _MAX_PATH 266 #if (_WIN32_WCE < 400) 267 #define MAKEINTATOM(i) (LPTSTR)((ULONG_PTR)((WORD)(i))) 268 #endif // (_WIN32_WCE < 400) 270 #if (_WIN32_WCE < 410) 271 #define WHEEL_PAGESCROLL (UINT_MAX) 272 #define WHEEL_DELTA 120 273 #endif // (_WIN32_WCE < 410) 289 #define VARCMP_NULL 3 292 #ifndef RDW_ALLCHILDREN 293 #define RDW_ALLCHILDREN 0 296 #endif // !(_ATL_VER >= 0x0800) 304 #if (_MSC_VER < 1300) && !defined(_WIN32_WCE) 310 #define BS_PUSHBOX 0x0000000AL 313 struct __declspec(uuid("000214e6-0000-0000-c000-000000000046")) IShellFolder;
314 struct __declspec(uuid("000214f9-0000-0000-c000-000000000046")) IShellLinkW;
315 struct __declspec(uuid("000214ee-0000-0000-c000-000000000046")) IShellLinkA;
316 #endif // (_MSC_VER < 1300) && !defined(_WIN32_WCE) 318 #ifndef _ATL_NO_OLD_HEADERS_WIN64 319 #if !defined(_WIN64) && (_ATL_VER < 0x0700) 321 #ifndef PSM_INSERTPAGE 322 #define PSM_INSERTPAGE (WM_USER + 119) 323 #endif // !PSM_INSERTPAGE 325 #ifndef GetClassLongPtr 326 #define GetClassLongPtrA GetClassLongA 327 #define GetClassLongPtrW GetClassLongW 329 #define GetClassLongPtr GetClassLongPtrW 331 #define GetClassLongPtr GetClassLongPtrA 333 #endif // !GetClassLongPtr 336 #define GCLP_HICONSM (-34) 337 #endif // !GCLP_HICONSM 339 #ifndef GetWindowLongPtr 340 #define GetWindowLongPtrA GetWindowLongA 341 #define GetWindowLongPtrW GetWindowLongW 343 #define GetWindowLongPtr GetWindowLongPtrW 345 #define GetWindowLongPtr GetWindowLongPtrA 347 #endif // !GetWindowLongPtr 349 #ifndef SetWindowLongPtr 350 #define SetWindowLongPtrA SetWindowLongA 351 #define SetWindowLongPtrW SetWindowLongW 353 #define SetWindowLongPtr SetWindowLongPtrW 355 #define SetWindowLongPtr SetWindowLongPtrA 357 #endif // !SetWindowLongPtr 360 #define GWLP_WNDPROC (-4) 362 #ifndef GWLP_HINSTANCE 363 #define GWLP_HINSTANCE (-6) 365 #ifndef GWLP_HWNDPARENT 366 #define GWLP_HWNDPARENT (-8) 368 #ifndef GWLP_USERDATA 369 #define GWLP_USERDATA (-21) 372 #define GWLP_ID (-12) 375 #ifndef DWLP_MSGRESULT 376 #define DWLP_MSGRESULT 0 379 typedef long LONG_PTR;
380 typedef unsigned long ULONG_PTR;
381 typedef ULONG_PTR DWORD_PTR;
383 #ifndef HandleToUlong 384 #define HandleToUlong( h ) ((ULONG)(ULONG_PTR)(h) ) 387 #define HandleToLong( h ) ((LONG)(LONG_PTR) (h) ) 390 #define LongToHandle( h) ((HANDLE)(LONG_PTR) (h)) 393 #define PtrToUlong( p ) ((ULONG)(ULONG_PTR) (p) ) 396 #define PtrToLong( p ) ((LONG)(LONG_PTR) (p) ) 399 #define PtrToUint( p ) ((UINT)(UINT_PTR) (p) ) 402 #define PtrToInt( p ) ((INT)(INT_PTR) (p) ) 405 #define PtrToUshort( p ) ((unsigned short)(ULONG_PTR)(p) ) 408 #define PtrToShort( p ) ((short)(LONG_PTR)(p) ) 411 #define IntToPtr( i ) ((VOID *)(INT_PTR)((int)i)) 414 #define UIntToPtr( ui ) ((VOID *)(UINT_PTR)((unsigned int)ui)) 417 #define LongToPtr( l ) ((VOID *)(LONG_PTR)((long)l)) 420 #define ULongToPtr( ul ) ((VOID *)(ULONG_PTR)((unsigned long)ul)) 423 #endif // !defined(_WIN64) && (_ATL_VER < 0x0700) 424 #endif // !_ATL_NO_OLD_HEADERS_WIN64 430 #if (_MSC_VER >= 1300) && (_MSC_VER < 1400) 433 #define BS_PUSHBOX 0x0000000AL 436 #pragma warning(disable: 4244) // conversion from 'type1' to 'type2', possible loss of data 438 #endif // (_MSC_VER >= 1300) && (_MSC_VER < 1400) 445 #define BTNS_BUTTON TBSTYLE_BUTTON 449 #define BTNS_SEP TBSTYLE_SEP 453 #define BTNS_CHECK TBSTYLE_CHECK 457 #define BTNS_GROUP TBSTYLE_GROUP 460 #ifndef BTNS_CHECKGROUP 461 #define BTNS_CHECKGROUP TBSTYLE_CHECKGROUP 464 #if (_WIN32_IE >= 0x0300) 465 #ifndef BTNS_DROPDOWN 466 #define BTNS_DROPDOWN TBSTYLE_DROPDOWN 470 #if (_WIN32_IE >= 0x0400) 471 #ifndef BTNS_AUTOSIZE 472 #define BTNS_AUTOSIZE TBSTYLE_AUTOSIZE 475 #ifndef BTNS_NOPREFIX 476 #define BTNS_NOPREFIX TBSTYLE_NOPREFIX 485 #define _TRUNCATE ((size_t)-1) 488 #ifndef _ERRCODE_DEFINED 489 #define _ERRCODE_DEFINED 493 #ifndef _SECURECRT_ERRCODE_VALUES_DEFINED 494 #define _SECURECRT_ERRCODE_VALUES_DEFINED 500 #define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0])) 508 #ifndef IS_INTRESOURCE 509 #define IS_INTRESOURCE(_r) (((ULONG_PTR)(_r) >> 16) == 0) 510 #endif // IS_INTRESOURCE 514 #undef SubclassWindow 515 #endif // _INC_WINDOWSX 519 #define GET_X_LPARAM(lParam) ((int)(short)LOWORD(lParam)) 522 #define GET_Y_LPARAM(lParam) ((int)(short)HIWORD(lParam)) 526 #if (_MSC_VER >= 1300) && defined(_MANAGED) 527 __if_not_exists(_IMAGELIST::_IMAGELIST) {
struct _IMAGELIST { }; }
528 __if_not_exists(_TREEITEM::_TREEITEM) {
struct _TREEITEM { }; }
529 __if_not_exists(_PSP::_PSP) {
struct _PSP { }; }
533 #if (_ATL_VER < 0x0700) 536 #define ATLVERIFY(expr) ATLASSERT(expr) 538 #define ATLVERIFY(expr) (expr) 541 #endif // (_ATL_VER < 0x0700) 544 #if (((_ATL_VER < 0x0700) && defined(_ATL_DLL)) || (_ATL_VER >= 0x0B00)) && !defined(_WIN32_WCE) 545 namespace ATL { HRESULT AtlGetCommCtrlVersion(LPDWORD pdwMajor, LPDWORD pdwMinor); };
548 #ifndef WM_MOUSEHWHEEL 549 #define WM_MOUSEHWHEEL 0x020E 556 #if (_ATL_VER >= 0x0700) 557 DECLARE_TRACE_CATEGORY(atlTraceUI);
559 __declspec(selectany)
ATL::CTraceCategory atlTraceUI(_T("atlTraceUI"));
561 #else // !(_ATL_VER >= 0x0700) 564 atlTraceUI = 0x10000000
566 #endif // !(_ATL_VER >= 0x0700) 569 inline bool AtlIsOldWindows()
571 #ifdef _versionhelpers_H_INCLUDED_ 572 return !::IsWindowsVersionOrGreater(4, 90, 0);
573 #else // !_versionhelpers_H_INCLUDED_ 574 OSVERSIONINFO ovi = {
sizeof(OSVERSIONINFO) };
575 BOOL bRet = ::GetVersionEx(&ovi);
576 return (!bRet || !((ovi.dwMajorVersion >= 5) || (ovi.dwMajorVersion == 4 && ovi.dwMinorVersion >= 90)));
577 #endif // _versionhelpers_H_INCLUDED_ 581 inline HFONT AtlGetDefaultGuiFont()
584 return (HFONT)::GetStockObject(DEFAULT_GUI_FONT);
586 return (HFONT)::GetStockObject(SYSTEM_FONT);
592 inline HFONT AtlCreateControlFont()
596 ATLVERIFY(::SystemParametersInfo(SPI_GETICONTITLELOGFONT,
sizeof(LOGFONT), &lf, 0) != FALSE);
597 HFONT hFont = ::CreateFontIndirect(&lf);
598 ATLASSERT(hFont != NULL);
601 return (HFONT)::GetStockObject(SYSTEM_FONT);
607 inline HFONT AtlCreateBoldFont(HFONT hFont = NULL)
612 ATLVERIFY(::SystemParametersInfo(SPI_GETICONTITLELOGFONT,
sizeof(LOGFONT), &lf, 0) != FALSE);
614 ATLVERIFY(::GetObject(hFont,
sizeof(LOGFONT), &lf) ==
sizeof(LOGFONT));
617 hFont = (HFONT)::GetStockObject(SYSTEM_FONT);
618 ATLVERIFY(::GetObject(hFont,
sizeof(LOGFONT), &lf) ==
sizeof(LOGFONT));
620 lf.lfWeight = FW_BOLD;
621 HFONT hFontBold = ::CreateFontIndirect(&lf);
622 ATLASSERT(hFontBold != NULL);
627 inline BOOL AtlInitCommonControls(DWORD dwFlags)
629 INITCOMMONCONTROLSEX iccx = {
sizeof(INITCOMMONCONTROLSEX), dwFlags };
630 BOOL bRet = ::InitCommonControlsEx(&iccx);
640 #if defined(_WIN32_WCE) && !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) 641 #define _WTL_NO_RUNTIME_STRUCT_SIZE 644 #ifndef _WTL_NO_RUNTIME_STRUCT_SIZE 646 #ifndef _SIZEOF_STRUCT 647 #define _SIZEOF_STRUCT(structname, member) (((int)((LPBYTE)(&((structname*)0)->member) - ((LPBYTE)((structname*)0)))) + sizeof(((structname*)0)->member)) 650 #if (_WIN32_WINNT >= 0x0600) && !defined(REBARBANDINFO_V6_SIZE) 651 #define REBARBANDINFO_V6_SIZE _SIZEOF_STRUCT(REBARBANDINFO, cxHeader) 652 #endif // (_WIN32_WINNT >= 0x0600) && !defined(REBARBANDINFO_V6_SIZE) 654 #if (_WIN32_WINNT >= 0x0600) && !defined(LVGROUP_V5_SIZE) 655 #define LVGROUP_V5_SIZE _SIZEOF_STRUCT(LVGROUP, uAlign) 656 #endif // (_WIN32_WINNT >= 0x0600) && !defined(LVGROUP_V5_SIZE) 658 #if (_WIN32_WINNT >= 0x0600) && !defined(LVTILEINFO_V5_SIZE) 659 #define LVTILEINFO_V5_SIZE _SIZEOF_STRUCT(LVTILEINFO, puColumns) 660 #endif // (_WIN32_WINNT >= 0x0600) && !defined(LVTILEINFO_V5_SIZE) 662 #if defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN) && !defined(MCHITTESTINFO_V1_SIZE) 663 #define MCHITTESTINFO_V1_SIZE _SIZEOF_STRUCT(MCHITTESTINFO, st) 664 #endif // defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN) && !defined(MCHITTESTINFO_V1_SIZE) 666 #if !defined(_WIN32_WCE) && (WINVER >= 0x0600) && !defined(NONCLIENTMETRICS_V1_SIZE) 667 #define NONCLIENTMETRICS_V1_SIZE _SIZEOF_STRUCT(NONCLIENTMETRICS, lfMessageFont) 668 #endif // !defined(_WIN32_WCE) && (WINVER >= 0x0600) && !defined(NONCLIENTMETRICS_V1_SIZE) 670 #if !defined(_WIN32_WCE) && (_WIN32_WINNT >= 0x0501) && !defined(TTTOOLINFO_V2_SIZE) 671 #define TTTOOLINFO_V2_SIZE _SIZEOF_STRUCT(TTTOOLINFO, lParam) 672 #endif // !defined(_WIN32_WCE) && (_WIN32_WINNT >= 0x0501) && !defined(TTTOOLINFO_V2_SIZE) 674 #endif // !_WTL_NO_RUNTIME_STRUCT_SIZE 676 namespace RunTimeHelper
679 inline bool IsCommCtrl6()
681 DWORD dwMajor = 0, dwMinor = 0;
682 HRESULT hRet = ATL::AtlGetCommCtrlVersion(&dwMajor, &dwMinor);
683 return (SUCCEEDED(hRet) && (dwMajor >= 6));
686 inline bool IsVista()
688 #ifdef _versionhelpers_H_INCLUDED_ 689 return ::IsWindowsVistaOrGreater();
690 #else // !_versionhelpers_H_INCLUDED_ 691 OSVERSIONINFO ovi = {
sizeof(OSVERSIONINFO) };
692 BOOL bRet = ::GetVersionEx(&ovi);
693 return ((bRet != FALSE) && (ovi.dwMajorVersion >= 6));
694 #endif // _versionhelpers_H_INCLUDED_ 697 inline bool IsThemeAvailable()
703 HMODULE hThemeDLL = ::LoadLibrary(_T(
"uxtheme.dll"));
704 if(hThemeDLL != NULL)
706 typedef BOOL (STDAPICALLTYPE *PFN_IsThemeActive)();
707 PFN_IsThemeActive pfnIsThemeActive = (PFN_IsThemeActive)::GetProcAddress(hThemeDLL,
"IsThemeActive");
708 ATLASSERT(pfnIsThemeActive != NULL);
709 bRet = (pfnIsThemeActive != NULL) && (pfnIsThemeActive() != FALSE);
712 typedef BOOL (STDAPICALLTYPE *PFN_IsAppThemed)();
713 PFN_IsAppThemed pfnIsAppThemed = (PFN_IsAppThemed)::GetProcAddress(hThemeDLL,
"IsAppThemed");
714 ATLASSERT(pfnIsAppThemed != NULL);
715 bRet = (pfnIsAppThemed != NULL) && (pfnIsAppThemed() != FALSE);
718 ::FreeLibrary(hThemeDLL);
727 #ifdef _versionhelpers_H_INCLUDED_ 728 return ::IsWindows7OrGreater();
729 #else // !_versionhelpers_H_INCLUDED_ 730 OSVERSIONINFO ovi = {
sizeof(OSVERSIONINFO) };
731 BOOL bRet = ::GetVersionEx(&ovi);
732 return ((bRet != FALSE) && (ovi.dwMajorVersion == 6) && (ovi.dwMinorVersion >= 1));
733 #endif // _versionhelpers_H_INCLUDED_ 736 inline bool IsRibbonUIAvailable()
738 static INT iRibbonUI = -1;
740 #if defined(NTDDI_WIN7) && (NTDDI_VERSION >= NTDDI_WIN7) 743 HMODULE hRibbonDLL = ::LoadLibrary(_T(
"propsys.dll"));
744 if (hRibbonDLL != NULL)
746 const GUID CLSID_UIRibbonFramework = { 0x926749fa, 0x2615, 0x4987, { 0x88, 0x45, 0xc3, 0x3e, 0x65, 0xf2, 0xb9, 0x57 } };
749 ATL::CComPtr<IUnknown> pIUIFramework;
750 iRibbonUI = SUCCEEDED(pIUIFramework.CoCreateInstance(CLSID_UIRibbonFramework)) ? 1 : 0;
752 ::FreeLibrary(hRibbonDLL);
759 #endif // defined(NTDDI_WIN7) && (NTDDI_VERSION >= NTDDI_WIN7) 761 return (iRibbonUI == 1);
764 #endif // !_WIN32_WCE 766 inline UINT SizeOf_REBARBANDINFO()
768 UINT uSize =
sizeof(REBARBANDINFO);
769 #if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600) 770 if(!(IsVista() && IsCommCtrl6()))
771 uSize = REBARBANDINFO_V6_SIZE;
772 #endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600) 776 #if (_WIN32_WINNT >= 0x501) 777 inline UINT SizeOf_LVGROUP()
779 UINT uSize =
sizeof(LVGROUP);
780 #if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600) 782 uSize = LVGROUP_V5_SIZE;
783 #endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600) 787 inline UINT SizeOf_LVTILEINFO()
789 UINT uSize =
sizeof(LVTILEINFO);
790 #if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600) 792 uSize = LVTILEINFO_V5_SIZE;
793 #endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600) 796 #endif // (_WIN32_WINNT >= 0x501) 798 inline UINT SizeOf_MCHITTESTINFO()
800 UINT uSize =
sizeof(MCHITTESTINFO);
801 #if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN) 802 if(!(IsVista() && IsCommCtrl6()))
803 uSize = MCHITTESTINFO_V1_SIZE;
804 #endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN) 809 inline UINT SizeOf_NONCLIENTMETRICS()
811 UINT uSize =
sizeof(NONCLIENTMETRICS);
812 #if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (WINVER >= 0x0600) 814 uSize = NONCLIENTMETRICS_V1_SIZE;
815 #endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (WINVER >= 0x0600) 819 inline UINT SizeOf_TOOLINFO()
821 UINT uSize =
sizeof(TOOLINFO);
822 #if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0501) 824 uSize = TTTOOLINFO_V2_SIZE;
825 #endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0501) 828 #endif // !_WIN32_WCE 835 namespace ModuleHelper
837 inline HINSTANCE GetModuleInstance()
839 #if (_ATL_VER >= 0x0700) 840 return ATL::_AtlBaseModule.GetModuleInstance();
841 #else // !(_ATL_VER >= 0x0700) 842 return ATL::_pModule->GetModuleInstance();
843 #endif // !(_ATL_VER >= 0x0700) 846 inline HINSTANCE GetResourceInstance()
848 #if (_ATL_VER >= 0x0700) 849 return ATL::_AtlBaseModule.GetResourceInstance();
850 #else // !(_ATL_VER >= 0x0700) 851 return ATL::_pModule->GetResourceInstance();
852 #endif // !(_ATL_VER >= 0x0700) 855 inline void AddCreateWndData(ATL::_AtlCreateWndData* pData,
void* pObject)
857 #if (_ATL_VER >= 0x0700) 858 ATL::_AtlWinModule.AddCreateWndData(pData, pObject);
859 #else // !(_ATL_VER >= 0x0700) 860 ATL::_pModule->AddCreateWndData(pData, pObject);
861 #endif // !(_ATL_VER >= 0x0700) 864 inline void* ExtractCreateWndData()
866 #if (_ATL_VER >= 0x0700) 867 return ATL::_AtlWinModule.ExtractCreateWndData();
868 #else // !(_ATL_VER >= 0x0700) 869 return ATL::_pModule->ExtractCreateWndData();
870 #endif // !(_ATL_VER >= 0x0700) 878 namespace SecureHelper
880 inline void strcpyA_x(
char* lpstrDest,
size_t cchDest,
const char* lpstrSrc)
883 ATL::Checked::strcpy_s(lpstrDest, cchDest, lpstrSrc);
885 if(cchDest > (
size_t)lstrlenA(lpstrSrc))
886 ATLVERIFY(lstrcpyA(lpstrDest, lpstrSrc) != NULL);
892 inline void strcpyW_x(
wchar_t* lpstrDest,
size_t cchDest,
const wchar_t* lpstrSrc)
895 ATL::Checked::wcscpy_s(lpstrDest, cchDest, lpstrSrc);
897 if(cchDest > (
size_t)lstrlenW(lpstrSrc))
898 ATLVERIFY(lstrcpyW(lpstrDest, lpstrSrc) != NULL);
904 inline void strcpy_x(LPTSTR lpstrDest,
size_t cchDest, LPCTSTR lpstrSrc)
907 strcpyW_x(lpstrDest, cchDest, lpstrSrc);
909 strcpyA_x(lpstrDest, cchDest, lpstrSrc);
913 inline errno_t strncpyA_x(
char* lpstrDest,
size_t cchDest,
const char* lpstrSrc,
size_t cchCount)
916 return ATL::Checked::strncpy_s(lpstrDest, cchDest, lpstrSrc, cchCount);
919 if(lpstrDest == NULL || cchDest == 0 || lpstrSrc == NULL)
923 else if(cchCount == _TRUNCATE)
925 cchCount = __min(cchDest - 1,
size_t(lstrlenA(lpstrSrc)));
928 else if(cchDest <= cchCount)
933 if(nRet == 0 || nRet == STRUNCATE)
934 nRet = (lstrcpynA(lpstrDest, lpstrSrc, (
int)cchCount + 1) != NULL) ? nRet : EINVAL;
935 ATLASSERT(nRet == 0 || nRet == STRUNCATE);
940 inline errno_t strncpyW_x(
wchar_t* lpstrDest,
size_t cchDest,
const wchar_t* lpstrSrc,
size_t cchCount)
943 return ATL::Checked::wcsncpy_s(lpstrDest, cchDest, lpstrSrc, cchCount);
946 if(lpstrDest == NULL || cchDest == 0 || lpstrSrc == NULL)
950 else if(cchCount == _TRUNCATE)
952 cchCount = __min(cchDest - 1,
size_t(lstrlenW(lpstrSrc)));
955 else if(cchDest <= cchCount)
960 if(nRet == 0 || nRet == STRUNCATE)
961 nRet = (lstrcpynW(lpstrDest, lpstrSrc, (
int)cchCount + 1) != NULL) ? nRet : EINVAL;
962 ATLASSERT(nRet == 0 || nRet == STRUNCATE);
967 inline errno_t strncpy_x(LPTSTR lpstrDest,
size_t cchDest, LPCTSTR lpstrSrc,
size_t cchCount)
970 return strncpyW_x(lpstrDest, cchDest, lpstrSrc, cchCount);
972 return strncpyA_x(lpstrDest, cchDest, lpstrSrc, cchCount);
976 inline void strcatA_x(
char* lpstrDest,
size_t cchDest,
const char* lpstrSrc)
979 ATL::Checked::strcat_s(lpstrDest, cchDest, lpstrSrc);
981 if(cchDest > (
size_t)lstrlenA(lpstrSrc))
982 ATLVERIFY(lstrcatA(lpstrDest, lpstrSrc) != NULL);
988 inline void strcatW_x(
wchar_t* lpstrDest,
size_t cchDest,
const wchar_t* lpstrSrc)
991 ATL::Checked::wcscat_s(lpstrDest, cchDest, lpstrSrc);
993 if(cchDest > (
size_t)lstrlenW(lpstrSrc))
994 ATLVERIFY(lstrcatW(lpstrDest, lpstrSrc) != NULL);
1000 inline void strcat_x(LPTSTR lpstrDest,
size_t cchDest, LPCTSTR lpstrSrc)
1003 strcatW_x(lpstrDest, cchDest, lpstrSrc);
1005 strcatA_x(lpstrDest, cchDest, lpstrSrc);
1009 inline void memcpy_x(
void* pDest,
size_t cbDest,
const void* pSrc,
size_t cbSrc)
1012 ATL::Checked::memcpy_s(pDest, cbDest, pSrc, cbSrc);
1015 memcpy(pDest, pSrc, cbSrc);
1021 inline void memmove_x(
void* pDest,
size_t cbDest,
const void* pSrc,
size_t cbSrc)
1024 ATL::Checked::memmove_s(pDest, cbDest, pSrc, cbSrc);
1027 memmove(pDest, pSrc, cbSrc);
1033 inline int vsprintf_x(LPTSTR lpstrBuff,
size_t cchBuff, LPCTSTR lpstrFormat, va_list args)
1035 #if _SECURE_ATL && !defined(_ATL_MIN_CRT) && !defined(_WIN32_WCE) 1036 return _vstprintf_s(lpstrBuff, cchBuff, lpstrFormat, args);
1039 #pragma warning(push) 1040 #pragma warning(disable: 4996) 1041 return _vstprintf(lpstrBuff, lpstrFormat, args);
1042 #pragma warning(pop) 1046 inline int wvsprintf_x(LPTSTR lpstrBuff,
size_t cchBuff, LPCTSTR lpstrFormat, va_list args)
1048 #if _SECURE_ATL && !defined(_ATL_MIN_CRT) && !defined(_WIN32_WCE) 1049 return _vstprintf_s(lpstrBuff, cchBuff, lpstrFormat, args);
1052 return ::wvsprintf(lpstrBuff, lpstrFormat, args);
1056 inline int sprintf_x(LPTSTR lpstrBuff,
size_t cchBuff, LPCTSTR lpstrFormat, ...)
1059 va_start(args, lpstrFormat);
1060 int nRes = vsprintf_x(lpstrBuff, cchBuff, lpstrFormat, args);
1065 inline int wsprintf_x(LPTSTR lpstrBuff,
size_t cchBuff, LPCTSTR lpstrFormat, ...)
1068 va_start(args, lpstrFormat);
1069 int nRes = wvsprintf_x(lpstrBuff, cchBuff, lpstrFormat, args);
1079 namespace MinCrtHelper
1081 inline int _isspace(TCHAR ch)
1083 #ifndef _ATL_MIN_CRT 1084 return _istspace(ch);
1085 #else // _ATL_MIN_CRT 1087 ::GetStringTypeEx(::GetThreadLocale(), CT_CTYPE1, &ch, 1, &type);
1088 return (type & C1_SPACE) == C1_SPACE;
1089 #endif // _ATL_MIN_CRT 1092 inline int _isdigit(TCHAR ch)
1094 #ifndef _ATL_MIN_CRT 1095 return _istdigit(ch);
1096 #else // _ATL_MIN_CRT 1098 ::GetStringTypeEx(::GetThreadLocale(), CT_CTYPE1, &ch, 1, &type);
1099 return (type & C1_DIGIT) == C1_DIGIT;
1100 #endif // _ATL_MIN_CRT 1103 inline int _atoi(LPCTSTR str)
1105 #ifndef _ATL_MIN_CRT 1107 #else // _ATL_MIN_CRT 1108 while(_isspace(*str) != 0)
1113 if(ch == _T(
'-') || ch == _T(
'+'))
1117 while(_isdigit(ch) != 0)
1119 total = 10 * total + (ch -
'0');
1123 return (sign ==
'-') ? -total : total;
1124 #endif // _ATL_MIN_CRT 1127 inline LPCTSTR _strrchr(LPCTSTR str, TCHAR ch)
1129 #ifndef _ATL_MIN_CRT 1130 return _tcsrchr(str, ch);
1131 #else // _ATL_MIN_CRT 1132 LPCTSTR lpsz = NULL;
1137 str = ::CharNext(str);
1140 #endif // _ATL_MIN_CRT 1143 inline LPTSTR _strrchr(LPTSTR str, TCHAR ch)
1145 #ifndef _ATL_MIN_CRT 1146 return _tcsrchr(str, ch);
1147 #else // _ATL_MIN_CRT 1153 str = ::CharNext(str);
1156 #endif // _ATL_MIN_CRT 1167 namespace GenericWndClass
1169 inline LPCTSTR GetName()
1171 return _T(
"WTL_GenericWindow");
1174 inline ATOM Register()
1177 WNDCLASSEX wc = {
sizeof(WNDCLASSEX) };
1179 WNDCLASS wc = { 0 };
1181 wc.lpfnWndProc = ::DefWindowProc;
1182 wc.hInstance = ModuleHelper::GetModuleInstance();
1183 wc.hCursor = ::LoadCursor(NULL, IDC_ARROW);
1184 wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
1185 wc.lpszClassName = GetName();
1187 ATOM atom = ::RegisterClassEx(&wc);
1189 ATOM atom = ::RegisterClass(&wc);
1191 ATLASSERT(atom != 0);
1195 inline BOOL Unregister()
1197 return ::UnregisterClass(GetName(), ModuleHelper::GetModuleInstance());
1208 virtual BOOL PreTranslateMessage(MSG* pMsg) = 0;
1218 virtual BOOL OnIdle() = 0;
1221 #ifndef _ATL_NO_OLD_NAMES 1224 #define DoUpdate OnIdle 1225 #endif // !_ATL_NO_OLD_NAMES 1234 ATL::CSimpleArray<CMessageFilter*> m_aMsgFilter;
1235 ATL::CSimpleArray<CIdleHandler*> m_aIdleHandler;
1241 return m_aMsgFilter.Add(pMessageFilter);
1246 return m_aMsgFilter.Remove(pMessageFilter);
1252 return m_aIdleHandler.Add(pIdleHandler);
1257 return m_aIdleHandler.Remove(pIdleHandler);
1260 #ifndef _ATL_NO_OLD_NAMES 1264 ATLTRACE2(atlTraceUI, 0, _T(
"CUpdateUIObject and AddUpdateUI are deprecated. Please change your code to use CIdleHandler and OnIdle\n"));
1265 return AddIdleHandler(pIdleHandler);
1270 ATLTRACE2(atlTraceUI, 0, _T(
"CUpdateUIObject and RemoveUpdateUI are deprecated. Please change your code to use CIdleHandler and OnIdle\n"));
1271 return RemoveIdleHandler(pIdleHandler);
1273 #endif // !_ATL_NO_OLD_NAMES 1278 BOOL bDoIdle = TRUE;
1284 while(bDoIdle && !::PeekMessage(&m_msg, NULL, 0, 0, PM_NOREMOVE))
1286 if(!OnIdle(nIdleCount++))
1290 bRet = ::GetMessage(&m_msg, NULL, 0, 0);
1294 ATLTRACE2(atlTraceUI, 0, _T(
"::GetMessage returned -1 (error)\n"));
1299 ATLTRACE2(atlTraceUI, 0, _T(
"CMessageLoop::Run - exiting\n"));
1303 if(!PreTranslateMessage(&m_msg))
1305 ::TranslateMessage(&m_msg);
1306 ::DispatchMessage(&m_msg);
1309 if(IsIdleMessage(&m_msg))
1316 return (
int)m_msg.wParam;
1319 static BOOL IsIdleMessage(MSG* pMsg)
1322 switch(pMsg->message)
1326 case WM_NCMOUSEMOVE:
1327 #endif // !_WIN32_WCE 1338 virtual BOOL PreTranslateMessage(MSG* pMsg)
1341 for(
int i = m_aMsgFilter.GetSize() - 1; i >= 0; i--)
1344 if(pMessageFilter != NULL && pMessageFilter->PreTranslateMessage(pMsg))
1351 virtual BOOL OnIdle(
int )
1353 for(
int i = 0; i < m_aIdleHandler.GetSize(); i++)
1356 if(pIdleHandler != NULL)
1357 pIdleHandler->OnIdle();
1371 #if (_ATL_VER >= 0x0700) 1372 ATL::CComCritSecLock<ATL::CComCriticalSection> m_cslock;
1376 #endif // (_ATL_VER >= 0x0700) 1380 #if (_ATL_VER >= 0x0700) 1381 return m_cslock.Lock();
1382 #else // !(_ATL_VER >= 0x0700) 1383 ::EnterCriticalSection(&ATL::_pModule->m_csStaticDataInit);
1385 #endif // !(_ATL_VER >= 0x0700) 1390 #if (_ATL_VER >= 0x0700) 1392 #else // !(_ATL_VER >= 0x0700) 1393 ::LeaveCriticalSection(&ATL::_pModule->m_csStaticDataInit);
1394 #endif // !(_ATL_VER >= 0x0700) 1402 #if (_ATL_VER >= 0x0700) 1403 ATL::CComCritSecLock<ATL::CComCriticalSection> m_cslock;
1407 #endif // (_ATL_VER >= 0x0700) 1411 #if (_ATL_VER >= 0x0700) 1412 return m_cslock.Lock();
1413 #else // !(_ATL_VER >= 0x0700) 1414 ::EnterCriticalSection(&ATL::_pModule->m_csWindowCreate);
1416 #endif // !(_ATL_VER >= 0x0700) 1421 #if (_ATL_VER >= 0x0700) 1423 #else // !(_ATL_VER >= 0x0700) 1424 ::LeaveCriticalSection(&ATL::_pModule->m_csWindowCreate);
1425 #endif // !(_ATL_VER >= 0x0700) 1433 #ifndef _WTL_STACK_ALLOC_THRESHOLD 1434 #define _WTL_STACK_ALLOC_THRESHOLD 512 1437 #if (_ATL_VER >= 0x0700) 1439 using ATL::CTempBuffer;
1441 #else // !(_ATL_VER >= 0x0700) 1445 #define SIZE_MAX _UI64_MAX 1447 #define SIZE_MAX UINT_MAX 1451 #pragma warning(push) 1452 #pragma warning(disable: 4284) // warning for operator -> 1454 template<
typename T,
int t_nFixedBytes = 128>
1464 Allocate(nElements);
1469 if(m_p != reinterpret_cast<T*>(m_abFixedBuffer))
1478 T* operator ->()
const 1480 ATLASSERT(m_p != NULL);
1484 T* Allocate(
size_t nElements)
1486 ATLASSERT(nElements <= (SIZE_MAX /
sizeof(T)));
1487 return AllocateBytes(nElements *
sizeof(T));
1490 T* AllocateBytes(
size_t nBytes)
1492 ATLASSERT(m_p == NULL);
1493 if(nBytes > t_nFixedBytes)
1494 m_p =
static_cast<T*
>(malloc(nBytes));
1496 m_p =
reinterpret_cast<T*
>(m_abFixedBuffer);
1503 BYTE m_abFixedBuffer[t_nFixedBytes];
1506 #pragma warning(pop) 1508 #endif // !(_ATL_VER >= 0x0700) 1517 DWORD m_dwMainThreadID;
1518 ATL::CSimpleMap<DWORD, CMessageLoop*>* m_pMsgLoopMap;
1519 ATL::CSimpleArray<HWND>* m_pSettingChangeNotify;
1522 HRESULT Init(ATL::_ATL_OBJMAP_ENTRY* pObjMap, HINSTANCE hInstance,
const GUID* pLibID = NULL)
1524 HRESULT hRet = CComModule::Init(pObjMap, hInstance, pLibID);
1528 m_dwMainThreadID = ::GetCurrentThreadId();
1529 typedef ATL::CSimpleMap<DWORD, CMessageLoop*> _mapClass;
1530 m_pMsgLoopMap = NULL;
1531 ATLTRY(m_pMsgLoopMap =
new _mapClass);
1532 if(m_pMsgLoopMap == NULL)
1533 return E_OUTOFMEMORY;
1534 m_pSettingChangeNotify = NULL;
1541 TermSettingChangeNotify();
1542 delete m_pMsgLoopMap;
1550 if(FAILED(lock.Lock()))
1552 ATLTRACE2(atlTraceUI, 0, _T(
"ERROR : Unable to lock critical section in CAppModule::AddMessageLoop.\n"));
1557 ATLASSERT(pMsgLoop != NULL);
1558 ATLASSERT(m_pMsgLoopMap->Lookup(::GetCurrentThreadId()) == NULL);
1560 BOOL bRet = m_pMsgLoopMap->Add(::GetCurrentThreadId(), pMsgLoop);
1567 BOOL RemoveMessageLoop()
1570 if(FAILED(lock.Lock()))
1572 ATLTRACE2(atlTraceUI, 0, _T(
"ERROR : Unable to lock critical section in CAppModule::RemoveMessageLoop.\n"));
1577 BOOL bRet = m_pMsgLoopMap->Remove(::GetCurrentThreadId());
1584 CMessageLoop* GetMessageLoop(DWORD dwThreadID = ::GetCurrentThreadId())
const 1587 if(FAILED(lock.Lock()))
1589 ATLTRACE2(atlTraceUI, 0, _T(
"ERROR : Unable to lock critical section in CAppModule::GetMessageLoop.\n"));
1594 CMessageLoop* pLoop = m_pMsgLoopMap->Lookup(dwThreadID);
1603 BOOL InitSettingChangeNotify(DLGPROC pfnDlgProc = _SettingChangeDlgProc)
1606 if(FAILED(lock.Lock()))
1608 ATLTRACE2(atlTraceUI, 0, _T(
"ERROR : Unable to lock critical section in CAppModule::InitSettingChangeNotify.\n"));
1613 if(m_pSettingChangeNotify == NULL)
1615 typedef ATL::CSimpleArray<HWND> _notifyClass;
1616 ATLTRY(m_pSettingChangeNotify =
new _notifyClass);
1617 ATLASSERT(m_pSettingChangeNotify != NULL);
1620 BOOL bRet = (m_pSettingChangeNotify != NULL);
1621 if(bRet && m_pSettingChangeNotify->GetSize() == 0)
1625 HWND hNtfWnd = ::CreateDialogIndirect(GetModuleInstance(), &templ, NULL, pfnDlgProc);
1626 ATLASSERT(::IsWindow(hNtfWnd));
1627 if(::IsWindow(hNtfWnd))
1631 ::SetWindowLongPtr(hNtfWnd, GWLP_USERDATA, (LONG_PTR)
this);
1633 ::SetWindowLongPtr(hNtfWnd, GWLP_USERDATA, PtrToLong(
this));
1635 bRet = m_pSettingChangeNotify->Add(hNtfWnd);
1648 void TermSettingChangeNotify()
1651 if(FAILED(lock.Lock()))
1653 ATLTRACE2(atlTraceUI, 0, _T(
"ERROR : Unable to lock critical section in CAppModule::TermSettingChangeNotify.\n"));
1658 if(m_pSettingChangeNotify != NULL && m_pSettingChangeNotify->GetSize() > 0)
1659 ::DestroyWindow((*m_pSettingChangeNotify)[0]);
1660 delete m_pSettingChangeNotify;
1661 m_pSettingChangeNotify = NULL;
1666 BOOL AddSettingChangeNotify(HWND hWnd)
1669 if(FAILED(lock.Lock()))
1671 ATLTRACE2(atlTraceUI, 0, _T(
"ERROR : Unable to lock critical section in CAppModule::AddSettingChangeNotify.\n"));
1676 ATLASSERT(::IsWindow(hWnd));
1678 if(InitSettingChangeNotify() != FALSE)
1679 bRet = m_pSettingChangeNotify->Add(hWnd);
1686 BOOL RemoveSettingChangeNotify(HWND hWnd)
1689 if(FAILED(lock.Lock()))
1691 ATLTRACE2(atlTraceUI, 0, _T(
"ERROR : Unable to lock critical section in CAppModule::RemoveSettingChangeNotify.\n"));
1697 if(m_pSettingChangeNotify != NULL)
1698 bRet = m_pSettingChangeNotify->Remove(hWnd);
1713 WORD wMenu, wClass, wTitle;
1717 static INT_PTR CALLBACK _SettingChangeDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1719 static BOOL CALLBACK _SettingChangeDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1722 if(uMsg == WM_SETTINGCHANGE)
1730 ATLASSERT(pModule != NULL);
1731 ATLASSERT(pModule->m_pSettingChangeNotify != NULL);
1732 const UINT uTimeout = 1500;
1733 for(
int i = 1; i < pModule->m_pSettingChangeNotify->GetSize(); i++)
1735 #if !defined(_WIN32_WCE) 1736 ::SendMessageTimeout((*pModule->m_pSettingChangeNotify)[i], uMsg, wParam, lParam, SMTO_ABORTIFHUNG, uTimeout, NULL);
1737 #elif(_WIN32_WCE >= 400) // CE specific 1738 ::SendMessageTimeout((*pModule->m_pSettingChangeNotify)[i], uMsg, wParam, lParam, SMTO_NORMAL, uTimeout, NULL);
1739 #else // _WIN32_WCE < 400 specific 1741 ::SendMessage((*pModule->m_pSettingChangeNotify)[i], uMsg, wParam, lParam);
1757 HANDLE m_hEventShutdown;
1763 HRESULT Init(ATL::_ATL_OBJMAP_ENTRY* pObjMap, HINSTANCE hInstance,
const GUID* pLibID = NULL)
1767 return CAppModule::Init(pObjMap, hInstance, pLibID);
1772 if(m_hEventShutdown != NULL && ::CloseHandle(m_hEventShutdown))
1773 m_hEventShutdown = NULL;
1778 #if (_MSC_VER >= 1300) 1779 LONG Unlock()
throw()
1784 LONG lRet = CComModule::Unlock();
1788 ::SetEvent(m_hEventShutdown);
1793 void MonitorShutdown()
1797 ::WaitForSingleObject(m_hEventShutdown, INFINITE);
1801 m_bActivity =
false;
1802 dwWait = ::WaitForSingleObject(m_hEventShutdown, m_dwTimeOut);
1804 while(dwWait == WAIT_OBJECT_0);
1806 if(!m_bActivity && m_nLockCnt == 0)
1808 #if ((_WIN32_WINNT >= 0x0400 ) || defined(_WIN32_DCOM)) && defined(_ATL_FREE_THREADED) && !defined(_WIN32_WCE) 1809 ::CoSuspendClassObjects();
1810 if(!m_bActivity && m_nLockCnt == 0)
1817 if(::CloseHandle(m_hEventShutdown))
1818 m_hEventShutdown = NULL;
1819 ::PostThreadMessage(m_dwMainThreadID, WM_QUIT, 0, 0);
1824 m_hEventShutdown = ::CreateEvent(NULL,
false,
false, NULL);
1825 if(m_hEventShutdown == NULL)
1827 DWORD dwThreadID = 0;
1828 #if !defined(_ATL_MIN_CRT) && defined(_MT) && !defined(_WIN32_WCE) 1829 HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0, (UINT (WINAPI*)(
void*))MonitorProc,
this, 0, (UINT*)&dwThreadID);
1831 HANDLE hThread = ::CreateThread(NULL, 0, MonitorProc,
this, 0, &dwThreadID);
1833 bool bRet = (hThread != NULL);
1835 ::CloseHandle(hThread);
1839 static DWORD WINAPI MonitorProc(
void* pv)
1842 p->MonitorShutdown();
1846 #if (_ATL_VER < 0x0700) 1848 static LPCTSTR FindOneOf(LPCTSTR p1, LPCTSTR p2)
1850 while(p1 != NULL && *p1 != NULL)
1853 while(p != NULL && *p != NULL)
1856 return ::CharNext(p1);
1859 p1 = ::CharNext(p1);
1863 #endif // (_ATL_VER < 0x0700) 1870 #if (_ATL_VER < 0x0700) 1883 Attach(key.Detach());
1889 Attach(key.Detach());
1894 LONG SetValue(LPCTSTR pszValueName, DWORD dwType,
const void* pValue, ULONG nBytes)
1896 ATLASSERT(m_hKey != NULL);
1897 return ::RegSetValueEx(m_hKey, pszValueName, NULL, dwType, static_cast<const BYTE*>(pValue), nBytes);
1900 LONG SetGUIDValue(LPCTSTR pszValueName, REFGUID guidValue)
1902 ATLASSERT(m_hKey != NULL);
1904 OLECHAR szGUID[64] = { 0 };
1905 ::StringFromGUID2(guidValue, szGUID, 64);
1908 LPCTSTR lpstr = OLE2CT(szGUID);
1911 return E_OUTOFMEMORY;
1913 return SetStringValue(pszValueName, lpstr);
1916 LONG SetBinaryValue(LPCTSTR pszValueName,
const void* pValue, ULONG nBytes)
1918 ATLASSERT(m_hKey != NULL);
1919 return ::RegSetValueEx(m_hKey, pszValueName, NULL, REG_BINARY, reinterpret_cast<const BYTE*>(pValue), nBytes);
1922 LONG SetDWORDValue(LPCTSTR pszValueName, DWORD dwValue)
1924 ATLASSERT(m_hKey != NULL);
1925 return ::RegSetValueEx(m_hKey, pszValueName, NULL, REG_DWORD, reinterpret_cast<const BYTE*>(&dwValue),
sizeof(DWORD));
1929 LONG SetQWORDValue(LPCTSTR pszValueName, ULONGLONG qwValue)
1931 ATLASSERT(m_hKey != NULL);
1932 return ::RegSetValueEx(m_hKey, pszValueName, NULL, REG_QWORD, reinterpret_cast<const BYTE*>(&qwValue),
sizeof(ULONGLONG));
1936 LONG SetStringValue(LPCTSTR pszValueName, LPCTSTR pszValue, DWORD dwType = REG_SZ)
1938 ATLASSERT(m_hKey != NULL);
1939 if(pszValue == NULL)
1942 return ERROR_INVALID_DATA;
1944 ATLASSERT((dwType == REG_SZ) || (dwType == REG_EXPAND_SZ));
1946 return ::RegSetValueEx(m_hKey, pszValueName, NULL, dwType, reinterpret_cast<const BYTE*>(pszValue), (lstrlen(pszValue) + 1) *
sizeof(TCHAR));
1949 LONG SetMultiStringValue(LPCTSTR pszValueName, LPCTSTR pszValue)
1951 ATLASSERT(m_hKey != NULL);
1952 if(pszValue == NULL)
1955 return ERROR_INVALID_DATA;
1960 LPCTSTR pszTemp = pszValue;
1963 nLength = lstrlen(pszTemp) + 1;
1965 nBytes += nLength *
sizeof(TCHAR);
1966 }
while (nLength != 1);
1968 return ::RegSetValueEx(m_hKey, pszValueName, NULL, REG_MULTI_SZ, reinterpret_cast<const BYTE*>(pszValue), nBytes);
1971 LONG QueryValue(LPCTSTR pszValueName, DWORD* pdwType,
void* pData, ULONG* pnBytes)
1973 ATLASSERT(m_hKey != NULL);
1974 return ::RegQueryValueEx(m_hKey, pszValueName, NULL, pdwType, static_cast<LPBYTE>(pData), pnBytes);
1977 LONG QueryGUIDValue(LPCTSTR pszValueName, GUID& guidValue)
1979 ATLASSERT(m_hKey != NULL);
1981 guidValue = GUID_NULL;
1983 TCHAR szGUID[64] = { 0 };
1985 LONG lRes = QueryStringValue(pszValueName, szGUID, &nCount);
1987 if (lRes != ERROR_SUCCESS)
1990 if(szGUID[0] != _T(
'{'))
1991 return ERROR_INVALID_DATA;
1994 LPOLESTR lpstr = T2OLE(szGUID);
1997 return E_OUTOFMEMORY;
2000 HRESULT hr = ::CLSIDFromString(lpstr, &guidValue);
2002 return ERROR_INVALID_DATA;
2004 return ERROR_SUCCESS;
2007 LONG QueryBinaryValue(LPCTSTR pszValueName,
void* pValue, ULONG* pnBytes)
2009 ATLASSERT(pnBytes != NULL);
2010 ATLASSERT(m_hKey != NULL);
2013 LONG lRes = ::RegQueryValueEx(m_hKey, pszValueName, NULL, &dwType, reinterpret_cast<LPBYTE>(pValue), pnBytes);
2014 if (lRes != ERROR_SUCCESS)
2016 if (dwType != REG_BINARY)
2017 return ERROR_INVALID_DATA;
2019 return ERROR_SUCCESS;
2022 LONG QueryDWORDValue(LPCTSTR pszValueName, DWORD& dwValue)
2024 ATLASSERT(m_hKey != NULL);
2026 ULONG nBytes =
sizeof(DWORD);
2028 LONG lRes = ::RegQueryValueEx(m_hKey, pszValueName, NULL, &dwType, reinterpret_cast<LPBYTE>(&dwValue), &nBytes);
2029 if (lRes != ERROR_SUCCESS)
2031 if (dwType != REG_DWORD)
2032 return ERROR_INVALID_DATA;
2034 return ERROR_SUCCESS;
2038 LONG QueryQWORDValue(LPCTSTR pszValueName, ULONGLONG& qwValue)
2040 ATLASSERT(m_hKey != NULL);
2042 ULONG nBytes =
sizeof(ULONGLONG);
2044 LONG lRes = ::RegQueryValueEx(m_hKey, pszValueName, NULL, &dwType, reinterpret_cast<LPBYTE>(&qwValue), &nBytes);
2045 if (lRes != ERROR_SUCCESS)
2047 if (dwType != REG_QWORD)
2048 return ERROR_INVALID_DATA;
2050 return ERROR_SUCCESS;
2054 LONG QueryStringValue(LPCTSTR pszValueName, LPTSTR pszValue, ULONG* pnChars)
2056 ATLASSERT(m_hKey != NULL);
2057 ATLASSERT(pnChars != NULL);
2059 ULONG nBytes = (*pnChars) *
sizeof(TCHAR);
2062 LONG lRes = ::RegQueryValueEx(m_hKey, pszValueName, NULL, &dwType, reinterpret_cast<LPBYTE>(pszValue), &nBytes);
2064 if (lRes != ERROR_SUCCESS)
2069 if(dwType != REG_SZ && dwType != REG_EXPAND_SZ)
2071 return ERROR_INVALID_DATA;
2074 if (pszValue != NULL)
2078 if ((nBytes %
sizeof(TCHAR) != 0) || (pszValue[nBytes /
sizeof(TCHAR) -1] != 0))
2079 return ERROR_INVALID_DATA;
2083 pszValue[0] = _T(
'\0');
2087 *pnChars = nBytes /
sizeof(TCHAR);
2089 return ERROR_SUCCESS;
2092 LONG QueryMultiStringValue(LPCTSTR pszValueName, LPTSTR pszValue, ULONG* pnChars)
2094 ATLASSERT(m_hKey != NULL);
2095 ATLASSERT(pnChars != NULL);
2097 if (pszValue != NULL && *pnChars < 2)
2098 return ERROR_INSUFFICIENT_BUFFER;
2100 ULONG nBytes = (*pnChars) *
sizeof(TCHAR);
2103 LONG lRes = ::RegQueryValueEx(m_hKey, pszValueName, NULL, &dwType, reinterpret_cast<LPBYTE>(pszValue), &nBytes);
2104 if (lRes != ERROR_SUCCESS)
2106 if (dwType != REG_MULTI_SZ)
2107 return ERROR_INVALID_DATA;
2108 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)))
2109 return ERROR_INVALID_DATA;
2111 *pnChars = nBytes /
sizeof(TCHAR);
2113 return ERROR_SUCCESS;
2117 #else // !(_ATL_VER < 0x0700) 2121 #endif // !(_ATL_VER < 0x0700) 2127 #if defined(_WTL_FORWARD_DECLARE_CSTRING) && !defined(_WTL_USE_CSTRING) 2128 #define _WTL_USE_CSTRING 2129 #endif // defined(_WTL_FORWARD_DECLARE_CSTRING) && !defined(_WTL_USE_CSTRING) 2131 #ifdef _WTL_USE_CSTRING 2133 #endif // _WTL_USE_CSTRING 2138 #define _CSTRING_NS ATL 2140 #define _CSTRING_NS WTL 2142 #endif // _CSTRING_NS 2146 #ifdef __ATLTYPES_H__ 2149 #define _WTYPES_NS WTL 2151 #endif // _WTYPES_NS 2160 #if (((_ATL_VER < 0x0700) && defined(_ATL_DLL)) || (_ATL_VER >= 0x0B00)) && !defined(_WIN32_WCE) 2165 inline HRESULT AtlGetDllVersion(HINSTANCE hInstDLL, DLLVERSIONINFO* pDllVersionInfo)
2167 ATLASSERT(pDllVersionInfo != NULL);
2168 if(pDllVersionInfo == NULL)
2169 return E_INVALIDARG;
2172 DLLGETVERSIONPROC pfnDllGetVersion = (DLLGETVERSIONPROC)::GetProcAddress(hInstDLL,
"DllGetVersion");
2173 if(pfnDllGetVersion == NULL)
2176 return (*pfnDllGetVersion)(pDllVersionInfo);
2179 inline HRESULT AtlGetDllVersion(LPCTSTR lpstrDllName, DLLVERSIONINFO* pDllVersionInfo)
2181 HINSTANCE hInstDLL = ::LoadLibrary(lpstrDllName);
2182 if(hInstDLL == NULL)
2184 HRESULT hRet = AtlGetDllVersion(hInstDLL, pDllVersionInfo);
2185 ::FreeLibrary(hInstDLL);
2193 inline HRESULT AtlGetCommCtrlVersion(LPDWORD pdwMajor, LPDWORD pdwMinor)
2195 ATLASSERT(pdwMajor != NULL && pdwMinor != NULL);
2196 if(pdwMajor == NULL || pdwMinor == NULL)
2197 return E_INVALIDARG;
2200 ::ZeroMemory(&dvi,
sizeof(dvi));
2201 dvi.cbSize =
sizeof(dvi);
2202 HRESULT hRet = AtlGetDllVersion(_T(
"comctl32.dll"), &dvi);
2206 *pdwMajor = dvi.dwMajorVersion;
2207 *pdwMinor = dvi.dwMinorVersion;
2209 else if(hRet == E_NOTIMPL)
2226 inline HRESULT AtlGetShellVersion(LPDWORD pdwMajor, LPDWORD pdwMinor)
2228 ATLASSERT(pdwMajor != NULL && pdwMinor != NULL);
2229 if(pdwMajor == NULL || pdwMinor == NULL)
2230 return E_INVALIDARG;
2233 ::ZeroMemory(&dvi,
sizeof(dvi));
2234 dvi.cbSize =
sizeof(dvi);
2235 HRESULT hRet = AtlGetDllVersion(_T(
"shell32.dll"), &dvi);
2239 *pdwMajor = dvi.dwMajorVersion;
2240 *pdwMinor = dvi.dwMinorVersion;
2242 else if(hRet == E_NOTIMPL)
2256 #endif // (_ATL_VER < 0x0700) && defined(_ATL_DLL) && !defined(_WIN32_WCE) 2260 #include "atlwinx.h" 2261 #include "atluser.h" 2264 #ifndef _WTL_NO_AUTOMATIC_NAMESPACE 2265 using namespace WTL;
2266 #endif // !_WTL_NO_AUTOMATIC_NAMESPACE 2268 #endif // __ATLAPP_H__ Definition: atlapp.h:1205
Definition: atlapp.h:1872
Definition: atlapp.h:1368
Definition: atlapp.h:1231
Definition: atlapp.h:1399
Definition: atlapp.h:1514
Definition: atlapp.h:1215
Definition: atlmisc.h:757
Definition: atlapp.h:1455
Definition: atlapp.h:1754
Definition: atlapp.h:1706