Mfc 如何将按键传递回家长?
我有一个MFC对话框,在PreTranslateMessage方法中:Mfc 如何将按键传递回家长?,mfc,visual-studio-2015,Mfc,Visual Studio 2015,我有一个MFC对话框,在PreTranslateMessage方法中: BOOL CAssignHistoryDlg::PreTranslateMessage(MSG* pMsg) { BOOL bNoDispatch, bDealtWith ; bDealtWith = FALSE ; if ( (pMsg->message == WM_KEYDOWN || pMsg->message == WM_KEYUP || pMsg-&g
BOOL CAssignHistoryDlg::PreTranslateMessage(MSG* pMsg)
{
BOOL bNoDispatch, bDealtWith ;
bDealtWith = FALSE ;
if ( (pMsg->message == WM_KEYDOWN || pMsg->message == WM_KEYUP ||
pMsg->message == WM_CHAR)
&& pMsg->wParam == VK_F5)
{
// Eat it.
bNoDispatch = TRUE ;
bDealtWith = TRUE ;
}
if (!bDealtWith)
bNoDispatch = CSizingDialog::PreTranslateMessage(pMsg);
return bNoDispatch ;
}
这是父对象内部的无模式对话(实际上是对话)
如何将此VK_F5按键传递给父级以便也可以处理它
谢谢。您可能尝试过
发送消息
,但没有成功。尝试使用PostMessage
异步发送邮件:
BOOL c_child_dialog::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_F5)
{
//***Edit: Find previous key state from lParam:
//bits 30: The previous key state
const BOOL repeat = pMsg->lParam & (1 << 30);
if (!repeat)
GetParent()->PostMessage(pMsg->message, pMsg->wParam, pMsg->lParam);
}
return CDialogEx::PreTranslateMessage(pMsg);
}
return CDialogEx::PreTranslateMessage(pMsg);
}
BOOL c_parent_dialog::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_F5)
{
TRACE(L"parent-PreTranslateMessage-VK_F5\n");
return TRUE;
}
return CDialogEx::PreTranslateMessage(pMsg);
}
但是,我认为为
VK_F5
和其他键创建一个父函数,然后从子对话框调用它更可靠。Edit,添加代码以确保前一个键状态已启动,以避免重复消息
child.Create(IDD_CHILD, this);