Introduction
The GetVersion
function returns the current version number of the operating system. If the function succeeds, the return value is a DWORD
value that contains the major and minor version numbers of the operating system in the low order word, and information about the operating system platform in the high order word.
For all platforms, the low order word contains the version number of the operating system. The low-order byte of this word specifies the major version number, in hexadecimal notation. The high-order byte specifies the minor version (revision) number, in hexadecimal notation.
In the table, you can find the examples for several Windows platforms:
Often programmers need to get the currently running version of the system. The code in this article will show you how to identify the Windows platforms.
Macros definition
Windows version macros compare operating system version requirements to the corresponding values for the currently running version of the system. This enables you to easily determine the presence of a required set of operating system version conditions.
#define WinVerMajor() LOBYTE(LOWORD(GetVersion()))
#define WinVerMinor() HIBYTE(LOWORD(GetVersion()))
#define IsWinVerNTs() (GetVersion() < 0x80000000)
#define IsWinVerNT351Plus() (IsWinVerNTs() && WinVerMajor() >= 3)
#define IsWinVerNT4Plus() (IsWinVerNTs() && WinVerMajor() > 3)
#define IsWinVer98Plus() (LOWORD(GetVersion()) != 4)
#define IsWinVerMEPlus() (WinVerMajor() >= 5 || WinVerMinor() > 10)
#define IsWinVer2000Plus() (WinVerMajor() >= 5)
#define IsWinVerXPPlus() (WinVerMajor() >= 5 && LOWORD(GetVersion()) != 5)
If the currently running operating system satisfies the specified requirements, the return value is a nonzero value. If the current system does not satisfy the requirements, the return value is zero.
Using the macros
These examples will show you how easilyy you can use the macros in your applications:
if (IsWinVerMEPlus())
{
printf("If you can see this message you"
" are running Windows ME or higher! \n");
}
else
{
printf("If you can see this message you are running Windows 95 or 98! \n");
}
if (IsWinVerXPPlus())
{
printf("If you can see this message you are running Windows XP or 2003! \n");
}
if (IsWinVer2000Plus())
{
printf("Your operating system supports the opacity"
" and transparency color key of a layered window! \n");
}