MFC 中PreTranslateMessage(MSG* pMsg)截获按钮和编辑框的消息进行预处理

在类向导自动为对话框添加PreTranslateMessage(MSG* pMsg)函数;

BOOL CjilutestDlg::PreTranslateMessage(MSG* pMsg)
{
    // TODO:  在此添加专用代码和/或调用基类

    if (pMsg->message == WM_LBUTTONDOWN )
    {
        CButton *pbutton = (CButton*)GetDlgItem(IDC_BUTTON1);
        if (pMsg->hwnd == pbutton->GetSafeHwnd())
        {
            
        //按钮动作记录

        }
        
    }
    if (pMsg->message == WM_LBUTTONDOWN)
    {
        CEdit *pedit = (CEdit*)GetDlgItem(IDC_EDIT1);
        if (pMsg->hwnd == pedit->GetSafeHwnd())
        {

          //编辑框进行的动作记录
        }


    }

    return CDialogEx::PreTranslateMessage(pMsg);
}

猜你喜欢

转载自blog.csdn.net/gjh1215/article/details/83049928