1、添加鼠标响应:
在对话框类属性的“重写”中添加WM_MOUSEMOVE/WM_LBUTTONUP/WM_LBUTTONDOWN/WM_LBUTTONDBLCLK消息响应函数
1 void C窗口响应鼠标消息Dlg::OnLButtonDown(UINT nFlags, CPoint point) 2 { 3 MessageBox(_T("鼠标左键按下!")); 4 CDialogEx::OnLButtonDown(nFlags, point); 5 } 6 7 void C窗口响应鼠标消息Dlg::OnLButtonDblClk(UINT nFlags, CPoint point) 8 { 9 MessageBox(_T("鼠标左键双击!")); 10 CDialogEx::OnLButtonDblClk(nFlags, point); 11 } 12 13 14 void C窗口响应鼠标消息Dlg::OnLButtonUp(UINT nFlags, CPoint point) 15 { 16 MessageBox(_T("鼠标左键弹起!")); 17 CString szStr; 18 szStr.Format(_T("X=%d,Y=%d"), point.x, point.y); 19 MessageBox(szStr); 20 CDialogEx::OnLButtonUp(nFlags, point); 21 } 22 23 void C窗口响应鼠标消息Dlg::OnMouseMove(UINT nFlags, CPoint point) 24 { 25 MessageBox(_T("鼠标在移动!")); 26 CDialogEx::OnMouseMove(nFlags, point); 27 }
2、添加键盘响应:
在对话框类属性的“消息”中添加PreTranslateMessage函数
1 BOOL C窗口响应键盘消息Dlg::PreTranslateMessage(MSG* pMsg) 2 { 3 if (pMsg->message == WM_KEYDOWN) { 4 MessageBox(_T("键盘有键按下!")); 5 } 6 return CDialogEx::PreTranslateMessage(pMsg);