Difference between LOWORD and HIWORD WPARAM and LPARAM

I was wondering what the differences between LOWORD and HIWORD are, i want to know what there used for, how there used and why. I looked it up and on one site it says that "LOWORD returns the lower 16 bits of WHATEVER is passed into it. HIWORD the upper 16 bits." the upper and lower 16 bits of what???

Also what does WPARAM and LPARAM do? what are they used with and why. i read that there meant for mouse tracking and when you resize a window and getting the mouses button state. but is that correct? please elaborate on the 4 words please with as much detail as you can give.
I'll give you a concrete case so you can see what are they used for:

1
2
3
4
5
6
7
8
9
LRESULT CALLBACK splash_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
     switch (message) {
          case WM_COMMAND:
               if((HIWORD(wParam) == BN_CLICKED) && (LOWORD(wParam) == MY_BUTTON)) {
                    bEEP(100, 100);
               }
         break;
     }
}


In this case, the WPARAM wParam argument contains a 32 bits value. The upper 16 bits specifies that the event BN_CLICKED ocurred (the user pressed the mouse button) and the lower 16 bits specifies on which element the BN_CLICKED event have been actioned, in this case a button called MY_BUTTON. Instead of sending a 16 bits value for the event and another 16 bits value for the object affected by the event we send only a 32bit value (now when almost everyone has 32bit architecture computers) containing both values.
Somebody correct me if I am wrong.
Last edited on
Ok so if i understand this correctly, in a nutshell HIWORD is the Upper 16 bits of UINT and LOWORD is the Lower 16 bits of UINT???? am i correct so far??
That is exactly correct.

WPARAM and LPARAM are just additional information that comes with the message. Their exact purpose depends on which message is actually being sent. They can mean completely different things for different messages.

For example, in a mouse click message, they might indication the position of the mouse. But for a button press message, they might be the ID of the button being pressed.

To know exactly how they're used, the easiest way is to look up the desired message on MSDN (ie, WM_MOUSEMOVE's page will say exactly what the WPARAM and LPARAM for that message do).
Ok, now UINT does what exactly? I know it stands for Unsigned Integer an i think i read that the value is higher than a regular Int, or something like that.
unsigned just means it doesn't have a sign (ie: it can't be negative).

This allows for a higher maximum.

IE: a signed char can hold a value between -128 and +127
an unsigned char can hold a value betwee 0 and 255

unsigned int is the same idea, only [usually] 4 bytes instead of 1.
Ok so is there a site that explains this stuff other than MSDN? MSDN tends to get a little too technical for me, and sometimes doesnt explain things enough.

Also when you say something like int or char can hold x amount of values, does that mean just numbers or words? i assume words and numbers all have certain sizes correct?
Last edited on
MSDN is the best reference for WinAPI, but not necessarily the best way to learn it. There are books/tutorials that are much better in teaching it because they will walk you through how to actually use it.

MSDN is more like an encycopedia. It's more for looking up the details of a specific function/struct, as it will tell you pretty much every detail... what the parameters do, what the function returns, what the function actually does, any side-effects, etc.

Unfortunately, I don't have any recommendations for books/tutorials, as it's been so long since I've had to read any. :( Maybe someone else can help.
Ok, well if anyone out there knows of really good win api books for a complete beginner please let me know
I have a question about my code also. So in it there is this:

1
2
3
4
5
6
7
8
9
10
11
12
13
 INITCOMMONCONTROLSEX commCon;
        commCon.dwSize = sizeof(INITCOMMONCONTROLSEX);
        commCon.dwICC = ICC_TAB_CLASSES;
        InitCommonControlsEx(&commCon); // have to run this to use tab control
        hTabControl = GetDlgItem(H, TAB_MAIN);

        TCITEM tcItem;
        tcItem.mask = TCIF_TEXT; // I'm only having text on the tab

        //Tab 1
        tcItem.pszText = "Project Setup";
        TabCtrl_InsertItem(hTabControl, 0, &tcItem);


What is commCon.dwSize?? I know commCon is assigned to INITCOMMONCONTROLSEX but why is there a '.' there? and is dwSize a keyword? is dwICC?
Programming Windows by Charles Petzold was the book for learning Windows programming.
INITCOMMONCONTROLSEX is a structure and dwSize and dwICC are members (probably DWORD since they start with the 'dw'). DWORD is just a typedef for 32-bit integer, whereas WORD is a typedef for a 16-bit integer.

1
2
3
4
5
6
7
8
9
10
11
struct Girlfriend
{
  string Name;
  int age;
  bool Keeper;
}; // sorry, forgot this first time around...

  Girlfriend Jill;                // creates an object of Girlfriend called Jill
  Jill.Name = "Jill";          // Sets Name to "Jill"
  Jill.Age = 24;               // Sets Age to 24;
  bool Keeper = false;   // Poor Jill's just not a keeper... 


If Jill had been a pointer to Girlfriend instead of an object the notation would have looked like:

 
  Jill->Name = "Jill";


EDIT: fixed, forgot closing semicolon after struct definition
Last edited on
Ok i found that book at barnes and noble, is there any more suggestions
Thanks i'll bookmark those right now. Im trying to get your example to work with the . operator, but i get an error

C:\Users\Chay Hawk\Desktop\dot operator\main.cpp|5|error: expected unqualified-id before ')' token|
C:\Users\Chay Hawk\Desktop\dot operator\main.cpp||In function 'int main()':|
C:\Users\Chay Hawk\Desktop\dot operator\main.cpp|14|error: aggregate 'Girlfriend Jill' has incomplete type and cannot be defined|
C:\Users\Chay Hawk\Desktop\dot operator\main.cpp|17|warning: unused variable 'Keeper'|
||=== Build finished: 2 errors, 1 warnings ===|


This is how i set it up:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

using namespace std;

struct Girlfriend()
{
    string Name;
    int Age;
    bool Keeper;
}

int main()
{
  Girlfriend Jill;                // creates an object of Girlfriend called Jill
  Jill.Name = "Jill";          // Sets Name to "Jill"
  Jill.Age = 24;               // Sets Age to 24;
  bool Keeper = false;

}
struct Girlfriend()

Get rid of those parenthesis. You only put empty parenthesis like that for functions, not for structs/classes.
Sorry I forgot the semicolon after the definition of struct Girlfriend. That will cause problems.
I changed it and it still doesnt work??

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <string>

using namespace std;

struct Girlfriend;
{
    string Name;
    int Age;
    bool Keeper;
}

int main()
{
  Girlfriend Jill;                // creates an object of Girlfriend called Jill
  Jill.Name = "Jill";          // Sets Name to "Jill"
  Jill.Age = 24;               // Sets Age to 24;
  bool Keeper = false;
}



Errors:

C:\Users\Chay Hawk\Desktop\Dot operator\main.cpp|8|error: expected unqualified-id before '{' token|
C:\Users\Chay Hawk\Desktop\Dot operator\main.cpp||In function 'int main()':|
C:\Users\Chay Hawk\Desktop\Dot operator\main.cpp|16|error: aggregate 'Girlfriend Jill' has incomplete type and cannot be defined|
C:\Users\Chay Hawk\Desktop\Dot operator\main.cpp|19|warning: unused variable 'Keeper'|
||=== Build finished: 2 errors, 1 warnings ===|
You need a semi-colon at the end of the struct definition.

main should return a value.
In other words, change this...

1
2
3
4
5
6
struct Girlfriend;
{
    string Name;
    int Age;
    bool Keeper;
}


to this...

1
2
3
4
5
6
struct Girlfriend
{
    string Name;
    int Age;
    bool Keeper;
};


Topic archived. No new replies allowed.