我在WINXP下的VC6++下,运行Charles Petzold书的第四章的SYSMETS1.C 
或 SYSMETS2.C 或 SYSMETS3.C, 必须在 #include <windows.h> 之前,加上 
#define WINVER 0x0500,才能顺利编译和运行,为什么?    否则如下语句会出错:
    SM_MOUSEWHEELPRESENT,    TEXT ("SM_MOUSEWHEELPRESENT"),     
                             TEXT ("Mouse wheel present flag"),
    SM_XVIRTUALSCREEN,       TEXT ("SM_XVIRTUALSCREEN"),        
                             TEXT ("Virtual screen x origin"),
    SM_YVIRTUALSCREEN,       TEXT ("SM_YVIRTUALSCREEN"),        
                             TEXT ("Virtual screen y origin"),
    SM_CXVIRTUALSCREEN,      TEXT ("SM_CXVIRTUALSCREEN"),       
                             TEXT ("Virtual screen width"),
    SM_CYVIRTUALSCREEN,      TEXT ("SM_CYVIRTUALSCREEN"),       
                             TEXT ("Virtual screen height"),
    SM_CMONITORS,            TEXT ("SM_CMONITORS"),             
                             TEXT ("Number of monitors"),
    SM_SAMEDISPLAYFORMAT,    TEXT ("SM_SAMEDISPLAYFORMAT"),     
                             TEXT ("Same color format flag")

解决方案 »

  1.   

    应为在有些头文件里定义变量、函数、宏的时候往往是这样子的
    #if WINVER>=0x0500
    ... 
    #define SM_MOUSEWHEELPRESENT ... //打个比方
    ...
    #endif所以如果没有定义WINVER或者WINVER<0x0500
    #if WINVER>=0x0500
    ...
    #endif
    之间的代码就没有编译,也就是说这时编译器就看不到这些代码
    所以要定义#define WINVER 0x0500
      

  2.   

    Following mainly From MSDN online:Code generated by wizards in previous versions of Visual C++ did not define a value for _WIN32_WINNT in Stdafx.h. New MFC projects in Visual Studio .NET explicitly define _WIN32_WINNT to the standard 0x0400 setting, which targets the Windows NT 4.0 and later operating systems. some functions and structures have operating system limit, such as KBDLLHOOKSTRUCT, so U must define _WIN32_WINNT >= some_vlaue in stdafx before you include some head files.If _WIN32_WINNT was not explicitly defined in the older Stdafx.h files, the included MFC headers define _WIN32_WINNT for you. 
    The statement #include <afxwin.h>
    eventually includes Afxv_w32.h. This header defines _WIN32_WINNT (if it is not already defined) to be equal to WINVER. In Visual C++ .NET, WINVER is set explicitly in Windows.h to be 0x0501. In Visual C++ 6.0 WINVER is set to be 0x0400.When your project was being built in a previous version of Visual C++, such as 6.0, WINVER may have been set to 0x0400, to allow compilation using an earlier version of Platform SDK header files, such as may have been found on Windows 95 or Windows NT 4.0. Then when you build an MFC project from a previous release in Visual C++ .NET, you may see compilation errors due to the fact that your project is now using a different value for WINVER. so U can get your WINVER = 0x0400 to enable the compiler.