vc 响应键盘输入消息出错
我的代码如下:
BOOL CKeytest3Dlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
switch(pMsg-> message)
{
case WM_KEYDOWN:
switch(pMsg-> wParam)
{
case VK_CAPITAL:
dlg.DoModal();
break;
default:
break;
}
break;
default:
break;
}
return CDialog::PreTranslateMessage(pMsg);
}
当我按下VK_CAPITAL键时,dlg窗口产生,但当我关闭这个对话框时出错,不知怎么回事?
------解决方案--------------------厄.... 你没写过自定义消息...?
我只能给你写个大概,具体过程你上网一搜很多的
1. Keytest3Dlg.h 中自定义消息 #define WM_POPUP_NEWDLG WM_USER + 0x10
2. Keytest3Dlg.h 中声明一个函数,LRESULT OnPopupNewDlg(WPARAM, LPARAM);
3. Keytest3Dlg.cpp中定义这个函数
LRESULT OnPopupNewDlg(WPARAM wp, LPARAM lp)
{
UNREFERENCED_PARAMETER(wp);
UNREFERENCED_PARAMETER(lp);
CYourDlg dlg;
dlg.DoModal();
}
4.Keytest3Dlg.cpp中进行消息映射
ON_MESSAGE(WM_POPUP_NEWDLG, OnPopupNewDlg)
5.在你PreTranslateMessage中刚才DoModal那个地方, this-> PostMessage(WM_POPUP_NEWDLG);