After inputting the MFC input box, click Enter to end the focus of the input box

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)
        {

           //After getting the carriage return, the ID of the input box where the focus is located
            CWnd *pWnd=GetFocus();
            int nId=pWnd->GetDlgCtrlID();

           //End the focus of the input box
            GetDlgItem(nId)->PostMessage(WM_KILLFOCUS, 0, 0);
            return TRUE;
        }
    }
    return CDialog::PreTranslateMessage(pMsg);
}

Guess you like

Origin blog.csdn.net/Hat_man_/article/details/109740871