消息分流器简单代码

消息分流器原理,这里不细说,可以google中查询,,以下提供短小代码实现下

每个消息都有 wParam 和 lParam,WM_COMMAND,wParam包含两个不同的值,其中:

 wParam:低字节是控件的id,高字节是通知码 notifyCode

 lParam: 强制转换为按钮或控件的句柄值 hWndCtl



#include
#define chHANDLE_DLGMSG(hwnd, message, fn) case (message): return (SetDlgMsgResult(hwnd, uMsg, HANDLE_##message((hwnd), (wParam), (lParam), (fn))))


INT_PTR CALLBACK Dlg_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{

SetWindowText(hwnd, L"消息分流器");
return TRUE;
}
INT_PTR CALLBACK Dlg_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
switch (id)
{
case IDOK:
{ SetWindowText(hwnd, L"消息分流器OK");
break;
}
// LOWORD(wParam) == IDOK
}
return TRUE;
}
// “关于”框的消息处理程序。
INT_PTR CALLBACK About(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
chHANDLE_DLGMSG(hDlg, WM_INITDIALOG, Dlg_OnInitDialog);
chHANDLE_DLGMSG(hDlg, WM_COMMAND, Dlg_OnCommand);


}
return (INT_PTR)FALSE;
}

你可能感兴趣的:(c++学习问题记录)