MFC输入框输入完毕,点击回车,结束输入框焦点

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);
}

猜你喜欢

转载自blog.csdn.net/Hat_man_/article/details/109740871