Basic Question about windows programming

Started by
6 comments, last by Metal Typhoon 21 years, 10 months ago
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
Metal Typhoon
Advertisement
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 -
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 loopcase 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
[email=esheppard@gmail.com]esheppard@gmail.com[/email]
Damn it!! you bet me!! I need to learn to type faster!! hehe

CEO Plunder Studios
[email=esheppard@gmail.com]esheppard@gmail.com[/email]
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 ?
Metal Typhoon
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.
---visit #directxdev on afternet <- not just for directx, despite the name
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
{[JohnE, Chief Architect and Senior Programmer, Twilight Dragon Media{[+++{GCC/MinGW}+++{Code::Blocks IDE}+++{wxWidgets Cross-Platform Native UI Framework}+++
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

Metal Typhoon

This topic is closed to new replies.

Advertisement