Re: Problem with wParam




"Robby" <Robby@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:8B3B0BE3-B32A-43B4-9642-E3C3B6EAE43A@xxxxxxxxxxxxxxxx

> Hi,
>
> My question would of eventually lead up to how can the HIWORD of wParam =
> -120.

You're essentially right, but it doesn't look like the simplest way of
saying it!

First it is easier to think in hexadecimal where each digit represents
exactly four binary digits (and which is easy to use in C++). You have

wParam = 0xff880000;

If you write

WORD w = HIWORD(wParam);

then w = 0xff88;

Think of signed integers as being cyclic, with (-1) always being the number
with all bits set.

So

BYTE(-1) is 0xff
WORD(-1) is 0xffff
UINT(-1) is 0xffffffff

and so on. So WORD(-120) is 0xffff - 119 = 0xffff-0x0077 = 0xff88

[IMPORTANT: the representation of negative integers depends on the size of
the integer, and you have to be careful. WORD(BYTE(-1)) will be be 0x00ff
and not the same as WORD(-1) whereas WORD(BYTE(1)) and WORD(1) are the
same.]

Dave

--
David Webber
Author MOZART the music processor for Windows -
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mzusers/mailinglist.htm



.