?? getwinversion.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結(jié)構(gòu)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;
}
}
//輸出結(jié)果
cout <<"你的操作系統(tǒng)是:"<< (LPCTSTR)WinVer << endl;
}
return nRetCode;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -