1 // ResizableVersion.cpp: implementation of the CResizableVersion class.
3 /////////////////////////////////////////////////////////////////////////////
5 // This file is part of ResizableLib
6 // http://sourceforge.net/projects/resizablelib
8 // Copyright (C) 2000-2004 by Paolo Messina
9 // http://www.geocities.com/ppescher - mailto:ppescher@hotmail.com
11 // The contents of this file are subject to the Artistic License (the "License").
12 // You may not use this file except in compliance with the License.
13 // You may obtain a copy of the License at:
14 // http://www.opensource.org/licenses/artistic-license.html
16 // If you find this code useful, credits would be nice!
18 /////////////////////////////////////////////////////////////////////////////
21 #include "ResizableVersion.h"
23 //////////////////////////////////////////////////////////////////////
24 // Static initializer object (with macros to hide in ClassView)
26 // static intializer must be called before user code
27 #pragma warning(disable:4073)
31 #define BEGIN_HIDDEN {
39 struct _VersionInitializer
48 // The one and only version-check object
49 static _VersionInitializer g_version
;
51 //////////////////////////////////////////////////////////////////////
52 // Private implementation
54 // DLL Version support
57 static DLLVERSIONINFO g_dviCommCtrls
;
58 static OSVERSIONINFOEX g_osviWindows
;
60 static void CheckOsVersion()
62 // Try calling GetVersionEx using the OSVERSIONINFOEX structure.
63 SecureZeroMemory(&g_osviWindows
, sizeof(OSVERSIONINFOEX
));
64 g_osviWindows
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
65 if (GetVersionEx((LPOSVERSIONINFO
)&g_osviWindows
))
68 // If that fails, try using the OSVERSIONINFO structure.
69 g_osviWindows
.dwOSVersionInfoSize
= sizeof (OSVERSIONINFO
);
70 if (GetVersionEx((LPOSVERSIONINFO
)&g_osviWindows
))
73 // When all the above fails, set values for the worst case
74 g_osviWindows
.dwMajorVersion
= 4;
75 g_osviWindows
.dwMinorVersion
= 0;
76 g_osviWindows
.dwBuildNumber
= 0;
77 g_osviWindows
.dwPlatformId
= VER_PLATFORM_WIN32_WINDOWS
;
78 g_osviWindows
.szCSDVersion
[0] = TEXT('\0');
81 static void CheckCommCtrlsVersion()
83 // Check Common Controls version
84 SecureZeroMemory(&g_dviCommCtrls
, sizeof(DLLVERSIONINFO
));
85 HMODULE hMod
= ::LoadLibrary(_T("comctl32.dll"));
88 // Get the version function
89 DLLGETVERSIONPROC pfnDllGetVersion
;
90 pfnDllGetVersion
= (DLLGETVERSIONPROC
)GetProcAddress(hMod
, "DllGetVersion");
92 if (pfnDllGetVersion
!= NULL
)
94 // Obtain version information
95 g_dviCommCtrls
.cbSize
= sizeof(DLLVERSIONINFO
);
96 if (SUCCEEDED(pfnDllGetVersion(&g_dviCommCtrls
)))
106 // Set values for the worst case
107 g_dviCommCtrls
.dwMajorVersion
= 4;
108 g_dviCommCtrls
.dwMinorVersion
= 0;
109 g_dviCommCtrls
.dwBuildNumber
= 0;
110 g_dviCommCtrls
.dwPlatformID
= DLLVER_PLATFORM_WINDOWS
;
114 //////////////////////////////////////////////////////////////////////
115 // Exported global symbols
117 DWORD realWINVER
= 0;
119 #ifdef _WIN32_WINDOWS
120 DWORD real_WIN32_WINDOWS
= 0;
124 DWORD real_WIN32_WINNT
= 0;
128 DWORD real_WIN32_IE
= 0;
131 // macro to convert version numbers to hex format
132 #define CNV_OS_VER(x) ((BYTE)(((BYTE)(x) / 10 * 16) | ((BYTE)(x) % 10)))
134 void InitRealVersions()
136 CheckCommCtrlsVersion();
139 // set real version values
141 realWINVER
= MAKEWORD(CNV_OS_VER(g_osviWindows
.dwMinorVersion
),
142 CNV_OS_VER(g_osviWindows
.dwMajorVersion
));
144 #ifdef _WIN32_WINDOWS
145 if (g_osviWindows
.dwPlatformId
== VER_PLATFORM_WIN32_WINDOWS
)
146 real_WIN32_WINDOWS
= realWINVER
;
148 real_WIN32_WINDOWS
= 0;
152 if (g_osviWindows
.dwPlatformId
== VER_PLATFORM_WIN32_NT
)
153 real_WIN32_WINNT
= realWINVER
;
155 real_WIN32_WINNT
= 0;
159 switch (g_dviCommCtrls
.dwMajorVersion
)
162 switch (g_dviCommCtrls
.dwMinorVersion
)
165 real_WIN32_IE
= 0x0300;
168 real_WIN32_IE
= 0x0400;
171 real_WIN32_IE
= 0x0401;
174 real_WIN32_IE
= 0x0200;
178 if (g_dviCommCtrls
.dwMinorVersion
> 80)
179 real_WIN32_IE
= 0x0501;
181 real_WIN32_IE
= 0x0500;
184 real_WIN32_IE
= 0x0600; // includes checks for 0x0560 (IE6)