BOOL CCOMDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if ((pMsg->message ==WM_KEYDOWN&&pMsg->wParam ==VK_ESCAPE)||(pMsg->message ==WM_KEYDOWN&&pMsg->wParam ==VK_RETURN)) return TRUE; return CDialog::PreTranslateMessage(pMsg); }
first change the id of ok button to your own id(i,e :MyOk) then you invoke the CDialog::OnOk in the message function On MyOk as for cancel do the same thing
{
// TODO: Add your specialized code here and/or call the base class
if ((pMsg->message ==WM_KEYDOWN&&pMsg->wParam ==VK_ESCAPE)||(pMsg->message ==WM_KEYDOWN&&pMsg->wParam ==VK_RETURN))
return TRUE;
return CDialog::PreTranslateMessage(pMsg);
}
then you invoke the CDialog::OnOk in the message function On MyOk
as for cancel do the same thing
首先如果重载OnCancel的话,那估计关闭窗口的按钮也同时没有用了
把ok,cancel自己定义当然不错,不过那样的ok,cancel不就没有用了吗?
改变按钮的default属性,当然也不错,但若是窗口上一个按钮都没有呢?
出了PreTranslateMessage,还有什么别的方法吗?
如果是你想要的窗口句柄,让它pass.
在我前面的判断里加||
试试.
BOOL CComSetupEdit::PreTranslateMessage(MSG* pMsg)
{
BOOL bHandledMsg = FALSE; switch (pMsg->message)
{
case WM_KEYDOWN:
{
switch (pMsg->wParam)
{
// hitting escape while searching for password edits
// should only stop the search for password edits and
// not kill app
case VK_ESCAPE://ESC键
bHandledMsg = TRUE;
break;
case 13://回车
bHandledMsg = TRUE;
break;
default: break;
} // switch (pMsg->wParam)
}
break;
default: break;
} // switch (pMsg->message) return (bHandledMsg ? TRUE : CDialog::PreTranslateMessage(pMsg));
}