BOOL CXXXDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (pMsg->message==WM_KEYDOWN)
{
if(pMsg->wParam==VK_RETURN)
{
//获取回车后,焦点所在输入框的ID
CWnd *pWnd=GetFocus();
int nId=pWnd->GetDlgCtrlID();
//结束输入框的焦点
GetDlgItem(nId)->PostMessage(WM_KILLFOCUS, 0, 0);
return TRUE;
}
}
return CDialog::PreTranslateMessage(pMsg);
}

这段代码是关于对话框消息预处理的。在 `PreTranslateMessage` 函数中,当检测到 `WM_KEYDOWN` 消息且按下回车键时,获取焦点所在输入框的 ID,然后向该输入框发送 `WM_KILLFOCUS` 消息以结束其焦点,最后返回 `TRUE`。
1647

被折叠的 条评论
为什么被折叠?



