TranslateMessage会翻译哪些消息 探索

来源:互联网 发布:淘宝代理货源怎么找 编辑:程序博客网 时间:2024/04/28 11:35

MSDN下有这么一段

 

This 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. 

 

 

是不是TranslateMessage只翻译那些virtual-key消息?也就是只将 WM_KEYDOWN和WM_KEYUP 翻译成WM_CHAR?

这个virtual-key 又包括哪些消息? 这个函数是否翻译 WM_LBUTTONDOWN 等其他消息?

 

MSDN中还有一段话是这样写的

Nonzero indicates that the message is translated, that is, a character message is posted to the thread's message queue. If the message is WM_KEYDOWN or WM_SYSKEYDOWN, the return value is nonzero, regardless of the translation. Zero indicates that the message is not translated, that is, a character message is not posted to the thread's message queue.

 

 

由此我们知道,如果消息被翻译了,TranslateMessage会返回非零值,并且,如果消息是WM_KEYDOWN或WM_KEYUP ,不管是否被翻译,都会返回非零值。

 

而如果返回值是0,那就说明消息没有被翻译

 

写一个简单的SDK程序来测试一下

我的SDK 程序中消息循环部分是这么写的

 

MSG msg;

 

while(GetMessage(&msg,hWnd,0,0)>0)

{

if(0==TranslateMessage(&msg))

   MessageBox(hWnd,L"The message isn't translated",L"Caution!",MB_OK);

DispatchMessage(&msg);

}

 

 

运行程序,发现我们的程序窗口显示了,同时还弹出一个 消息框 显示 The message isn't translated 

我们知道,窗口创建的时候,会发送WM_CREATE消息

这说明WM_CREATE消息也不会经过TranslateMessage翻译

 

我们在窗口上移动鼠标,同样弹出消息框 显示 The message isn't translated 

 

很遗憾,这时候我们无法在窗口上点击鼠标,因为只要一动鼠标就会 弹出消息框 显示 The message isn't translated

 

所以我们能修改窗口过程,屏蔽WM_MOUSEMOVE 来验证 点击鼠标时会否弹出  The message isn't translated

 

但我想,结果已经不用验证了。。。

 

最后我们关闭窗口

同样弹出那串英文,这说明。。。。。。。额是的

WM_CLOSE 也是不会被翻译的。。。。

原创粉丝点击