Thread: LPARAM and WPARAM

  1. #1
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584

    LPARAM and WPARAM

    I am reading Petzold. And, of course, for the messages sent to the window procedure, there are the two data types LPARAM and WPARAM. Petzold didn't really explain them and what they are actually implemented for (in messages). Well, the problem is that I get confused in the message handling of whether or not it is LPARAM or WPARAM or HIWORD(LPARAM) or LOWORD(WPARAM).

    Can anybody explain HIWORD and LOWORD, LPARAM and WPARAM? Thanks.

    --Garfield the Confused
    1978 Silver Anniversary Corvette

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    The message that gets generated and passed to GetMessage() from Windows is a struct that looks like this -

    Code:
    typedef struct tagMSG {     // msg 
        HWND   hwnd;     
        UINT   message; 
        WPARAM wParam; 
        LPARAM lParam; 
        DWORD  time; 
        POINT  pt; 
    } MSG;

    Windows then passes the first four parameters in this struct to your WndProc. WPARAM and LPARAM are both four bytes long and are used to send extra information along with the UINT message. Sometimes to squeeze extra information into these two parameters data is packed into each WORD (each 2 bytes). Therefore to extract this info you can use the HIWORD() and LOWORD() macros which look like -

    Code:
    #define LOWORD(l)           ((WORD)((DWORD_PTR)(l) & 0xffff))
    #define HIWORD(l)           ((WORD)((DWORD_PTR)(l) >> 16))
    I don't think there are set rules what about what type of data is sent in which parameter, so you'll either have to memorise what data is sent in each parameter for each message (if any) or look them up when you want to use them.
    zen

  3. #3
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Oh, I guess I'll try to memorize. They just get so confusing sometimes and when you mix them up, they don't generate an error (well, at least no for me) so it takes a while to figure out the problem.

    Thanks!

    --Garfield the Programmer
    1978 Silver Anniversary Corvette

  4. #4
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,227
    Yeah, you just have to memorize it... I used to have some sort of memory aide for Height and Width coordinates sent with WM_SIZE but now I couldn't tell you for the life of me...

    I think:

    x = LOWORD(lParam);
    y = HIWORD(lParam);

    but I really can't remeber..haven't had to use it in a long time.

  5. #5
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    > but I really can't remeber..haven't had to use it in a long time.

    Why not? When was the last time you had to (or wanted to) program a Windows application? I always thought that the WM_SIZE message was quite popular.

    Thanks.

    --Garfield the Programmer
    1978 Silver Anniversary Corvette

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    So many messages, so many params, too little time. Use the help, thats what it is for. No need to spend time rote learning when it will cost MUCH less time to look up the params rather than making a hard to find mistake.

    Remember a lot of controls send WM_NOTIFY mgs that are pointers to stucts. Are you going to memorise all of them?

    Next time I use WM_SIZE or(WM_EXITSIZEMOVE, WM_ENTERSIZEMOVE, WM_SIZING) ect I will look it up, even though I used it yesterday.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  7. #7
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,227
    well generally because most of the apps I've been doing lately have been dialog-based. Either that or I'm modifying old programs of mine and I already have the WM_SIZE completed.

    Not to mention I can't find enough time lately to program much...

  8. #8
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    > Not to mention I can't find enough time lately to program much...

    Ouch!!! Doesn't school cramp your style? I try to stay up for 2 extra hours to program. It is hard, but it is worthwhile.

    --Garfield the Programmer
    1978 Silver Anniversary Corvette

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating a Window Class
    By Dark_Phoenix in forum Windows Programming
    Replies: 2
    Last Post: 12-07-2008, 07:45 PM
  2. classmember WndProc isn't called ...
    By Greenhorn__ in forum Windows Programming
    Replies: 10
    Last Post: 07-19-2008, 11:40 AM
  3. destroywindow() problem
    By algi in forum Windows Programming
    Replies: 6
    Last Post: 03-27-2005, 11:40 PM
  4. button in function
    By algi in forum Windows Programming
    Replies: 1
    Last Post: 03-21-2005, 11:12 PM
  5. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 07:48 PM