《Windows核心编程》中的问题,SDK高手请进
本人最近在学习《Windows核心编程》这本书 , 在练习书中第一章的例子时 ,
出现下面的问题 , 不知问题出在哪里,望高手指点:
1、UNICODE和_UNICODE宏有什么区别
2、xHANDLE_DLGMSG宏作为对话框过程的处理函数宏, 其实现主要是调用
HANDLE_##message系列宏,而后者可能为空,那么能用Return返回到对话
框过程中吗?
3、程序出现了编译错误,总提示DialogBoxParamA出错,但参数却没有问题。
程序比较长,望高手能耐心看完。
#include <windows.h>
#include <windowsx.h>
#include <tchar.h>
#include "resource.h"
#ifndef _M_IX86
#define UNICODE
#endif
#ifdef UNICODE
#define _UNICODE
#endif
#define xHANDLE_DLGMSG(hwnd,message,fn) \
case(message): \
return SetDlgMsgResult(hwnd,message, \
HANDLE_##message((hwnd),(wParam),(lParam),(fn)))
#define ESM_POKECODEANDLOOKUP (WM_USER + 100)
BOOL Dlg_OnInitDialog(HWND hwnd,HWND hwndFocus,LPARAM lParam)
{
Edit_LimitText(GetDlgItem(hwnd,IDC_ERRORCODE),5);
SendMessage(hwnd,ESM_POKECODEANDLOOKUP,lParam,0);
return TRUE;
}
void Dlg_OnCommand(HWND hwnd,int id,HWND hwndCtl,UINT codeNotify)
{
switch(id)
{
case IDCANCEL:
EndDialog(hwnd,id);
break;
case IDC_ALWAYSONTOP:
SetWindowPos(hwnd,IsDlgButtonChecked(hwnd,IDC_ALWAYSONTOP)?HWND_TOPMOST:HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE);
break;
case IDC_ERRORCODE:
EnableWindow(GetDlgItem(hwnd,IDOK),Edit_GetTextLength(hwndCtl)>0);
break;
case IDOK:
DWORD dwError = GetDlgItemText(hwnd,IDC_ERRORCODE,NULL,FALSE);
/*Not Finish...*/
break;
}
}
INT_PTR WINAPI Dlg_Proc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg)
{
xHANDLE_DLGMSG(hwndDlg,WM_INITDIALOG,Dlg_OnInitDialog);
xHANDLE_DLGMSG(hwndDlg,WM_COMMAND,Dlg_OnCommand);
case ESM_POKECODEANDLOOKUP:
SetDlgItemInt(hwndDlg,IDC_ERRORCODE,(UINT)wParam,FALSE);
FORWARD_WM_COMMAND(hwndDlg,IDOK,GetDlgItem(hwndDlg,IDOK),BN_CLICKED,PostMessage);
SetForegroundWindow(hwndDlg);
break;
}
return FALSE;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE,LPTSTR lpCmdLine,int)
{
HWND hwnd;
hwnd = FindWindow(TEXT("#32770"),TEXT("Error Show"));
if(IsWindow(hwnd))
{
SendMessage(hwnd,ESM_POKECODEANDLOOKUP,_ttoi(lpCmdLine),0);
}
else
{
DialogBoxParam(hInstance,MAKEINTRESOURCE(IDD_ERRORSHOW),NULL,Dlg_Proc,_ttoi(lpCmdLine));
}
return 0;
}
下面是编译出错的信息提示:
--------------------Configuration: ErrorShow - Win32 Debug--------------------
Compiling...
ErrorShow.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\ErrorShow\ErrorShow.cpp(77) : error C2664: 'DialogBoxParamA' : cannot convert parameter 4 from 'long (struct HWND__ *,unsigned int,unsigned int,long)' to 'int (__stdcall *)(struct HWND__ *,unsigned
int,unsigned int,long)'
None of the functions with this name in scope match the target type
Error executing cl.exe.
ErrorShow.exe - 1 error(s), 0 warning(s)