⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getwinversion.cpp

📁 Visual.C++程序设计技巧与实例--配套光盘 第6章 文件和系统操作 本章共11个实例: 1. FolderCopy文件夹的选择和拷贝 2. DeleteCertainFile删除指定路
💻 CPP
字号:
// GetWinVersion.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "GetWinVersion.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//定义一组版本
#define W95		"Windows 95"
#define W98		"Windows 98"
#define WME		"Windows ME"
#define WNT4    "Windows NT 4.0"
#define W2K		"Windows 2000"

/////////////////////////////////////////////////////////////////////////////
// The one and only application object

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	int nRetCode = 0;
	
	// initialize MFC and print and error on failure
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
	{
		// TODO: change error code to suit your needs
		cerr << _T("Fatal Error: MFC initialization failed") << endl;
		nRetCode = 1;
	}
	else
	{
		/*注释掉这段自动生成的代码
		// TODO: code your application's behavior here.
		CString strHello;
		strHello.LoadString(IDS_HELLO);
		cout << (LPCTSTR)strHello << endl;
		*/
		//定义CString类型的WinVer以存储版本信息
		CString	WinVer;
		//定义OSVERSIONINFO结构winfo
		OSVERSIONINFO winfo;
		winfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
		//得到版本信息
		GetVersionEx(&winfo);
		//以下是判断属于"Windows 95","Windows 98","Windows ME"
		//"Windows NT 4.0"还是"Windows 2000"
		if(winfo.dwPlatformId==VER_PLATFORM_WIN32_NT)
		{
			if(winfo.dwMajorVersion>=5)
				WinVer=W2K;
			else
				WinVer=WNT4;
		}
		else
		{
			if(winfo.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS)
			{
				if(winfo.dwMinorVersion<10)
					WinVer=W95;
				else
					if(winfo.dwMinorVersion<90)
						WinVer=W98;
					else
						WinVer=WME;
			}
		}	
		//输出结果
		cout <<"你的操作系统是:"<< (LPCTSTR)WinVer << endl;
	}
	
	return nRetCode;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -