Aid*_*yan 15
您还可以在对话框的PreTranslateMessage中过滤键.如果你得到WM_KEYDOWN了VK_RETURN,打电话GetFocus.如果焦点在编辑控件上,请在编辑控件中调用您按下的返回处理.
注意if依赖于短路的子句的顺序是有效的.
BOOL CMyDialog::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN &&
pMsg->wParam == VK_RETURN &&
GetFocus() == m_EditControl)
{
// handle return pressed in edit control
return TRUE; // this doesn't need processing anymore
}
return FALSE; // all other cases still need default processing
}
Run Code Online (Sandbox Code Playgroud)
正确答案是处理WM_GETDLGCODE / OnGetDlgCode消息。在那里你可以指定你希望所有的键都由你的类处理。
UINT CMyEdit::OnGetDlgCode()
{
return CEdit::OnGetDlgCode() | DLGC_WANTALLKEYS;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16285 次 |
| 最近记录: |