cache the result of wxGetOsVersion() (heavily modified patch 1783198)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48621 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1199,32 +1199,64 @@ bool wxIsPlatform64Bit()
|
|||||||
|
|
||||||
wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin)
|
wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin)
|
||||||
{
|
{
|
||||||
|
static struct
|
||||||
|
{
|
||||||
|
// this may be false, true or -1 if we tried to initialize but failed
|
||||||
|
int initialized;
|
||||||
|
|
||||||
|
wxOperatingSystemId os;
|
||||||
|
|
||||||
|
int verMaj,
|
||||||
|
verMin;
|
||||||
|
} s_version;
|
||||||
|
|
||||||
|
// query the OS info only once as it's not supposed to change
|
||||||
|
if ( !s_version.initialized )
|
||||||
|
{
|
||||||
OSVERSIONINFO info;
|
OSVERSIONINFO info;
|
||||||
wxZeroMemory(info);
|
wxZeroMemory(info);
|
||||||
|
info.dwOSVersionInfoSize = sizeof(info);
|
||||||
info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
|
||||||
if ( ::GetVersionEx(&info) )
|
if ( ::GetVersionEx(&info) )
|
||||||
{
|
{
|
||||||
if (verMaj) *verMaj = info.dwMajorVersion;
|
s_version.initialized = true;
|
||||||
if (verMin) *verMin = info.dwMinorVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined( __WXWINCE__ )
|
#if defined(__WXWINCE__)
|
||||||
return wxOS_WINDOWS_CE;
|
s_version.os = wxOS_WINDOWS_CE;
|
||||||
#elif defined( __WXMICROWIN__ )
|
#elif defined(__WXMICROWIN__)
|
||||||
return wxOS_WINDOWS_MICRO;
|
s_version.os = wxOS_WINDOWS_MICRO;
|
||||||
#else
|
#else // "normal" desktop Windows system, use run-time detection
|
||||||
switch ( info.dwPlatformId )
|
switch ( info.dwPlatformId )
|
||||||
{
|
{
|
||||||
case VER_PLATFORM_WIN32_NT:
|
case VER_PLATFORM_WIN32_NT:
|
||||||
return wxOS_WINDOWS_NT;
|
s_version.os = wxOS_WINDOWS_NT;
|
||||||
|
break;
|
||||||
|
|
||||||
case VER_PLATFORM_WIN32_WINDOWS:
|
case VER_PLATFORM_WIN32_WINDOWS:
|
||||||
return wxOS_WINDOWS_9X;
|
s_version.os = wxOS_WINDOWS_9X;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif // Windows versions
|
||||||
|
|
||||||
|
s_version.verMaj = info.dwMajorVersion;
|
||||||
|
s_version.verMin = info.dwMinorVersion;
|
||||||
|
}
|
||||||
|
else // GetVersionEx() failed
|
||||||
|
{
|
||||||
|
s_version.initialized = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return wxOS_UNKNOWN;
|
if ( s_version.initialized == 1 )
|
||||||
#endif
|
{
|
||||||
|
if ( verMaj )
|
||||||
|
*verMaj = s_version.verMaj;
|
||||||
|
if ( verMin )
|
||||||
|
*verMin = s_version.verMin;
|
||||||
|
}
|
||||||
|
|
||||||
|
// this works even if we were not initialized successfully as the initial
|
||||||
|
// values of this field is 0 which is wxOS_UNKNOWN and exactly what we need
|
||||||
|
return s_version.os;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxWinVersion wxGetWinVersion()
|
wxWinVersion wxGetWinVersion()
|
||||||
|
Reference in New Issue
Block a user