编辑器是VC++6.0
建立 Win32 Application
在编译时出现如下错误:
--------------------Configuration: sysmets1 - Win32 Debug--------------------
Compiling...
sysmets1.c
e:/test/sysmets1/sysmets.h(297) : error C2065: 'SM_MOUSEWHEELPRESENT' : undeclared identifier
e:/test/sysmets1/sysmets.h(297) : error C2099: initializer is not a constant
e:/test/sysmets1/sysmets.h(297) : warning C4047: 'initializing' : 'int ' differs in levels of indirection from 'char [21]'
e:/test/sysmets1/sysmets.h(301) : error C2065: 'SM_XVIRTUALSCREEN' : undeclared identifier
e:/test/sysmets1/sysmets.h(301) : error C2099: initializer is not a constant
e:/test/sysmets1/sysmets.h(303) : warning C4047: 'initializing' : 'int ' differs in levels of indirection from 'char [24]'
e:/test/sysmets1/sysmets.h(305) : error C2065: 'SM_YVIRTUALSCREEN' : undeclared identifier
e:/test/sysmets1/sysmets.h(305) : error C2099: initializer is not a constant
e:/test/sysmets1/sysmets.h(309) : error C2065: 'SM_CXVIRTUALSCREEN' : undeclared identifier
e:/test/sysmets1/sysmets.h(309) : error C2099: initializer is not a constant
e:/test/sysmets1/sysmets.h(309) : warning C4047: 'initializing' : 'int ' differs in levels of indirection from 'char [19]'
e:/test/sysmets1/sysmets.h(313) : error C2065: 'SM_CYVIRTUALSCREEN' : undeclared identifier
e:/test/sysmets1/sysmets.h(313) : error C2099: initializer is not a constant
e:/test/sysmets1/sysmets.h(315) : warning C4047: 'initializing' : 'int ' differs in levels of indirection from 'char [22]'
e:/test/sysmets1/sysmets.h(317) : error C2065: 'SM_CMONITORS' : undeclared identifier
e:/test/sysmets1/sysmets.h(317) : error C2099: initializer is not a constant
e:/test/sysmets1/sysmets.h(321) : error C2065: 'SM_SAMEDISPLAYFORMAT' : undeclared identifier
e:/test/sysmets1/sysmets.h(321) : error C2099: initializer is not a constant
e:/test/sysmets1/sysmets.h(321) : warning C4047: 'initializing' : 'int ' differs in levels of indirection from 'char [21]'
Error executing cl.exe.
sysmets1.obj - 14 error(s), 5 warning(s)
解决方法:
那些是WindowNT里才能使用的常量,它是是被条件编译的。
需要在的sysmets.cpp文件的最前面加一句
#define WINVER 0x0500
另外还有一个地方有错误
GetSystemMetrics (sysmetrics[i].iIndex)
改为
GetSystemMetrics (sysmetrics[i].Index)
以下是对照表:
Minimum System Required | Macros to Define |
---|---|
Windows 95 and Windows NT 4.0 | WINVER=0x0400 |
Windows 98 and Windows NT 4.0 | _WIN32_WINDOWS=0x0410 and WINVER=0x0400 |
Windows NT 4.0 | _WIN32_WINNT=0x0400 and WINVER=0x0400 |
Windows 98 | _WIN32_WINDOWS=0x0410 |
Windows 2000 | _WIN32_WINNT=0x0500 and WINVER=0x0500 |
Windows Me | _WIN32_WINDOWS=0x049 |