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