第一:关于代码编译的问题
第一次把ErrorShow实例从光盘上拷下来,用Microsoft Visual C++ 6.0编译,出现如下错误:
Compiling...
ErrorShow.cpp
You are not using the latest Platform SDK header/library
files. This may prevent the project from building correctly.
c:/documents and settings/administrator/桌面/01-errorshow/cmnhdr.h(212) : error C2065: 'GetWindowLongPtr' : undeclared identifier
c:/documents and settings/administrator/桌面/01-errorshow/cmnhdr.h(212) : error C2065: 'GWLP_HINSTANCE' : undeclared identifier
c:/documents and settings/administrator/桌面/01-errorshow/errorshow.cpp(83) : error C2065: 'PCTSTR' : undeclared identifier
c:/documents and settings/administrator/桌面/01-errorshow/errorshow.cpp(83) : error C2146: syntax error : missing ')' before identifier 'LocalLock'
c:/documents and settings/administrator/桌面/01-errorshow/errorshow.cpp(83) : error C2059: syntax error : ')'
c:/documents and settings/administrator/桌面/01-errorshow/errorshow.cpp(125) : error C2664: 'DialogBoxParamA' : cannot convert parameter 4 from 'long (struct HWND__ *,unsigned int,unsigned int,long)' to 'int (__stdcall *)(struct HWND__ *,unsigned in
t,unsigned int,long)'
None of the functions with this name in scope match the target type
执行 cl.exe 时出错.
ErrorShow.obj - 1 error(s), 0 warning(s)
解决办法:
1.将GetWindowLongPtr改成GetWindowLong GWLP_HINSTANCE改成GWL_HINSTANCE原因可能是If you are retrieving a pointer or a handle, this function supersedes the GetWindowLong function.(参照msdn的说法)
2.将PCTSTR改成PTSTR(这个类型包含在windows.h头文件中)
3. Dlg_Proc改成(DLGPROC)Dlg_Proc 类型要匹配
改完之后应该就可以编译成功了。
第二:关于代码中一些让人费解的代码
1.chSETDLGICONS(hwnd, IDI_ERRORSHOW);
chHANDLE_DLGMSG(hwnd, WM_INITDIALOG, Dlg_OnInitDialog);
chHANDLE_DLGMSG(hwnd, WM_COMMAND, Dlg_OnCommand);
这些都是作者定义的宏,包含在CmnHdr.h中,如:#define chHANDLE_DLGMSG(hwnd, message, fn) /
case (message): return (SetDlgMsgResult(hwnd, uMsg, /
HANDLE_##message((hwnd), (wParam), (lParam), (fn))))
其实这是一些消息分流器,包含在windowsx.h中,作者为了使用方便及避免一些问题自定义了它,有关消息分流器的知识&