经TranslateMessage翻译后才能够获得的消息在PreTranslateMessage中也能够获得吗?
的有关信息介绍如下:TranslateMessage:The TranslateMessage function translates virtual-key messages into character messages. The character messages are posted to the calling thread's message queue, to be read the next time the thread calls the GetMessage or PeekMessage function....WM_KEYDOWN and WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message. WM_SYSKEYDOWN and WM_SYSKEYUP combinations produce a WM_SYSCHAR or WM_SYSDEADCHAR message. PreTranslateMessage:Used by class CWinApp to translate window messages before they are dispatched to the TranslateMessage and DispatchMessage Windows functions. TranslateMessage 和 PreTranslateMessage 字面上很相似,但是功能完全不同。PreTranslateMessage 仅仅是一个类似钩子回调函数 (hook callback function) 的东西,给你一个在 TranslateMessage 之前优先处理消息的机会。伪代码:MSG msg;while(GetMessage(&msg, NULL, 0, 0)){ PreTranslateMessage(&msg); TranslateMessage(&msg); DispatchMessage(&msg);}TranslateMessage 是为 WM_KEYDOWN + WM_KEYUP 的组合产生一个 WM_CHAR 或 WM_DEADCHAR 消息;为 WM_SYSKEYDOWN + WM_SYSKEYUP 的组合产生一个 WM_SYSCHAR 或 WM_SYSDEADCHAR 消息。这个消息是直接发送到消息队列里的,所以 PreTranslateMessage 也可以截获这个消息。虽然不清楚楼主为什么要用 PreTranslateMessage 来代替 TranslateMessage 的功能,不过理论上的确可行。只要判断上述那两组消息,并向消息队列发送 WM_CHAR/WM_SYSCHAR 就可以了,例如简化为: 遇到可映射为 ASCII 的 WM_KEYDOWN 时生成一个 WM_CHAR,遇到一个 WM_SYSKEYDOWN 时生成一个 WM_SYSCHAR。