程序是这样的BOOL CRegFixDlg::OnInitDialog()
{
CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, TRUE); // Set small icon OSVERSIONINFO osinfo;
int num=osinfo.dwMajorVersion ;
if (num==5)
MessageBox(_T("NT5"));
DWORD iButtonStyle=WS_CHILD|WS_VISIBLE|BS_CENTER|BS_FLAT|BS_MULTILINE|BS_VCENTER;
m_button1.Create (_T("Button1"),iButtonStyle,CRect(20,197,100,227),this,501);......
}就是说先判断操作系统版本,如果是Windows 2000/XP/Server 2003,就弹出信息,提示是NT5但是现在根本没有弹出信息来这是怎么回事啊?
{
CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, TRUE); // Set small icon OSVERSIONINFO osinfo;
int num=osinfo.dwMajorVersion ;
if (num==5)
MessageBox(_T("NT5"));
DWORD iButtonStyle=WS_CHILD|WS_VISIBLE|BS_CENTER|BS_FLAT|BS_MULTILINE|BS_VCENTER;
m_button1.Create (_T("Button1"),iButtonStyle,CRect(20,197,100,227),this,501);......
}就是说先判断操作系统版本,如果是Windows 2000/XP/Server 2003,就弹出信息,提示是NT5但是现在根本没有弹出信息来这是怎么回事啊?
但它返回的值并不总是“真实”的。例如出于兼容性的考虑,
Windows for Workgroup 3.11(注意这和Windows 3.11是两个不同的版本)
返回的版本号是3.10,不是3.11。你可以使用GetFileVersionInfo()函数
来获得USER.EXE的版本号,它返回的将是3.11。Windows 3.2中文版返回的
版本号是3.10,而不是3.20,这倒不是技术原因,
而是因为Windows 3.2是在Windows 3.10的基础上汉化的。
如果想知道程序是否运行在Windows NT环境下,16位程序可以调用
WinFlags()函数,用返回值同WF_WINNT相与,如果不为零说明运行
在Windows NT中。如果你的C++系统中没有定义WF_WINNT常数,
可以加上下面这句: #define WF_WINNT 0x4000 32位程序仍可以使用
GetVersion()函数,但返回值同16位不同。32位软件最好使用
GetVersionEx()函数。这个函数使用OSVERSIONINFO结构,
该结构是如下定义的:
typedef struct _OSVERSIONINFO
{ DWORD dwOSVersionInfoSize;
DWORD dwMajorVersion; // 主版本号
DWORD dwMinorVersion; // 副版本号
DWORD dwBuildNumber; // Build号
DWORD dwPlatformId;
TCHAR szCSDVersion[ 128 ];
} OSVERSIONINFO;
在Windows 95上,
dwMajorVersion为4,dwMinorVersion为0,dwBuildNumber为950,
也就是说Windows 95的版本号为4.00.950。
dwPlatformId是用来区分Windows 95、Windows NT和Win32s。
其取值含义如下:取值 含义
VER_PLATFORM_WIN32s Win32s on Windows 3.1
VER_PLATFORM_WIN32_WINDOWS Win32 on Windows 95
VER_PLATFORM_WIN32_NT Win32 on Windows NT 若想区别Windows 95与Windows 95 OSR2,要看dwBuildNumber,
如果dwBuildNumber的低位字大于1080,则系统为Windows 95 OSR2
或更高版本。在Win32中不再支持WinFlags()函数。
尽管GetVersionEx()函数和GetVersion ()函数是Windows
提供的标准的版本函数,但在实际编程使用GetFileVersionInfo()
函数有时更方便。
一个实例:
OSVERSIONINFO osvi;
memset(&osvi, 0, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
GetVersionEx (&osvi);
CString s;
// s.Format("你的Windows版本为:%d.%d", osvi.dwMajorVersion, osvi.dwMinorVersion);
DWORD info=osvi.dwMajorVersion,of=osvi.dwMinorVersion;
// AfxMessageBox(info,of,MB_OK);
// m_info=info+of;
UpdateData(false);