Problem with conversation decimal to hex value for SendMessage

Viewed 79

I'm trying to understand what the rule is for converting hex int (decimal) and IntrPtr.

I read somewhere that it should represent the "higher memory" or something like that.

If someone could explain that to me a bit, it would be great.

But actually it's just about the following:

I want to use SendMessage to send APPCOMMAND_SAVE (int value 32).

const int WM_APPCOMMAND = 0x319;

MS docs says #define WM_APPCOMMAND / 0x0319 But that doesn't seem to make any difference. I have somehow problems with the zero signs. How ever 0x319 works.

So I found out that e.g. vol up is:

const int APPCOMMAND_VOLUME_UP = 0xA0000; // 10

Now I'm trying to convert APPCOMMAND_SAVE (32) to the right hex value:

const int APPCOMMAND_SAVE = 0x200000; //? Hex value of 32 is the right?
1 Answers

Looking a little more at the lParam for the WM_APPCOMMAND API call, I can see that this contains three separate values in a bitmask:

  • cmd - which is the specific app command you are referring to [2 bytes]
  • uDevice - which indicates the device that generated the input [2 bytes]
  • dwKeys - which indicates which virtual keys are depressed, if any [2 bytes]

The values for all of these is contained in lParam alone as a bitmask, with each one taking 2 bytes. They are therefore structured into lParam as so:

0xAADDKK

Where AA indicates the APPCOMMAND being sent, DD indicates the uDevice, and KK indicates the dwKeys.

With that in mind, in order to send a command for APPCOMMAND_SAVE (decimal 32, hex 0x20) with no uDevice and no dwKeys the correct lParam value to use is:

0x200000

With regards to your other point:

MS docs says #define WM_APPCOMMAND / 0x0319 But that doesn't seem to make any difference. I have somehow problems with the zero signs. How ever 0x319 works.

Hexadecimal numbers function as per base-10 in that leading 0s are dropped from numbers. Therefore hex 0x0319 is the same as 0x319 and also 0x00000319, in the same way that in base-10, 1000 is the same number as 01000 and indeed 00000001000.

Related