ResizableVersion.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. // ResizableVersion.cpp: implementation of the CResizableVersion class.
  2. //
  3. /////////////////////////////////////////////////////////////////////////////
  4. //
  5. // This file is part of ResizableLib
  6. // https://github.com/ppescher/resizablelib
  7. //
  8. // Copyright (C) 2000-2015 by Paolo Messina
  9. // mailto:ppescher@hotmail.com
  10. //
  11. // The contents of this file are subject to the Artistic License 2.0
  12. // http://opensource.org/licenses/Artistic-2.0
  13. //
  14. // If you find this code useful, credits would be nice!
  15. //
  16. /////////////////////////////////////////////////////////////////////////////
  17. #include "stdafx.h"
  18. #include "ResizableVersion.h"
  19. #include <Shlwapi.h>
  20. //////////////////////////////////////////////////////////////////////
  21. // Static initializer object (with macros to hide in ClassView)
  22. // static intializer must be called before user code
  23. #pragma warning(disable:4073)
  24. #pragma init_seg(lib)
  25. #ifdef _UNDEFINED_
  26. #define BEGIN_HIDDEN {
  27. #define END_HIDDEN }
  28. #else
  29. #define BEGIN_HIDDEN
  30. #define END_HIDDEN
  31. #endif
  32. BEGIN_HIDDEN
  33. struct _VersionInitializer
  34. {
  35. _VersionInitializer()
  36. {
  37. InitRealVersions();
  38. };
  39. };
  40. END_HIDDEN
  41. // The one and only version-check object
  42. static _VersionInitializer g_version;
  43. //////////////////////////////////////////////////////////////////////
  44. // Private implementation
  45. static DLLVERSIONINFO g_dviCommCtrls;
  46. static OSVERSIONINFOEX g_osviWindows;
  47. static void CheckOsVersion()
  48. {
  49. // Try calling GetVersionEx using the OSVERSIONINFOEX structure.
  50. ZeroMemory(&g_osviWindows, sizeof(OSVERSIONINFOEX));
  51. g_osviWindows.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  52. if (GetVersionEx((LPOSVERSIONINFO)&g_osviWindows))
  53. return;
  54. // If that fails, try using the OSVERSIONINFO structure.
  55. g_osviWindows.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
  56. if (GetVersionEx((LPOSVERSIONINFO)&g_osviWindows))
  57. return;
  58. // When all the above fails, set values for the worst case
  59. g_osviWindows.dwMajorVersion = 4;
  60. g_osviWindows.dwMinorVersion = 0;
  61. g_osviWindows.dwBuildNumber = 0;
  62. g_osviWindows.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS;
  63. g_osviWindows.szCSDVersion[0] = TEXT('\0');
  64. }
  65. static void CheckCommCtrlsVersion()
  66. {
  67. // Check Common Controls version
  68. ZeroMemory(&g_dviCommCtrls, sizeof(DLLVERSIONINFO));
  69. HMODULE hMod = ::LoadLibrary(_T("comctl32.dll"));
  70. if (hMod != NULL)
  71. {
  72. // Get the version function
  73. DLLGETVERSIONPROC pfnDllGetVersion;
  74. pfnDllGetVersion = (DLLGETVERSIONPROC)GetProcAddress(hMod, "DllGetVersion");
  75. if (pfnDllGetVersion != NULL)
  76. {
  77. // Obtain version information
  78. g_dviCommCtrls.cbSize = sizeof(DLLVERSIONINFO);
  79. if (SUCCEEDED(pfnDllGetVersion(&g_dviCommCtrls)))
  80. {
  81. ::FreeLibrary(hMod);
  82. return;
  83. }
  84. }
  85. ::FreeLibrary(hMod);
  86. }
  87. // Set values for the worst case
  88. g_dviCommCtrls.dwMajorVersion = 4;
  89. g_dviCommCtrls.dwMinorVersion = 0;
  90. g_dviCommCtrls.dwBuildNumber = 0;
  91. g_dviCommCtrls.dwPlatformID = DLLVER_PLATFORM_WINDOWS;
  92. }
  93. //////////////////////////////////////////////////////////////////////
  94. // Exported global symbols
  95. DWORD realWINVER = 0;
  96. #ifdef _WIN32_WINDOWS
  97. DWORD real_WIN32_WINDOWS = 0;
  98. #endif
  99. #ifdef _WIN32_WINNT
  100. DWORD real_WIN32_WINNT = 0;
  101. #endif
  102. #ifdef _WIN32_IE
  103. DWORD real_WIN32_IE = 0;
  104. #endif
  105. DWORD real_ThemeSettings = 0;
  106. // macro to convert version numbers to hex format
  107. #define CNV_OS_VER(x) ((BYTE)(((BYTE)(x) / 10 * 16) | ((BYTE)(x) % 10)))
  108. void InitRealVersions()
  109. {
  110. CheckCommCtrlsVersion();
  111. CheckOsVersion();
  112. // set real version values
  113. realWINVER = MAKEWORD(CNV_OS_VER(g_osviWindows.dwMinorVersion),
  114. CNV_OS_VER(g_osviWindows.dwMajorVersion));
  115. #ifdef _WIN32_WINDOWS
  116. if (g_osviWindows.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
  117. real_WIN32_WINDOWS = realWINVER;
  118. else
  119. real_WIN32_WINDOWS = 0;
  120. #endif
  121. #ifdef _WIN32_WINNT
  122. if (g_osviWindows.dwPlatformId == VER_PLATFORM_WIN32_NT)
  123. real_WIN32_WINNT = realWINVER;
  124. else
  125. real_WIN32_WINNT = 0;
  126. #endif
  127. #ifdef _WIN32_IE
  128. switch (g_dviCommCtrls.dwMajorVersion)
  129. {
  130. case 4:
  131. switch (g_dviCommCtrls.dwMinorVersion)
  132. {
  133. case 70:
  134. real_WIN32_IE = 0x0300;
  135. break;
  136. case 71:
  137. real_WIN32_IE = 0x0400;
  138. break;
  139. case 72:
  140. real_WIN32_IE = 0x0401;
  141. break;
  142. default:
  143. real_WIN32_IE = 0x0200;
  144. }
  145. break;
  146. case 5:
  147. if (g_dviCommCtrls.dwMinorVersion > 80)
  148. real_WIN32_IE = 0x0501;
  149. else
  150. real_WIN32_IE = 0x0500;
  151. break;
  152. case 6:
  153. real_WIN32_IE = 0x0600; // includes checks for 0x0560 (IE6)
  154. break;
  155. default:
  156. real_WIN32_IE = 0;
  157. }
  158. #endif
  159. }
  160. // Whether non-client area is using XP Visual Style
  161. void InitThemeSettings()
  162. {
  163. real_ThemeSettings = 0;
  164. typedef BOOL (STDAPICALLTYPE * IS_APP_THEMED)(VOID);
  165. typedef DWORD (STDAPICALLTYPE * GET_THEME_APP_PROPERTIES)(VOID);
  166. // check dll is in place, themes can't work without
  167. HMODULE hLib = GetModuleHandle(_T("uxtheme.dll"));
  168. if (hLib == NULL)
  169. return;
  170. // check calling process has themes enabled
  171. IS_APP_THEMED pfnIsAppThemed =
  172. (IS_APP_THEMED) GetProcAddress(hLib, "IsAppThemed");
  173. ASSERT(pfnIsAppThemed);
  174. if (!pfnIsAppThemed())
  175. return;
  176. // check application theme includes non-client area
  177. GET_THEME_APP_PROPERTIES pfnGetThemeAppProperties =
  178. (GET_THEME_APP_PROPERTIES) GetProcAddress(hLib, "GetThemeAppProperties");
  179. ASSERT(pfnGetThemeAppProperties);
  180. real_ThemeSettings = pfnGetThemeAppProperties();
  181. }