CEdit中怎么响应回车事件?

9月 11th, 2013
Visited 1948 times, 2 so far today
0

Comments

//方法一,直接重写PreTranslateMessage方法,在其中捕获相应的动作

重写PreTranslateMessage
BOOL CMyDialog::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->wParam==VK_RETURN && pMsg->message == WM_KEYDOWN )
{
if(GetFocus()->GetDlgCtrlID() == IDC_EDIT1)
{
//写上要处理的代码
}
// do it you
return TRUE;
}

return CDialog::PreTranslateMessage(pMsg);
}

//方法二: 从CEdit派生一个新的MyEdit类,在类的PreTranslateMessage()函数中处理

BOOL CMyEdit::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message==WM_KEYDOWN && pMsg->wParam == VK_RETURN)
{
yourFunc();//在这里调用你的函数
}
return CEdit::PreTranslateMessage(pMsg);
}