OSVERSIONINFO结构

typedef struct _OSVERSIONINFO {
DWORD dwOSVersionInfoSize;
DWORD dwMajorVersion;
DWORD dwMinorVersion;
DWORD dwBuildNumber;
DWORD dwPlatformId;
TCHAR szCSDVersion[128];
OSVERSIONINFO;


该结构体包含操作系统的版本信息。包括操作系统的主版本号、副版本号、创建号、以及操作系统平台ID号和关于操作系统的其他描述信息。

dwOSVersionInfoSize:指定该数据结构的字节大小。

dwMajorVersion:操作系统的主版本号

dwMinorVersion:操作系统的副版本号

dwBuildNumber:操作系统的创建号

dwPlatformId:操作系统平台ID号
其中dwPlatformId可为以下值:
VER_PLATFORM_WIN32s:标识为Windows 3.1;
VER_PLATFORM_WIN32_WINDOWS:标识为Windows 95或Windows 98;对于Windows 95操作系统而言,dwMinorVersion值为0,对Windows 98操作系统dwMinorVersion则大于0;
VER_PLATFORM_WIN32_NT:标识为WindowsNT。
VER_PLATFORM_WIN32_CE:标识为Windows CE


szCSDVersion:关于该操作系统的附近信息


下表总结了Windows支持的版本号:
     
Windows 7 6.1 6 1 OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION
Windows Server 2008 R2 6.1 6 1 OSVERSIONINFOEX.wProductType != VER_NT_WORKSTATION
Windows Server 2008 6.0 6 0 OSVERSIONINFOEX.wProductType != VER_NT_WORKSTATION
Windows Vista 6.0 6 0 OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION
Windows Server 2003 R2 5.2 5 2 GetSystemMetrics(SM_SERVERR2) != 0
Windows Server 2003 5.2 5 2 GetSystemMetrics(SM_SERVERR2) == 0
Windows XP 5.1 5 1 Not applicable
Windows 2000 5.0 5 0 Not applicable

SVERSIONINFO结构包含了操作系统的版本信息,包括操作系统的主版本号、副版本号、创建号、以及操作系统平台ID号和关于操作系统的其他描述信息。其定义为:

  typedef struct _OSVERSIONINFO{

  DWORD dwOSVersionInfoSize;

  //指定该数据结构的字节大小

  DWORD dwMajorVersion;

  //操作系统的主版本号

  DWORD dwMinorVersion;

  //操作系统的副版本号

  DWORD dwBuildNumber;

  //操作系统的创建号

  DWORD dwPlatformId;

  //操作系统ID号

  TCHAR szCSDVersion[ 128 ];

  //关于操作系统的一些附加信息

  } OSVERSIONINFO;

  其中dwPlatformId可为以下值:

  VER_PLATFORM_WIN32s:标识为Windows 3.1;

  VER_PLATFORM_WIN32_WINDOWS:标识为Windows 95或Windows 98;

  对于Windows 95操作系统而言,dwMinorVersion值为0,对Windows 98操作系统dwMinorVersion则大于0;

  VER_PLATFORM_WIN32_NT:标识为WindowsNT。

dwMajorVersion:

Identifies the major version number of the operating system as follows. Operating System Value

Windows 95 4
Windows 98 4
Windows Me 4
Windows NT 3.51 3
Windows NT 4.0 4
Windows 2000 5
Windows XP 5
Windows .NET Server 5

dwMinorVersion:

Identifies the minor version number of the operating system as follows. Operating System Value

Windows 95 0
Windows 98 10
Windows Me 90
Windows NT 3.51 51
Windows NT 4.0 0
Windows 2000 0
Windows XP 1
Windows .NET Server

需求:
Windows NT/2000/XP: Included in Windows NT 3.5 and later.
Windows 95/98/Me: Included in Windows 95 and later.
头文件: Declared in Winnt.h; include Windows.h.
Unicode: Declared as Unicode and ANSI structures.

程序具体实现步骤

  1.使用AppWizard新建一个基于单文档的工程SystemJudge。

  2.在工程中添加两个文件,即定义文件judge.h和实现文件judge.cpp。

  在judge.h文件中添加如下代码:

  #ifndef __JUDGE_H__

  #define __ JUDGE _H__

  Cstring JudgeOperatingSystem();

  //判断操作系统函数定义

  #endif

  在judge.cpp文件中添加如下代码:

  #include "stdafx.h"

  #include "judge.h"

  Cstring JudgeOperatingSystem()

  //判断操作系统函数的实现

  {

  OSVERSIONINFO OsVersionInfo;

  OsVersionInfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);

  GetVersionEx(&&OsVersionInfo);

  if(OsVersionInfo.dwPlatformId=VER_PLATFORM_WIN32_WINDOWS )

   {

   if(OsVersionInfo.dwMajorVersion>4) return "Windows98";

  else if(OsVersionInfo.dwMajorVersion=4)

   {

   if(OsVersionInfo.dwMinorVersion>0) return "Windows98";

  else return "Windows95";

   }

   else return "Windows3.1";

   }

  elseif(OsVersionInfo.dwPlatformId= VER_PLATFORM_WIN32_NT )

   {

   return "WindowsNT";

   }

   else if(OsVersionInfo.dwPlatformId== VER_PLATFORM_WIN32s)

   {

   return "Windows3.1";

   }

   else return "NoName";

  }

  3.在CmainFrame类的实现文件MainFrm.cpp中开头添加#include"judge.h"。并在其OnCreate函数中return语句前加入如下判断代码:

  Cstring sOperatingSystem = JudgeOperatingSystem();

  if( sOperatingSystem == "Windows98")

  {

  //假如本软件需要在WindowsNT下运行

  MessageBox(

   "本软件在WindowsNT4.0或更高的版本下运行,您的操作系统是Windows98 "

  "请安装WindowsNT4.0以上的版本或使用Windows98版!",

  "警告",

  MB_OK

  );

  }

   else if( sOperatingSystem == "WindowsNT")

   {

   //假如软件需要在Windows98下运行,我们可在此添加警告对话框

   }

   else return -1;

  至此,操作系统判断功能已经实现,在软件启动时会自动判断软件当前运行的操作系统并提示用户是否在正确的操作系统环境,从而保证了软件运行的正常性。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值