Jump to content
  • Advertisement
Sign in to follow this  
Samurai Jack

Winapi: Last window closed? PostQuitMessage

This topic is 4441 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

Greetings! I was wondering, if it is by any chance possible to determine with WINAPI when my last window was closed? For example: I wrote a tiny component library, that has a base class: cWindow sobe derivates: cLabel : public cWindow cButton : public cWindow I would like in cWindow::OnDestroy that if it is the last window open, it shall send the PostQuitMessage. The problem? What if you have to or more windows, and I do not want cButton to send PostQuitMessage when it is destroyed. The idea is how to detect that last cWindow was destruct? I can not just sit in the destructor with a couter because there is allways a posibility that an user declares a cWindow variable, but never opens a window. For example:
cWindow* pWin = new cWindow();
delete pWin;
I would not like that in souch a situation PostQuitMessage gets called. I have the HANDLE to my Application Module, now I would like to determine how many Windows are registered? Is it possible?

Share this post


Link to post
Share on other sites
Advertisement
There's no way from the API, you'll have to handle it yourself. I'd do it with a static member variable in cWindow, that gets incremented whenever a window is created, not just allocated, and decremented in WM_DESTROY.

Having said that, I hate using PostQuitMessage() because it stops any more windows being created (Including error MessageBox()es). I usually just set a flag somewhere or return false to indicate that the app should exit.

Share this post


Link to post
Share on other sites
I think wxWidgets does this by by doing things like Steve says. All "top-level" windows derive from a single base class that increments a shared counter as they are created and decrements when its destroyed. Then when you destroy the last of the "top-level" windows it will fire off a message that its time to terminate the program.

Just for clarification, a top-level window would be any of your main dialogs, not something like a button or static box or whatever. But you could do it however you see fit.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!