Archived

This topic is now archived and is closed to further replies.

Basic Question about windows programming

This topic is 5669 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i''ve been programming for windows for about 3 weeks i get everything i know why u need a procedure and how to handle messages and stuff like that but i still have some questions on my mind like these. what is wParam for?? i know u can send back messages to the window like return Msg.wParam ... that''s it ?? and what about lparam ??? Now about hInstance and hPrev. Why u have to delcare hprevsince u dont use it right ?? last one what is LOWORD and HIWORD ?? like LOWORD(wParam) ?? thx for all the replies

Share this post


Link to post
Share on other sites
hPrehInstance is for 16-bit Windows programs, don''t use it in Win32. It''s only there for compatibility with the old stuff.

When your window gets a message, your winproc gets 4 vars, the hwnd, the msg, and the wparam/lparam. The hwnd is obviously the window thats getting the message, the msg is the message, and the w/l params are additional data that go along with the message. Some messages don''t need them, some do, like WM_KEYDOWN which needs to tell you which key is down.

LOWORD/HIWORD are just macros to use with the params. Each param is an int, 32bit, so sometimes if a message has a lot of data to give you it will pack 2 values into a param, so 16bits of the param for one piece of info, the other 16bits for another, thereby being able to send you 4 values in the 2 params. Use LOWORD to get the value in the first 16bits, HIWORD to get the second 16bits. It''s all simple bit shifting/masking/twiddling, look it up in your favourite C textbook.

------------
- outRider -

Share this post


Link to post
Share on other sites
Well wParam and lParam are used to store messages specific to the message being sent to your message loop. eg for the WM_MOUSEMOVE message which sends a message whenever the mouse is moved, lParam and wParam store messages eg wParam stores the x and y position of where the mouse is. Now, but you may ask, how can you store 2 items in one variable? well thats where LOWORD and HIWORD come in, wParam is a DWORD (unsigned long) which is 32 bits which you dont need them all for such small numbers so in the bottom half is stored the x and the top WORD y. eg:
  
// in the message loop

case WM_MOUSEMOVE:
{
int x = LOWORD(wParam);
int y = HIWORD(wParam);
// do what you will with mouse location info...

}break;

LOWORD() and HIWORD() are just win32 macros to get to the info...

CEO Plunder Studios

Share this post


Link to post
Share on other sites
quote:
Original post by elis-cool
Damn it!! you bet me!! I need to learn to type faster!! hehe

CEO Plunder Studios


ok i understood what wparam and lparam do and how LOWORD and HIWORD works.. but what kind of messages does wparam return and lparam ?? i know u use wparam mostly for keyboard and the window itself ??? like

wParam can return the Mouse POsition, the key pressing dow what else ?? and what about lparam ?

Share this post


Link to post
Share on other sites
quote:
Original post by Metal Typhoon
but what kind of messages does wparam return and lparam ??

That depends on the message. The docs for each message describe what wParam and lParam do/mean.

Share this post


Link to post
Share on other sites
wParam and lParam can hold absolutely anything -- what they hold depends on the value of the message (the UINT parameter). If you look up any message Windows can pass to your program (the best place to look them up is at the MSDN Library, msdn.microsoft.com/library), it will tell you what, if any, values are passed in wParam and/or lParam along with the message.
If you''re sending messages to your own window, send whatever you like in wParam and lParam.

Twilight Dragon
www.freewebz.com/j-world

Share this post


Link to post
Share on other sites
quote:
Original post by TDragon
wParam and lParam can hold absolutely anything -- what they hold depends on the value of the message (the UINT parameter). If you look up any message Windows can pass to your program (the best place to look them up is at the MSDN Library, msdn.microsoft.com/library), it will tell you what, if any, values are passed in wParam and/or lParam along with the message.
If you''re sending messages to your own window, send whatever you like in wParam and lParam.

Twilight Dragon
www.freewebz.com/j-world
thx alot for all the responses... you guys are the best

Share this post


Link to post
Share on other sites