atlapp.h 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225
  1. // Windows Template Library - WTL version 10.0
  2. // Copyright (C) Microsoft Corporation, WTL Team. All rights reserved.
  3. //
  4. // This file is a part of the Windows Template Library.
  5. // The use and distribution terms for this software are covered by the
  6. // Microsoft Public License (http://opensource.org/licenses/MS-PL)
  7. // which can be found in the file MS-PL.txt at the root folder.
  8. #ifndef __ATLAPP_H__
  9. #define __ATLAPP_H__
  10. #pragma once
  11. #ifndef __cplusplus
  12. #error WTL requires C++ compilation (use a .cpp suffix)
  13. #endif
  14. #ifndef __ATLBASE_H__
  15. #error atlapp.h requires atlbase.h to be included first
  16. #endif
  17. #ifdef _WIN32_WCE
  18. #error WTL10 doesn't support Windows CE
  19. #endif
  20. #ifdef _ATL_NO_COMMODULE
  21. #error WTL doesn't support _ATL_NO_COMMODULE
  22. #endif
  23. #ifdef _ATL_NO_WIN_SUPPORT
  24. #error WTL doesn't support _ATL_NO_WIN_SUPPORT
  25. #endif
  26. #if (_MSC_VER < 1400)
  27. #error WTL10 requires C++ compiler version 14 (Visual C++ 2005) or higher
  28. #endif
  29. #if (WINVER < 0x0501)
  30. #error WTL requires WINVER >= 0x0501
  31. #endif
  32. #if (_WIN32_WINNT < 0x0501)
  33. #error WTL requires _WIN32_WINNT >= 0x0501
  34. #endif
  35. #if (_WIN32_IE < 0x0600)
  36. #error WTL requires _WIN32_IE >= 0x0600
  37. #endif
  38. #if (_ATL_VER < 0x0800)
  39. #error WTL10 requires ATL version 8 or higher
  40. #endif
  41. #ifdef _ATL_MIN_CRT
  42. #error WTL10 doesn't support _ATL_MIN_CRT
  43. #endif
  44. #ifdef _ATL_NO_MSIMG
  45. #error WTL10 doesn't support _ATL_NO_MSIMG
  46. #endif
  47. #include <limits.h>
  48. #ifdef _MT
  49. #include <process.h> // for _beginthreadex
  50. #endif
  51. #include <commctrl.h>
  52. #pragma comment(lib, "comctl32.lib")
  53. #include <commdlg.h>
  54. #include <shellapi.h>
  55. // Check for VS2005 without newer WinSDK
  56. #if (_MSC_VER == 1400) && !defined(RB_GETEXTENDEDSTYLE)
  57. #error WTL10 requires WinSDK 6.0 ot higher
  58. #endif
  59. #include <uxtheme.h>
  60. #pragma comment(lib, "uxtheme.lib")
  61. #if defined(_SYSINFOAPI_H_) && defined(NOT_BUILD_WINDOWS_DEPRECATE)
  62. #include <VersionHelpers.h>
  63. #endif
  64. #include "atlres.h"
  65. ///////////////////////////////////////////////////////////////////////////////
  66. // WTL version number
  67. #define _WTL_VER 0x1000 // version 10.0
  68. ///////////////////////////////////////////////////////////////////////////////
  69. // Classes in this file:
  70. //
  71. // CMessageFilter
  72. // CIdleHandler
  73. // CMessageLoop
  74. //
  75. // CAppModule
  76. // CServerAppModule
  77. //
  78. // Global functions:
  79. // AtlInitCommonControls()
  80. // AtlGetDefaultGuiFont()
  81. // AtlCreateControlFont()
  82. // AtlCreateBoldFont()
  83. // AtlGetStringPtr()
  84. ///////////////////////////////////////////////////////////////////////////////
  85. // Miscellaneous global support
  86. // define useful macros from winuser.h
  87. #ifndef IS_INTRESOURCE
  88. #define IS_INTRESOURCE(_r) (((ULONG_PTR)(_r) >> 16) == 0)
  89. #endif // IS_INTRESOURCE
  90. // protect template members from windowsx.h macros
  91. #ifdef _INC_WINDOWSX
  92. #undef SubclassWindow
  93. #endif // _INC_WINDOWSX
  94. // define useful macros from windowsx.h
  95. #ifndef GET_X_LPARAM
  96. #define GET_X_LPARAM(lParam) ((int)(short)LOWORD(lParam))
  97. #endif
  98. #ifndef GET_Y_LPARAM
  99. #define GET_Y_LPARAM(lParam) ((int)(short)HIWORD(lParam))
  100. #endif
  101. // Dummy structs for compiling with /CLR
  102. #ifdef _MANAGED
  103. __if_not_exists(_IMAGELIST::_IMAGELIST) { struct _IMAGELIST { }; }
  104. __if_not_exists(_TREEITEM::_TREEITEM) { struct _TREEITEM { }; }
  105. __if_not_exists(_PSP::_PSP) { struct _PSP { }; }
  106. #endif
  107. // Forward declaration for ATL11 fix
  108. #if (_ATL_VER >= 0x0B00)
  109. namespace ATL { HRESULT AtlGetCommCtrlVersion(LPDWORD pdwMajor, LPDWORD pdwMinor); }
  110. #endif
  111. #ifndef WM_MOUSEHWHEEL
  112. #define WM_MOUSEHWHEEL 0x020E
  113. #endif
  114. // Used for stack allocations with ATL::CTempBuffer
  115. #ifndef _WTL_STACK_ALLOC_THRESHOLD
  116. #define _WTL_STACK_ALLOC_THRESHOLD 512
  117. #endif
  118. namespace WTL
  119. {
  120. DECLARE_TRACE_CATEGORY(atlTraceUI)
  121. #ifdef _DEBUG
  122. __declspec(selectany) ATL::CTraceCategory atlTraceUI(_T("atlTraceUI"));
  123. #endif // _DEBUG
  124. // Common Controls initialization helper
  125. inline BOOL AtlInitCommonControls(DWORD dwFlags)
  126. {
  127. INITCOMMONCONTROLSEX iccx = { sizeof(INITCOMMONCONTROLSEX), dwFlags };
  128. BOOL bRet = ::InitCommonControlsEx(&iccx);
  129. ATLASSERT(bRet);
  130. return bRet;
  131. }
  132. // Default GUI font helper - "MS Shell Dlg" stock font
  133. inline HFONT AtlGetDefaultGuiFont()
  134. {
  135. return (HFONT)::GetStockObject(DEFAULT_GUI_FONT);
  136. }
  137. // Control font helper - default font for controls not in a dialog
  138. // (NOTE: Caller owns the font, and should destroy it when it's no longer needed)
  139. inline HFONT AtlCreateControlFont()
  140. {
  141. LOGFONT lf = {};
  142. ATLVERIFY(::SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(LOGFONT), &lf, 0) != FALSE);
  143. HFONT hFont = ::CreateFontIndirect(&lf);
  144. ATLASSERT(hFont != NULL);
  145. return hFont;
  146. }
  147. // Bold font helper
  148. // (NOTE: Caller owns the font, and should destroy it when it's no longer needed)
  149. inline HFONT AtlCreateBoldFont(HFONT hFont = NULL)
  150. {
  151. LOGFONT lf = {};
  152. if(hFont == NULL)
  153. ATLVERIFY(::SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(LOGFONT), &lf, 0) != FALSE);
  154. else
  155. ATLVERIFY(::GetObject(hFont, sizeof(LOGFONT), &lf) == sizeof(LOGFONT));
  156. lf.lfWeight = FW_BOLD;
  157. HFONT hFontBold = ::CreateFontIndirect(&lf);
  158. ATLASSERT(hFontBold != NULL);
  159. return hFontBold;
  160. }
  161. // Resource string pointer
  162. inline LPCWSTR AtlGetStringPtr(UINT uID, int* pch = NULL)
  163. {
  164. LPCWSTR lpstr = NULL;
  165. int nRet = ::LoadStringW(ATL::_AtlBaseModule.GetResourceInstance(), uID, (LPWSTR)&lpstr, 0);
  166. if(pch != NULL)
  167. *pch = nRet;
  168. return lpstr;
  169. }
  170. ///////////////////////////////////////////////////////////////////////////////
  171. // RunTimeHelper - helper functions for Windows version and structure sizes
  172. #ifndef _WTL_NO_RUNTIME_STRUCT_SIZE
  173. #ifndef _SIZEOF_STRUCT
  174. #define _SIZEOF_STRUCT(structname, member) (((int)((LPBYTE)(&((structname*)0)->member) - ((LPBYTE)((structname*)0)))) + sizeof(((structname*)0)->member))
  175. #endif
  176. #if (_WIN32_WINNT >= 0x0600) && !defined(REBARBANDINFO_V6_SIZE)
  177. #define REBARBANDINFO_V6_SIZE _SIZEOF_STRUCT(REBARBANDINFO, cxHeader)
  178. #endif // (_WIN32_WINNT >= 0x0600) && !defined(REBARBANDINFO_V6_SIZE)
  179. #if (_WIN32_WINNT >= 0x0600) && !defined(LVGROUP_V5_SIZE)
  180. #define LVGROUP_V5_SIZE _SIZEOF_STRUCT(LVGROUP, uAlign)
  181. #endif // (_WIN32_WINNT >= 0x0600) && !defined(LVGROUP_V5_SIZE)
  182. #if (_WIN32_WINNT >= 0x0600) && !defined(LVTILEINFO_V5_SIZE)
  183. #define LVTILEINFO_V5_SIZE _SIZEOF_STRUCT(LVTILEINFO, puColumns)
  184. #endif // (_WIN32_WINNT >= 0x0600) && !defined(LVTILEINFO_V5_SIZE)
  185. #if defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN) && !defined(MCHITTESTINFO_V1_SIZE)
  186. #define MCHITTESTINFO_V1_SIZE _SIZEOF_STRUCT(MCHITTESTINFO, st)
  187. #endif // defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN) && !defined(MCHITTESTINFO_V1_SIZE)
  188. #if (WINVER >= 0x0600) && !defined(NONCLIENTMETRICS_V1_SIZE)
  189. #define NONCLIENTMETRICS_V1_SIZE _SIZEOF_STRUCT(NONCLIENTMETRICS, lfMessageFont)
  190. #endif // (WINVER >= 0x0600) && !defined(NONCLIENTMETRICS_V1_SIZE)
  191. #ifndef TTTOOLINFO_V2_SIZE
  192. #define TTTOOLINFO_V2_SIZE _SIZEOF_STRUCT(TTTOOLINFO, lParam)
  193. #endif
  194. #endif // !_WTL_NO_RUNTIME_STRUCT_SIZE
  195. namespace RunTimeHelper
  196. {
  197. inline bool IsCommCtrl6()
  198. {
  199. DWORD dwMajor = 0, dwMinor = 0;
  200. HRESULT hRet = ATL::AtlGetCommCtrlVersion(&dwMajor, &dwMinor);
  201. return (SUCCEEDED(hRet) && (dwMajor >= 6));
  202. }
  203. inline bool IsVista()
  204. {
  205. #ifdef _versionhelpers_H_INCLUDED_
  206. return ::IsWindowsVistaOrGreater();
  207. #else // !_versionhelpers_H_INCLUDED_
  208. OSVERSIONINFO ovi = { sizeof(OSVERSIONINFO) };
  209. BOOL bRet = ::GetVersionEx(&ovi);
  210. return ((bRet != FALSE) && (ovi.dwMajorVersion >= 6));
  211. #endif // _versionhelpers_H_INCLUDED_
  212. }
  213. inline bool IsThemeAvailable()
  214. {
  215. return IsCommCtrl6() && (::IsThemeActive() != FALSE) && (::IsAppThemed() != FALSE);
  216. }
  217. inline bool IsWin7()
  218. {
  219. #ifdef _versionhelpers_H_INCLUDED_
  220. return ::IsWindows7OrGreater();
  221. #else // !_versionhelpers_H_INCLUDED_
  222. OSVERSIONINFO ovi = { sizeof(OSVERSIONINFO) };
  223. BOOL bRet = ::GetVersionEx(&ovi);
  224. return ((bRet != FALSE) && ((ovi.dwMajorVersion > 6) || ((ovi.dwMajorVersion == 6) && (ovi.dwMinorVersion >= 1))));
  225. #endif // _versionhelpers_H_INCLUDED_
  226. }
  227. inline bool IsRibbonUIAvailable()
  228. {
  229. static INT iRibbonUI = -1;
  230. #if defined(NTDDI_WIN7) && (NTDDI_VERSION >= NTDDI_WIN7)
  231. if (iRibbonUI == -1)
  232. {
  233. HMODULE hRibbonDLL = ::LoadLibrary(_T("propsys.dll"));
  234. if (hRibbonDLL != NULL)
  235. {
  236. const GUID CLSID_UIRibbonFramework = { 0x926749fa, 0x2615, 0x4987, { 0x88, 0x45, 0xc3, 0x3e, 0x65, 0xf2, 0xb9, 0x57 } };
  237. // block - create instance
  238. {
  239. ATL::CComPtr<IUnknown> pIUIFramework;
  240. iRibbonUI = SUCCEEDED(pIUIFramework.CoCreateInstance(CLSID_UIRibbonFramework)) ? 1 : 0;
  241. }
  242. ::FreeLibrary(hRibbonDLL);
  243. }
  244. else
  245. {
  246. iRibbonUI = 0;
  247. }
  248. }
  249. #endif // defined(NTDDI_WIN7) && (NTDDI_VERSION >= NTDDI_WIN7)
  250. return (iRibbonUI == 1);
  251. }
  252. inline UINT SizeOf_REBARBANDINFO()
  253. {
  254. UINT uSize = sizeof(REBARBANDINFO);
  255. #if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
  256. if(!(IsVista() && IsCommCtrl6()))
  257. uSize = REBARBANDINFO_V6_SIZE;
  258. #endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
  259. return uSize;
  260. }
  261. inline UINT SizeOf_LVGROUP()
  262. {
  263. UINT uSize = sizeof(LVGROUP);
  264. #if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
  265. if(!IsVista())
  266. uSize = LVGROUP_V5_SIZE;
  267. #endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
  268. return uSize;
  269. }
  270. inline UINT SizeOf_LVTILEINFO()
  271. {
  272. UINT uSize = sizeof(LVTILEINFO);
  273. #if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
  274. if(!IsVista())
  275. uSize = LVTILEINFO_V5_SIZE;
  276. #endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
  277. return uSize;
  278. }
  279. inline UINT SizeOf_MCHITTESTINFO()
  280. {
  281. UINT uSize = sizeof(MCHITTESTINFO);
  282. #if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
  283. if(!(IsVista() && IsCommCtrl6()))
  284. uSize = MCHITTESTINFO_V1_SIZE;
  285. #endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
  286. return uSize;
  287. }
  288. inline UINT SizeOf_NONCLIENTMETRICS()
  289. {
  290. UINT uSize = sizeof(NONCLIENTMETRICS);
  291. #if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (WINVER >= 0x0600)
  292. if(!IsVista())
  293. uSize = NONCLIENTMETRICS_V1_SIZE;
  294. #endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (WINVER >= 0x0600)
  295. return uSize;
  296. }
  297. inline UINT SizeOf_TOOLINFO()
  298. {
  299. UINT uSize = sizeof(TOOLINFO);
  300. #ifndef _WTL_NO_RUNTIME_STRUCT_SIZE
  301. if(!IsVista())
  302. uSize = TTTOOLINFO_V2_SIZE;
  303. #endif
  304. return uSize;
  305. }
  306. } // namespace RunTimeHelper
  307. ///////////////////////////////////////////////////////////////////////////////
  308. // ModuleHelper - helper functions for ATL (deprecated)
  309. namespace ModuleHelper
  310. {
  311. inline HINSTANCE GetModuleInstance()
  312. {
  313. return ATL::_AtlBaseModule.GetModuleInstance();
  314. }
  315. inline HINSTANCE GetResourceInstance()
  316. {
  317. return ATL::_AtlBaseModule.GetResourceInstance();
  318. }
  319. inline void AddCreateWndData(ATL::_AtlCreateWndData* pData, void* pObject)
  320. {
  321. ATL::_AtlWinModule.AddCreateWndData(pData, pObject);
  322. }
  323. inline void* ExtractCreateWndData()
  324. {
  325. return ATL::_AtlWinModule.ExtractCreateWndData();
  326. }
  327. } // namespace ModuleHelper
  328. ///////////////////////////////////////////////////////////////////////////////
  329. // SecureHelper - WTL10 requires use of secure functions
  330. // these are here only for compatibility with existing projects
  331. namespace SecureHelper
  332. {
  333. inline void strcpyA_x(char* lpstrDest, size_t cchDest, const char* lpstrSrc)
  334. {
  335. ATL::Checked::strcpy_s(lpstrDest, cchDest, lpstrSrc);
  336. }
  337. inline void strcpyW_x(wchar_t* lpstrDest, size_t cchDest, const wchar_t* lpstrSrc)
  338. {
  339. ATL::Checked::wcscpy_s(lpstrDest, cchDest, lpstrSrc);
  340. }
  341. inline void strcpy_x(LPTSTR lpstrDest, size_t cchDest, LPCTSTR lpstrSrc)
  342. {
  343. #ifdef _UNICODE
  344. strcpyW_x(lpstrDest, cchDest, lpstrSrc);
  345. #else
  346. strcpyA_x(lpstrDest, cchDest, lpstrSrc);
  347. #endif
  348. }
  349. inline errno_t strncpyA_x(char* lpstrDest, size_t cchDest, const char* lpstrSrc, size_t cchCount)
  350. {
  351. return ATL::Checked::strncpy_s(lpstrDest, cchDest, lpstrSrc, cchCount);
  352. }
  353. inline errno_t strncpyW_x(wchar_t* lpstrDest, size_t cchDest, const wchar_t* lpstrSrc, size_t cchCount)
  354. {
  355. return ATL::Checked::wcsncpy_s(lpstrDest, cchDest, lpstrSrc, cchCount);
  356. }
  357. inline errno_t strncpy_x(LPTSTR lpstrDest, size_t cchDest, LPCTSTR lpstrSrc, size_t cchCount)
  358. {
  359. #ifdef _UNICODE
  360. return strncpyW_x(lpstrDest, cchDest, lpstrSrc, cchCount);
  361. #else
  362. return strncpyA_x(lpstrDest, cchDest, lpstrSrc, cchCount);
  363. #endif
  364. }
  365. inline void strcatA_x(char* lpstrDest, size_t cchDest, const char* lpstrSrc)
  366. {
  367. ATL::Checked::strcat_s(lpstrDest, cchDest, lpstrSrc);
  368. }
  369. inline void strcatW_x(wchar_t* lpstrDest, size_t cchDest, const wchar_t* lpstrSrc)
  370. {
  371. ATL::Checked::wcscat_s(lpstrDest, cchDest, lpstrSrc);
  372. }
  373. inline void strcat_x(LPTSTR lpstrDest, size_t cchDest, LPCTSTR lpstrSrc)
  374. {
  375. #ifdef _UNICODE
  376. strcatW_x(lpstrDest, cchDest, lpstrSrc);
  377. #else
  378. strcatA_x(lpstrDest, cchDest, lpstrSrc);
  379. #endif
  380. }
  381. inline void memcpy_x(void* pDest, size_t cbDest, const void* pSrc, size_t cbSrc)
  382. {
  383. ATL::Checked::memcpy_s(pDest, cbDest, pSrc, cbSrc);
  384. }
  385. inline void memmove_x(void* pDest, size_t cbDest, const void* pSrc, size_t cbSrc)
  386. {
  387. ATL::Checked::memmove_s(pDest, cbDest, pSrc, cbSrc);
  388. }
  389. inline int vsprintf_x(LPTSTR lpstrBuff, size_t cchBuff, LPCTSTR lpstrFormat, va_list args)
  390. {
  391. return _vstprintf_s(lpstrBuff, cchBuff, lpstrFormat, args);
  392. }
  393. inline int wvsprintf_x(LPTSTR lpstrBuff, size_t cchBuff, LPCTSTR lpstrFormat, va_list args)
  394. {
  395. return _vstprintf_s(lpstrBuff, cchBuff, lpstrFormat, args);
  396. }
  397. inline int sprintf_x(LPTSTR lpstrBuff, size_t cchBuff, LPCTSTR lpstrFormat, ...)
  398. {
  399. va_list args;
  400. va_start(args, lpstrFormat);
  401. int nRes = vsprintf_x(lpstrBuff, cchBuff, lpstrFormat, args);
  402. va_end(args);
  403. return nRes;
  404. }
  405. inline int wsprintf_x(LPTSTR lpstrBuff, size_t cchBuff, LPCTSTR lpstrFormat, ...)
  406. {
  407. va_list args;
  408. va_start(args, lpstrFormat);
  409. int nRes = wvsprintf_x(lpstrBuff, cchBuff, lpstrFormat, args);
  410. va_end(args);
  411. return nRes;
  412. }
  413. } // namespace SecureHelper
  414. ///////////////////////////////////////////////////////////////////////////////
  415. // MinCrtHelper - WTL10 doesn't support _ATL_MIN_CRT,
  416. // these are here only for compatibility with existing projects
  417. namespace MinCrtHelper
  418. {
  419. inline int _isspace(TCHAR ch)
  420. {
  421. return _istspace(ch);
  422. }
  423. inline int _isdigit(TCHAR ch)
  424. {
  425. return _istdigit(ch);
  426. }
  427. inline int _atoi(LPCTSTR str)
  428. {
  429. return _ttoi(str);
  430. }
  431. inline LPCTSTR _strrchr(LPCTSTR str, TCHAR ch)
  432. {
  433. return _tcsrchr(str, ch);
  434. }
  435. inline LPTSTR _strrchr(LPTSTR str, TCHAR ch)
  436. {
  437. return _tcsrchr(str, ch);
  438. }
  439. } // namespace MinCrtHelper
  440. ///////////////////////////////////////////////////////////////////////////////
  441. // GenericWndClass - generic window class usable for subclassing
  442. // Use in dialog templates to specify a placeholder to be subclassed
  443. // Specify as a custom control with class name WTL_GenericWindow
  444. // Call Rregister() before creating dialog (for example, in WinMain)
  445. namespace GenericWndClass
  446. {
  447. inline LPCTSTR GetName()
  448. {
  449. return _T("WTL_GenericWindow");
  450. }
  451. inline ATOM Register()
  452. {
  453. WNDCLASSEX wc = { sizeof(WNDCLASSEX) };
  454. wc.lpfnWndProc = ::DefWindowProc;
  455. wc.hInstance = ModuleHelper::GetModuleInstance();
  456. wc.hCursor = ::LoadCursor(NULL, IDC_ARROW);
  457. wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  458. wc.lpszClassName = GetName();
  459. ATOM atom = ::RegisterClassEx(&wc);
  460. ATLASSERT(atom != 0);
  461. return atom;
  462. }
  463. inline BOOL Unregister() // only needed for DLLs or tmp use
  464. {
  465. return ::UnregisterClass(GetName(), ModuleHelper::GetModuleInstance());
  466. }
  467. } // namespace GenericWndClass
  468. ///////////////////////////////////////////////////////////////////////////////
  469. // CMessageFilter - Interface for message filter support
  470. class ATL_NO_VTABLE CMessageFilter
  471. {
  472. public:
  473. virtual BOOL PreTranslateMessage(MSG* pMsg) = 0;
  474. };
  475. ///////////////////////////////////////////////////////////////////////////////
  476. // CIdleHandler - Interface for idle processing
  477. class ATL_NO_VTABLE CIdleHandler
  478. {
  479. public:
  480. virtual BOOL OnIdle() = 0;
  481. };
  482. ///////////////////////////////////////////////////////////////////////////////
  483. // CMessageLoop - message loop implementation
  484. class CMessageLoop
  485. {
  486. public:
  487. ATL::CSimpleArray<CMessageFilter*> m_aMsgFilter;
  488. ATL::CSimpleArray<CIdleHandler*> m_aIdleHandler;
  489. MSG m_msg;
  490. CMessageLoop()
  491. {
  492. memset(&m_msg, 0, sizeof(m_msg));
  493. }
  494. virtual ~CMessageLoop()
  495. { }
  496. // Message filter operations
  497. BOOL AddMessageFilter(CMessageFilter* pMessageFilter)
  498. {
  499. return m_aMsgFilter.Add(pMessageFilter);
  500. }
  501. BOOL RemoveMessageFilter(CMessageFilter* pMessageFilter)
  502. {
  503. return m_aMsgFilter.Remove(pMessageFilter);
  504. }
  505. // Idle handler operations
  506. BOOL AddIdleHandler(CIdleHandler* pIdleHandler)
  507. {
  508. return m_aIdleHandler.Add(pIdleHandler);
  509. }
  510. BOOL RemoveIdleHandler(CIdleHandler* pIdleHandler)
  511. {
  512. return m_aIdleHandler.Remove(pIdleHandler);
  513. }
  514. // message loop
  515. int Run()
  516. {
  517. BOOL bDoIdle = TRUE;
  518. int nIdleCount = 0;
  519. BOOL bRet = FALSE;
  520. for(;;)
  521. {
  522. while(bDoIdle && !::PeekMessage(&m_msg, NULL, 0, 0, PM_NOREMOVE))
  523. {
  524. if(!OnIdle(nIdleCount++))
  525. bDoIdle = FALSE;
  526. }
  527. bRet = ::GetMessage(&m_msg, NULL, 0, 0);
  528. if(bRet == -1)
  529. {
  530. ATLTRACE2(atlTraceUI, 0, _T("::GetMessage returned -1 (error)\n"));
  531. continue; // error, don't process
  532. }
  533. else if(!bRet)
  534. {
  535. ATLTRACE2(atlTraceUI, 0, _T("CMessageLoop::Run - exiting\n"));
  536. break; // WM_QUIT, exit message loop
  537. }
  538. if(!PreTranslateMessage(&m_msg))
  539. {
  540. ::TranslateMessage(&m_msg);
  541. ::DispatchMessage(&m_msg);
  542. }
  543. if(IsIdleMessage(&m_msg))
  544. {
  545. bDoIdle = TRUE;
  546. nIdleCount = 0;
  547. }
  548. }
  549. return (int)m_msg.wParam;
  550. }
  551. // Overrideables
  552. // Override to change message filtering
  553. virtual BOOL PreTranslateMessage(MSG* pMsg)
  554. {
  555. // loop backwards
  556. for(int i = m_aMsgFilter.GetSize() - 1; i >= 0; i--)
  557. {
  558. CMessageFilter* pMessageFilter = m_aMsgFilter[i];
  559. if((pMessageFilter != NULL) && pMessageFilter->PreTranslateMessage(pMsg))
  560. return TRUE;
  561. }
  562. return FALSE; // not translated
  563. }
  564. // override to change idle processing
  565. virtual BOOL OnIdle(int /*nIdleCount*/)
  566. {
  567. for(int i = 0; i < m_aIdleHandler.GetSize(); i++)
  568. {
  569. CIdleHandler* pIdleHandler = m_aIdleHandler[i];
  570. if(pIdleHandler != NULL)
  571. pIdleHandler->OnIdle();
  572. }
  573. return FALSE; // don't continue
  574. }
  575. // override to change non-idle messages
  576. virtual BOOL IsIdleMessage(MSG* pMsg) const
  577. {
  578. // These messages should NOT cause idle processing
  579. switch(pMsg->message)
  580. {
  581. case WM_MOUSEMOVE:
  582. case WM_NCMOUSEMOVE:
  583. case WM_PAINT:
  584. case 0x0118: // WM_SYSTIMER (caret blink)
  585. return FALSE;
  586. }
  587. return TRUE;
  588. }
  589. };
  590. ///////////////////////////////////////////////////////////////////////////////
  591. // CStaticDataInitCriticalSectionLock and CWindowCreateCriticalSectionLock
  592. // internal classes to manage critical sections for ATL (deprecated)
  593. class CStaticDataInitCriticalSectionLock
  594. {
  595. public:
  596. ATL::CComCritSecLock<ATL::CComCriticalSection> m_cslock;
  597. CStaticDataInitCriticalSectionLock() : m_cslock(ATL::_pAtlModule->m_csStaticDataInitAndTypeInfo, false)
  598. { }
  599. HRESULT Lock()
  600. {
  601. return m_cslock.Lock();
  602. }
  603. void Unlock()
  604. {
  605. m_cslock.Unlock();
  606. }
  607. };
  608. class CWindowCreateCriticalSectionLock
  609. {
  610. public:
  611. ATL::CComCritSecLock<ATL::CComCriticalSection> m_cslock;
  612. CWindowCreateCriticalSectionLock() : m_cslock(ATL::_AtlWinModule.m_csWindowCreate, false)
  613. { }
  614. HRESULT Lock()
  615. {
  616. return m_cslock.Lock();
  617. }
  618. void Unlock()
  619. {
  620. m_cslock.Unlock();
  621. }
  622. };
  623. ///////////////////////////////////////////////////////////////////////////////
  624. // CAppModule - module class for an application
  625. #if (_MSC_VER == 1400) // VS2005
  626. #pragma warning(push)
  627. #pragma warning(disable : 4244)
  628. #pragma warning(disable : 4312)
  629. #endif
  630. class CAppModule : public ATL::CComModule
  631. {
  632. public:
  633. DWORD m_dwMainThreadID;
  634. ATL::CSimpleMap<DWORD, CMessageLoop*>* m_pMsgLoopMap;
  635. ATL::CSimpleArray<HWND>* m_pSettingChangeNotify;
  636. CAppModule() : m_dwMainThreadID(0), m_pMsgLoopMap(NULL), m_pSettingChangeNotify(NULL)
  637. { }
  638. // Overrides of CComModule::Init and Term
  639. HRESULT Init(ATL::_ATL_OBJMAP_ENTRY* pObjMap, HINSTANCE hInstance, const GUID* pLibID = NULL)
  640. {
  641. HRESULT hRet = CComModule::Init(pObjMap, hInstance, pLibID);
  642. if(FAILED(hRet))
  643. return hRet;
  644. m_dwMainThreadID = ::GetCurrentThreadId();
  645. typedef ATL::CSimpleMap<DWORD, CMessageLoop*> _mapClass;
  646. m_pMsgLoopMap = NULL;
  647. ATLTRY(m_pMsgLoopMap = new _mapClass);
  648. if(m_pMsgLoopMap == NULL)
  649. return E_OUTOFMEMORY;
  650. m_pSettingChangeNotify = NULL;
  651. return hRet;
  652. }
  653. void Term()
  654. {
  655. TermSettingChangeNotify();
  656. delete m_pMsgLoopMap;
  657. CComModule::Term();
  658. }
  659. // Message loop map methods
  660. BOOL AddMessageLoop(CMessageLoop* pMsgLoop)
  661. {
  662. CStaticDataInitCriticalSectionLock lock;
  663. if(FAILED(lock.Lock()))
  664. {
  665. ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CAppModule::AddMessageLoop.\n"));
  666. ATLASSERT(FALSE);
  667. return FALSE;
  668. }
  669. ATLASSERT(pMsgLoop != NULL);
  670. ATLASSERT(m_pMsgLoopMap->Lookup(::GetCurrentThreadId()) == NULL); // not in map yet
  671. BOOL bRet = m_pMsgLoopMap->Add(::GetCurrentThreadId(), pMsgLoop);
  672. lock.Unlock();
  673. return bRet;
  674. }
  675. BOOL RemoveMessageLoop()
  676. {
  677. CStaticDataInitCriticalSectionLock lock;
  678. if(FAILED(lock.Lock()))
  679. {
  680. ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CAppModule::RemoveMessageLoop.\n"));
  681. ATLASSERT(FALSE);
  682. return FALSE;
  683. }
  684. BOOL bRet = m_pMsgLoopMap->Remove(::GetCurrentThreadId());
  685. lock.Unlock();
  686. return bRet;
  687. }
  688. CMessageLoop* GetMessageLoop(DWORD dwThreadID = ::GetCurrentThreadId()) const
  689. {
  690. CStaticDataInitCriticalSectionLock lock;
  691. if(FAILED(lock.Lock()))
  692. {
  693. ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CAppModule::GetMessageLoop.\n"));
  694. ATLASSERT(FALSE);
  695. return NULL;
  696. }
  697. CMessageLoop* pLoop = m_pMsgLoopMap->Lookup(dwThreadID);
  698. lock.Unlock();
  699. return pLoop;
  700. }
  701. // Setting change notify methods
  702. // Note: Call this from the main thread for MSDI apps
  703. BOOL InitSettingChangeNotify(DLGPROC pfnDlgProc = _SettingChangeDlgProc)
  704. {
  705. CStaticDataInitCriticalSectionLock lock;
  706. if(FAILED(lock.Lock()))
  707. {
  708. ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CAppModule::InitSettingChangeNotify.\n"));
  709. ATLASSERT(FALSE);
  710. return FALSE;
  711. }
  712. if(m_pSettingChangeNotify == NULL)
  713. {
  714. typedef ATL::CSimpleArray<HWND> _notifyClass;
  715. ATLTRY(m_pSettingChangeNotify = new _notifyClass);
  716. ATLASSERT(m_pSettingChangeNotify != NULL);
  717. }
  718. BOOL bRet = (m_pSettingChangeNotify != NULL);
  719. if(bRet && (m_pSettingChangeNotify->GetSize() == 0))
  720. {
  721. // init everything
  722. _ATL_EMPTY_DLGTEMPLATE templ;
  723. HWND hNtfWnd = ::CreateDialogIndirect(GetModuleInstance(), &templ, NULL, pfnDlgProc);
  724. ATLASSERT(::IsWindow(hNtfWnd));
  725. if(::IsWindow(hNtfWnd))
  726. {
  727. ::SetWindowLongPtr(hNtfWnd, GWLP_USERDATA, (LONG_PTR)this);
  728. bRet = m_pSettingChangeNotify->Add(hNtfWnd);
  729. }
  730. else
  731. {
  732. bRet = FALSE;
  733. }
  734. }
  735. lock.Unlock();
  736. return bRet;
  737. }
  738. void TermSettingChangeNotify()
  739. {
  740. CStaticDataInitCriticalSectionLock lock;
  741. if(FAILED(lock.Lock()))
  742. {
  743. ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CAppModule::TermSettingChangeNotify.\n"));
  744. ATLASSERT(FALSE);
  745. return;
  746. }
  747. if((m_pSettingChangeNotify != NULL) && (m_pSettingChangeNotify->GetSize() > 0))
  748. ::DestroyWindow((*m_pSettingChangeNotify)[0]);
  749. delete m_pSettingChangeNotify;
  750. m_pSettingChangeNotify = NULL;
  751. lock.Unlock();
  752. }
  753. BOOL AddSettingChangeNotify(HWND hWnd)
  754. {
  755. CStaticDataInitCriticalSectionLock lock;
  756. if(FAILED(lock.Lock()))
  757. {
  758. ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CAppModule::AddSettingChangeNotify.\n"));
  759. ATLASSERT(FALSE);
  760. return FALSE;
  761. }
  762. ATLASSERT(::IsWindow(hWnd));
  763. BOOL bRet = FALSE;
  764. if(InitSettingChangeNotify() != FALSE)
  765. bRet = m_pSettingChangeNotify->Add(hWnd);
  766. lock.Unlock();
  767. return bRet;
  768. }
  769. BOOL RemoveSettingChangeNotify(HWND hWnd)
  770. {
  771. CStaticDataInitCriticalSectionLock lock;
  772. if(FAILED(lock.Lock()))
  773. {
  774. ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CAppModule::RemoveSettingChangeNotify.\n"));
  775. ATLASSERT(FALSE);
  776. return FALSE;
  777. }
  778. BOOL bRet = FALSE;
  779. if(m_pSettingChangeNotify != NULL)
  780. bRet = m_pSettingChangeNotify->Remove(hWnd);
  781. lock.Unlock();
  782. return bRet;
  783. }
  784. // Implementation - setting change notify dialog template and dialog procedure
  785. struct _ATL_EMPTY_DLGTEMPLATE : DLGTEMPLATE
  786. {
  787. _ATL_EMPTY_DLGTEMPLATE()
  788. {
  789. memset(this, 0, sizeof(_ATL_EMPTY_DLGTEMPLATE));
  790. style = WS_POPUP;
  791. }
  792. WORD wMenu, wClass, wTitle;
  793. };
  794. static INT_PTR CALLBACK _SettingChangeDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  795. {
  796. if(uMsg == WM_SETTINGCHANGE)
  797. {
  798. CAppModule* pModule = (CAppModule*)::GetWindowLongPtr(hWnd, GWLP_USERDATA);
  799. ATLASSERT(pModule != NULL);
  800. ATLASSERT(pModule->m_pSettingChangeNotify != NULL);
  801. const UINT uTimeout = 1500; // ms
  802. for(int i = 1; i < pModule->m_pSettingChangeNotify->GetSize(); i++)
  803. ::SendMessageTimeout((*pModule->m_pSettingChangeNotify)[i], uMsg, wParam, lParam, SMTO_ABORTIFHUNG, uTimeout, NULL);
  804. return TRUE;
  805. }
  806. return FALSE;
  807. }
  808. };
  809. #if (_MSC_VER == 1400) // VS2005
  810. #pragma warning(pop)
  811. #endif
  812. ///////////////////////////////////////////////////////////////////////////////
  813. // CServerAppModule - module class for a COM server application
  814. class CServerAppModule : public CAppModule
  815. {
  816. public:
  817. HANDLE m_hEventShutdown;
  818. bool m_bActivity;
  819. DWORD m_dwTimeOut;
  820. DWORD m_dwPause;
  821. CServerAppModule() : m_hEventShutdown(NULL), m_bActivity(false), m_dwTimeOut(5000), m_dwPause(1000)
  822. { }
  823. // Override of CAppModule::Init
  824. HRESULT Init(ATL::_ATL_OBJMAP_ENTRY* pObjMap, HINSTANCE hInstance, const GUID* pLibID = NULL)
  825. {
  826. m_dwTimeOut = 5000;
  827. m_dwPause = 1000;
  828. return CAppModule::Init(pObjMap, hInstance, pLibID);
  829. }
  830. void Term()
  831. {
  832. if((m_hEventShutdown != NULL) && ::CloseHandle(m_hEventShutdown))
  833. m_hEventShutdown = NULL;
  834. CAppModule::Term();
  835. }
  836. // COM Server methods
  837. LONG Unlock() throw()
  838. {
  839. LONG lRet = CComModule::Unlock();
  840. if(lRet == 0)
  841. {
  842. m_bActivity = true;
  843. ::SetEvent(m_hEventShutdown); // tell monitor that we transitioned to zero
  844. }
  845. return lRet;
  846. }
  847. void MonitorShutdown()
  848. {
  849. for(;;)
  850. {
  851. ::WaitForSingleObject(m_hEventShutdown, INFINITE);
  852. DWORD dwWait = 0;
  853. do
  854. {
  855. m_bActivity = false;
  856. dwWait = ::WaitForSingleObject(m_hEventShutdown, m_dwTimeOut);
  857. }
  858. while(dwWait == WAIT_OBJECT_0);
  859. // timed out
  860. if(!m_bActivity && (m_nLockCnt == 0)) // if no activity let's really bail
  861. {
  862. #if defined(_WIN32_DCOM) && defined(_ATL_FREE_THREADED)
  863. ::CoSuspendClassObjects();
  864. if(!m_bActivity && (m_nLockCnt == 0))
  865. #endif
  866. break;
  867. }
  868. }
  869. // This handle should be valid now. If it isn't,
  870. // check if _Module.Term was called first (it shouldn't)
  871. if(::CloseHandle(m_hEventShutdown))
  872. m_hEventShutdown = NULL;
  873. ::PostThreadMessage(m_dwMainThreadID, WM_QUIT, 0, 0);
  874. }
  875. bool StartMonitor()
  876. {
  877. m_hEventShutdown = ::CreateEvent(NULL, false, false, NULL);
  878. if(m_hEventShutdown == NULL)
  879. return false;
  880. DWORD dwThreadID = 0;
  881. #ifdef _MT
  882. HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0, (UINT (WINAPI*)(void*))MonitorProc, this, 0, (UINT*)&dwThreadID);
  883. #else
  884. HANDLE hThread = ::CreateThread(NULL, 0, MonitorProc, this, 0, &dwThreadID);
  885. #endif
  886. bool bRet = (hThread != NULL);
  887. if(bRet)
  888. ::CloseHandle(hThread);
  889. return bRet;
  890. }
  891. static DWORD WINAPI MonitorProc(void* pv)
  892. {
  893. CServerAppModule* p = (CServerAppModule*)pv;
  894. p->MonitorShutdown();
  895. return 0;
  896. }
  897. };
  898. ///////////////////////////////////////////////////////////////////////////////
  899. // CRegKeyEx - not used any more, here only for compatibility with old projects
  900. typedef ATL::CRegKey CRegKeyEx;
  901. } // namespace WTL
  902. ///////////////////////////////////////////////////////////////////////////////
  903. // CString forward reference (enables CString use in atluser.h and atlgdi.h)
  904. #if (defined(_WTL_USE_CSTRING) || defined(_WTL_FORWARD_DECLARE_CSTRING)) && !defined(__ATLSTR_H__)
  905. #include <atlstr.h>
  906. #endif
  907. // CString namespace
  908. #define _CSTRING_NS ATL
  909. // Type classes namespace
  910. #define _WTYPES_NS
  911. ///////////////////////////////////////////////////////////////////////////////
  912. // General DLL version helpers (removed in ATL11)
  913. #if (_ATL_VER >= 0x0B00)
  914. namespace ATL
  915. {
  916. inline HRESULT AtlGetDllVersion(HINSTANCE hInstDLL, DLLVERSIONINFO* pDllVersionInfo)
  917. {
  918. ATLASSERT(pDllVersionInfo != NULL);
  919. if(pDllVersionInfo == NULL)
  920. return E_INVALIDARG;
  921. // We must get this function explicitly because some DLLs don't implement it.
  922. DLLGETVERSIONPROC pfnDllGetVersion = (DLLGETVERSIONPROC)::GetProcAddress(hInstDLL, "DllGetVersion");
  923. if(pfnDllGetVersion == NULL)
  924. return E_NOTIMPL;
  925. return (*pfnDllGetVersion)(pDllVersionInfo);
  926. }
  927. inline HRESULT AtlGetDllVersion(LPCTSTR lpstrDllName, DLLVERSIONINFO* pDllVersionInfo)
  928. {
  929. HINSTANCE hInstDLL = ::LoadLibrary(lpstrDllName);
  930. if(hInstDLL == NULL)
  931. return E_FAIL;
  932. HRESULT hRet = AtlGetDllVersion(hInstDLL, pDllVersionInfo);
  933. ::FreeLibrary(hInstDLL);
  934. return hRet;
  935. }
  936. // Common Control Versions:
  937. // Win95/WinNT 4.0 maj=4 min=00
  938. // IE 3.x maj=4 min=70
  939. // IE 4.0 maj=4 min=71
  940. inline HRESULT AtlGetCommCtrlVersion(LPDWORD pdwMajor, LPDWORD pdwMinor)
  941. {
  942. ATLASSERT((pdwMajor != NULL) && (pdwMinor != NULL));
  943. if((pdwMajor == NULL) || (pdwMinor == NULL))
  944. return E_INVALIDARG;
  945. DLLVERSIONINFO dvi;
  946. ::ZeroMemory(&dvi, sizeof(dvi));
  947. dvi.cbSize = sizeof(dvi);
  948. HRESULT hRet = AtlGetDllVersion(_T("comctl32.dll"), &dvi);
  949. if(SUCCEEDED(hRet))
  950. {
  951. *pdwMajor = dvi.dwMajorVersion;
  952. *pdwMinor = dvi.dwMinorVersion;
  953. }
  954. else if(hRet == E_NOTIMPL)
  955. {
  956. // If DllGetVersion is not there, then the DLL is a version
  957. // previous to the one shipped with IE 3.x
  958. *pdwMajor = 4;
  959. *pdwMinor = 0;
  960. hRet = S_OK;
  961. }
  962. return hRet;
  963. }
  964. // Shell Versions:
  965. // Win95/WinNT 4.0 maj=4 min=00
  966. // IE 3.x, IE 4.0 without Web Integrated Desktop maj=4 min=00
  967. // IE 4.0 with Web Integrated Desktop maj=4 min=71
  968. // IE 4.01 with Web Integrated Desktop maj=4 min=72
  969. inline HRESULT AtlGetShellVersion(LPDWORD pdwMajor, LPDWORD pdwMinor)
  970. {
  971. ATLASSERT((pdwMajor != NULL) && (pdwMinor != NULL));
  972. if((pdwMajor == NULL) || (pdwMinor == NULL))
  973. return E_INVALIDARG;
  974. DLLVERSIONINFO dvi;
  975. ::ZeroMemory(&dvi, sizeof(dvi));
  976. dvi.cbSize = sizeof(dvi);
  977. HRESULT hRet = AtlGetDllVersion(_T("shell32.dll"), &dvi);
  978. if(SUCCEEDED(hRet))
  979. {
  980. *pdwMajor = dvi.dwMajorVersion;
  981. *pdwMinor = dvi.dwMinorVersion;
  982. }
  983. else if(hRet == E_NOTIMPL)
  984. {
  985. // If DllGetVersion is not there, then the DLL is a version
  986. // previous to the one shipped with IE 4.x
  987. *pdwMajor = 4;
  988. *pdwMinor = 0;
  989. hRet = S_OK;
  990. }
  991. return hRet;
  992. }
  993. } // namespace ATL
  994. #endif // (_ATL_VER >= 0x0B00)
  995. // These are always included
  996. #include "atlwinx.h"
  997. #include "atluser.h"
  998. #include "atlgdi.h"
  999. #ifndef _WTL_NO_AUTOMATIC_NAMESPACE
  1000. using namespace WTL;
  1001. #endif // !_WTL_NO_AUTOMATIC_NAMESPACE
  1002. #endif // __ATLAPP_H__