判断当前操作系统
原文来自:http://blog.gameres.com/thread.asp?BlogID=155&threadid=20286
//判断操作系统版本
#include <windows.h>
/*++------------------------------------------------------------------------
Function:
IsWin9x
Modification History:
Jurassic 03/17/2003 Created.
--------------------------------------------------------------------------*/
bool
__stdcall
IsWin9x(
void
)
{
OSVERSIONINFO VerInfo;
bool bRet=false;
VerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if ( GetVersionEx(&VerInfo))
{
if (VerInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
{
bRet=true;
}
}
return (bRet);
}
/*++------------------------------------------------------------------------
Function:
IsWinNt
Modification History:
Jurassic 03/17/2003 Created.
--------------------------------------------------------------------------*/
bool
__stdcall
IsWinNt(
void
)
{
OSVERSIONINFO VerInfo;
bool bRet=false;
VerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if( GetVersionEx(&VerInfo))
{
if (VerInfo.dwPlatformId == VER_PLATFORM_WIN32_NT &&
VerInfo.dwMajorVersion == 4)
{
bRet=true;
}
}
return (bRet);
}
/*++------------------------------------------------------------------------
Function:
IsWin2k
Modification History:
Jurassic 03/17/2003 Created.
--------------------------------------------------------------------------*/
bool
__stdcall
IsWin2k(
void
)
{
OSVERSIONINFO VerInfo;
bool bRet=false;
VerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if( GetVersionEx(&VerInfo))
{
if (VerInfo.dwPlatformId == VER_PLATFORM_WIN32_NT &&
VerInfo.dwMajorVersion == 5 &&
VerInfo.dwMinorVersion == 0)
{
bRet=true;
}
}
return (bRet);
}
/*++------------------------------------------------------------------------
Function:
IsWinxp
Modification History:
Jurassic 03/17/2003 Created.
--------------------------------------------------------------------------*/
bool
_stdcall
IsWinXp(
void
)
{
OSVERSIONINFO VerInfo;
bool bRet=false;
VerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if( GetVersionEx(&VerInfo))
{
if (VerInfo.dwPlatformId==VER_PLATFORM_WIN32_NT &&
VerInfo.dwMajorVersion == 5 &&
VerInfo.dwMinorVersion == 1)
{
bRet=true;
}
}
return (bRet);
}
补充一下
原型
BOOL GetVersionEx(
LPOSVERSIONINFO lpVersionInformation);
typedef struct _OSVERSIONINFO{
DWORD dwOSVersionInfoSize;
DWORD dwMajorVersion;
DWORD dwMinorVersion;
DWORD dwBuildNumber;
DWORD dwPlatformId;
TCHAR szCSDVersion;
} OSVERSIONINFO;
参数具体含义MSDN中有具体解释,偶就不画蛇添足了
对LongHorn系统的判断
这个我在MSDN2003没有发现,不知道2005里有没有
页:
[1]