判断Windows版本号

类别:VC语言 点击:0 评论:0 推荐:

API函数:GetVersionEx()
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  OSVERSIONINFO info ;
  info.dwOSVersionInfoSize = sizeof (info) ;
  GetVersionEx (&info) ;

  switch (info.dwPlatformId)
  {
  case VER_PLATFORM_WIN32s:
    Label1->Caption = "System:  Windows Win 32s" ;
    break ;
  case VER_PLATFORM_WIN32_WINDOWS:
    Label1->Caption = "System:  Windows 95" ;
    break ;
  case VER_PLATFORM_WIN32_NT:
    Label1->Caption = "System:  Windows NT" ;
    break ;
  default:
    Label1->Caption = "System:  Unknown" ;
    break ;
  }

  Label2->Caption = String ("Version: ")
    + String ((int) info.dwMajorVersion) + "." + String((int)info.dwMinorVersion) ;
  Label3->Caption = String ("Build:  ") + String ((int) (info.dwBuildNumber & 0xFFFF)) ;
  Label4->Caption = String ("System Info:  '") + info.szCSDVersion + "'" ;
}
或者

The following code fragment illustrates how to extract information from the GetVersion return value:

 
dwVersion = GetVersion();

// Get major and minor version numbers of Windows

dwWindowsMajorVersion =  (DWORD)(LOBYTE(LOWORD(dwVersion)));
dwWindowsMinorVersion =  (DWORD)(HIBYTE(LOWORD(dwVersion)));

// Get build numbers for Windows NT or Win32s

if (dwVersion < 0x80000000)                // Windows NT
    dwBuild = (DWORD)(HIWORD(dwVersion));
else if (dwWindowsMajorVersion < 4)        // Win32s
    dwBuild = (DWORD)(HIWORD(dwVersion) & ~0x8000);
else        // Windows 95 -- No build numbers provided

    dwBuild =  0;

 

 

 

 

 

 

本文地址:http://com.8s8s.com/it/it3536.htm