views:

212

answers:

1

I've looked at sites and MSDN documentation but I still don't understand the last parameter 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.

A: 

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

Preet Sangha
Perfect. Thanks for your time.
Rudi