1. 程式人生 > >MFC 中PreTranslateMessage(MSG* pMsg)截獲按鈕和編輯框的訊息進行預處理

MFC 中PreTranslateMessage(MSG* pMsg)截獲按鈕和編輯框的訊息進行預處理

在類嚮導自動為對話方塊新增PreTranslateMessage(MSG* pMsg)函式;

BOOL CjilutestDlg::PreTranslateMessage(MSG* pMsg) {     // TODO:  在此新增專用程式碼和/或呼叫基類

    if (pMsg->message == WM_LBUTTONDOWN )//&&pMsg->wParam == IDC_BUTTON1)     {         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); }