我有一个MFC对话框,在PreTranslateMessage方法中:
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按键传递给父级,以便也可以处理它?</ p>
谢谢。
答案 0 :(得分:1)
您可能已尝试过SendMessage
但它无效。尝试与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);
}
假设GetParent()
返回指向父对话框的指针。例如,如果在父对话框中,则按如下方式创建子项:
child.Create(IDD_CHILD, this);
但是我认为为VK_F5
和其他键创建父函数更可靠,然后从子对话框中调用它。