Getmessage() function

From my book:

"The second argument in the call to GetMessage() is the handle of the window for which you want to get messages. This parameter can be used to retrieve messages for one application window separately from another. If this argument is NULL, as it is here, GetMessage() retrieves all messages for an application. This is an easy way of retrieving all messages for an application regardless of how many windows it has. It is also the safest way because you are sure of getting all the messages for your application. When the user of your Windows program closes the application window for example, the window is closed before the WM_QUIT message is generated. Consequently, if you only retrieve messages by specifying a window handle to the GetMessage() function, you cannot retrieve the WM_QUIT message and your program is not able to terminate properly."

What is that last part describing. Can anyone simplify it? Very confused
Last edited on
It means that if you specify the Window handle, you'll only get messages for that Window. It then explains why you'll miss the WM_QUIT message to demonstrate why that's a bad idea.
But thats what I dont understand.

"When the user of your Windows program closes the application window for example, the window is closed before the WM_QUIT is generated? "

Why is it closed before it is generated? Wouldn't that mean you miss it either way?
That is a bit confusing.

The WM_QUIT message is generated, but because you are only removing the messages for your window using GetMessage when you pass it your window's handle, the message pump while-loop never exits. (system messages have a hwnd value of NULL.)

So even though the window has gone, the app will still be running; but invisible -- it will be listed in Task Manager's "Process" list, though.

Andy

PS I think the book you're currently reading ("Beginning Visual C++" by Ivor Horton?) is possibly a bit confusing as a first book on Windows programming?

I think you should maybe look at "Programming-Windows" (by Charles Petzold), the book most people use to learn Win32 programming.
http://www.charlespetzold.com/pw5/

http://www.charlespetzold.com/blog/2012/05/Programming-Windows-6th-Edition-for-the-CPlusPlus-Programmer.html Edit: this old link points at a book about Metro apps... :-( -- oops!

You could try borrowing a copy from a library to start with, to see what you think about it?

Also see

win32 programming
http://www.cplusplus.com/forum/windows/90336/

Is Petzold's book still relevant?
http://www.cplusplus.com/forum/windows/90740/

...
Last edited on
Yea I am using that book lol.

Well I have petzold's book too, I was just seeing if I could use this as a introduction. So do you think I should just read Petzold's?

I'm gonna go to school for now thanks for all your help.
Last edited on
closed account (G309216C)
Yes! Petzold's Book is awesome I read it few times. Although it does not teach advanced Windows Programming Concepts but it is still useful in sense majority of Needed items are included in it.

GL
btw the 6th edition is for metro apps, the 5th edition is for winapi
closed account (G309216C)
yes, 5th edition is also one of the best books I read so far.
btw the 6th edition is for metro apps, the 5th edition is for winapi

Oops! I've corrected my post.

Andy
Topic archived. No new replies allowed.