积极答复者
WM_KEYDOWN被翻译成WM_CHAR时不需要WM_KEYUP吗??那系统会如何处理WM_KEYUP消息?谢谢!

问题
答案
-
您可以做一个测试,创建一个基于Dialog的工程,重载PreTranslateMessage虚函数,在里面加入下面的代码,然后按F5进行Debug,在VS的Output窗口中观察输出的数据:
BOOL CXXXDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class switch (pMsg->message) { case WM_KEYDOWN: { static int nIndex1 = 0; CString strText(_T("")); strText.Format(_T("WM_KEYDOWN = %u.\r\n"), ++nIndex1); OutputDebugString(strText); } break; case WM_KEYUP: { static int nIndex2 = 0; CString strText(_T("")); strText.Format(_T("WM_KEYUP = %u.\r\n"), ++nIndex2); OutputDebugString(strText); } break; default: break; } return CDialogEx::PreTranslateMessage(pMsg); }
Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.
- 已标记为答案 May Wang - MSFT 2014年5月8日 2:40
全部回复
-
举个例子,比如很多时候需要处理当按下键的时候做一件事,松开的时候停止。
比如,按下“+”键的时候,数据连续不断的+1,当松开的时候,停止+1,按下"-"键的时候,数据连续-1,当松开的时候,停止-1.
鼠标按键事件WM_LBUTTON/WM_LBUTTONUP也有类似的用法.
Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.
-
您可以做一个测试,创建一个基于Dialog的工程,重载PreTranslateMessage虚函数,在里面加入下面的代码,然后按F5进行Debug,在VS的Output窗口中观察输出的数据:
BOOL CXXXDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class switch (pMsg->message) { case WM_KEYDOWN: { static int nIndex1 = 0; CString strText(_T("")); strText.Format(_T("WM_KEYDOWN = %u.\r\n"), ++nIndex1); OutputDebugString(strText); } break; case WM_KEYUP: { static int nIndex2 = 0; CString strText(_T("")); strText.Format(_T("WM_KEYUP = %u.\r\n"), ++nIndex2); OutputDebugString(strText); } break; default: break; } return CDialogEx::PreTranslateMessage(pMsg); }
Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.
- 已标记为答案 May Wang - MSFT 2014年5月8日 2:40