How to test for low-order/high-order word values.
Hello.
I''m testing out the use of various windows messages. Like a dope, I had my WndProc() test to see if the WM_ACTIVATE message was sent, and if so generate a MessageBox that tells me so. Little did I know that the message is sent each time the window is activate AND deactivated, and I actually had to restart my computer. Heh.
So I looked up WM_ACTIVATE on MSDN and it tells me that the low-order bit(s) of wParam indicate why the message was sent. How do I extract the low-order bit(s) from wParam so I can test that?
---signature---" Actually, at the time, I didn't give a damn about the FoxNews issue... just that you would come swooping in with your Super Mith cape flapping behind you and debunk it just because it didn't happen in your living room." - InnocuousFox
i = LOWORD(wParam);
For high word,
i = HIWORD(wParam);
Hope that helps
Edit:
I guess I oughtta explain how that works. The wParam is a 32 bit variable that is stored like this:
1111 1111 1111 1111 1111 1111 1111 1111
|--- High Word ---|...|---- Low Word ----|
A word is a 16-bit number. So, a 32 bit number is composed of 2 words, and they're called the high and low order words.
To get the Hi Word of a 32 bit variable (an unsigned long,) bitshift the variable to the right by 16.
To get the Lo Word of a 32 bit variable, bitshift the variable to the left by 16, and then back to the right by 16.
Here's an example:
The output of this program is:
Entire variable: 4294967295
High word of the variable: 65535
Low word of the variable: 65535
I believe HIWORD and LOWORD are just macro versions of the functions I have written above.
aut viam inveniam aut faciam
MoonStar Projects
[edited by - Ronin Magus on January 4, 2003 2:01:31 PM]
For high word,
i = HIWORD(wParam);
Hope that helps
Edit:
I guess I oughtta explain how that works. The wParam is a 32 bit variable that is stored like this:
1111 1111 1111 1111 1111 1111 1111 1111
|--- High Word ---|...|---- Low Word ----|
A word is a 16-bit number. So, a 32 bit number is composed of 2 words, and they're called the high and low order words.
To get the Hi Word of a 32 bit variable (an unsigned long,) bitshift the variable to the right by 16.
To get the Lo Word of a 32 bit variable, bitshift the variable to the left by 16, and then back to the right by 16.
Here's an example:
#include <iostream>using namespace std;unsigned int LoWord(unsigned long myLong){ return myLong << 16 >> 16;}unsigned int HiWord(unsigned long myLong){ return myLong >> 16;}int main(){ // set myLong to the max it can be unsigned long myLong = 0xFFFFFFFF; cout << "Entire variable: " << myLong << endl; cout << "High word of variable: " << HiWord(myLong) << endl; cout << "Low word of variable: " << LoWord(myLong) << endl; return 0;}
The output of this program is:
Entire variable: 4294967295
High word of the variable: 65535
Low word of the variable: 65535
I believe HIWORD and LOWORD are just macro versions of the functions I have written above.
aut viam inveniam aut faciam
MoonStar Projects
[edited by - Ronin Magus on January 4, 2003 2:01:31 PM]
Wow. That easy, huh? Thanks!
---signature---" Actually, at the time, I didn't give a damn about the FoxNews issue... just that you would come swooping in with your Super Mith cape flapping behind you and debunk it just because it didn't happen in your living room." - InnocuousFox
Just a note:
Update GameDev.net system time campaign:
WORD
is an unsigned 16-bit integer.unsigned short
would be a better return type. Update GameDev.net system time campaign:
''date ddmmHHMMYYYY''
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement