Merge branch 'scintilla-357'
[TortoiseGit.git] / ext / ResizableLib / ResizableVersion.cpp
blob2d13f7bd899e9c83d4dacfb3986eb6f84f641023
1 // ResizableVersion.cpp: implementation of the CResizableVersion class.
2 //
3 /////////////////////////////////////////////////////////////////////////////
4 //
5 // This file is part of ResizableLib
6 // http://sourceforge.net/projects/resizablelib
7 //
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 /////////////////////////////////////////////////////////////////////////////
20 #include "stdafx.h"
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)
28 #pragma init_seg(lib)
30 #ifdef _UNDEFINED_
31 #define BEGIN_HIDDEN {
32 #define END_HIDDEN }
33 #else
34 #define BEGIN_HIDDEN
35 #define END_HIDDEN
36 #endif
38 BEGIN_HIDDEN
39 struct _VersionInitializer
41 _VersionInitializer()
43 InitRealVersions();
46 END_HIDDEN
48 // The one and only version-check object
49 static _VersionInitializer g_version;
51 //////////////////////////////////////////////////////////////////////
52 // Private implementation
54 // DLL Version support
55 #include <shlwapi.h>
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))
66 return;
68 // If that fails, try using the OSVERSIONINFO structure.
69 g_osviWindows.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
70 if (GetVersionEx((LPOSVERSIONINFO)&g_osviWindows))
71 return;
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 = AtlLoadSystemLibraryUsingFullPath(_T("comctl32.dll"));
86 if (hMod != NULL)
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)))
98 ::FreeLibrary(hMod);
99 return;
103 ::FreeLibrary(hMod);
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;
121 #endif
123 #ifdef _WIN32_WINNT
124 DWORD real_WIN32_WINNT = 0;
125 #endif
127 #ifdef _WIN32_IE
128 DWORD real_WIN32_IE = 0;
129 #endif
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();
137 CheckOsVersion();
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;
147 else
148 real_WIN32_WINDOWS = 0;
149 #endif
151 #ifdef _WIN32_WINNT
152 if (g_osviWindows.dwPlatformId == VER_PLATFORM_WIN32_NT)
153 real_WIN32_WINNT = realWINVER;
154 else
155 real_WIN32_WINNT = 0;
156 #endif
158 #ifdef _WIN32_IE
159 switch (g_dviCommCtrls.dwMajorVersion)
161 case 4:
162 switch (g_dviCommCtrls.dwMinorVersion)
164 case 70:
165 real_WIN32_IE = 0x0300;
166 break;
167 case 71:
168 real_WIN32_IE = 0x0400;
169 break;
170 case 72:
171 real_WIN32_IE = 0x0401;
172 break;
173 default:
174 real_WIN32_IE = 0x0200;
176 break;
177 case 5:
178 if (g_dviCommCtrls.dwMinorVersion > 80)
179 real_WIN32_IE = 0x0501;
180 else
181 real_WIN32_IE = 0x0500;
182 break;
183 case 6:
184 real_WIN32_IE = 0x0600; // includes checks for 0x0560 (IE6)
185 break;
186 default:
187 real_WIN32_IE = 0;
189 #endif