开发者

[C#][Win32 API] PostMessage Help?

I've looked at sites and MSDN documentation but I still don't understand the last pa开发者_StackOverflow中文版rameter of PostMessage().

On forums in which people ask how to use PostMessage, people reply with one of two implementations:

  1. PostMessage(WindowHandle, WM_KEYDOWN, KeyCode, MapVirtualKey(KeyCode, 0) << 16);
  2. PostMessage(WindowHandle, WM_KEYDOWN, KeyCode, 0);

What's the difference? Why can the last parameter be left as 0 in some instances, but has to be 'shifted' and all that in other instances?

Just a quick question. Don't need essay replies (although they would be much appreciated). Any insight is appreciated. Thanks in advance.


See here for more information on PostMessage. Every message is different, and has it's own specification as to what parameters are required. In many respects you can view it as general function with one name (post message) that delegates to another function (the message name) and passes it those parameters.

The last parameter like the rest are message specific and can vary.

BOOL PostMessage(
  __in  HWND hWnd,
  __in  UINT Msg,
  __in  WPARAM wParam,
  __in  LPARAM lParam
);

In your first message WM_KEYDOWN needs the result of MapVirtualKey in lParam only in the high 16 bits. I'm not familliar with this message anymore, but I'd suspect that what's happening is that since 0 is being passed as the second parameter, there is no virtual key to scan code (or vice versa) translation required, however the keycode is still needed in the upper 16 bits of lParam

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜