经TranslateMessage翻译后才能够获得的消息在PreTranslateMessage中也能够获得吗?

来源:百度知道 编辑:UC知道 时间:2024/06/01 04:51:54
1.如果能够获得的话,TranslateMessage“将虚拟键消息转换为字符消息”这个功能是不是在PreTranslateMessage中也完全可以实现?
2.如果不能够的话,请举例说明那些消息不能够?谢谢

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);
}

Tran