OSVERSIONINFO结构
来源:互联网 发布:文明5 mac 中文 编辑:程序博客网 时间:2024/06/03 13:17
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支持的版本号:
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;
至此,操作系统判断功能已经实现,在软件启动时会自动判断软件当前运行的操作系统并提示用户是否在正确的操作系统环境,从而保证了软件运行的正常性。
- OSVERSIONINFO结构
- OSVERSIONINFO的用法及实例
- 结构
- 结构
- 结构
- 结构
- 结构
- 结构
- 结构
- 结构
- 结构
- 结构
- 结构
- 结构
- 结构
- 结构
- 结构
- 结构
- POJ 3667(线段树,区间合并,成段更新)
- XmlTextWriter
- 如何配置JDK,tomcat 和JSP
- 使用COM组件读写word文档
- 用C语言实现大小端判断
- OSVERSIONINFO结构
- 比较两个字符串并不区分大小写
- PHP匿名函数及闭包
- 使用特殊的技术更新数据库(ABAP)
- ListCtrl控件中的数据保存到EXCEL
- 跨越DLL边界传递CRT对象潜在的错误
- unresolved external symbol _RtlStringVPrintfWorkerW 驱动函数链接错误解决
- Asp.net 之TreeView重要
- C#_设置文件夹访问权限