Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to call PostQuitMessage

Like many applications, mine creates multiple windows. I do not know and cannot keep track of how many windows have been created, so I don't know when there are none.

My problem is that when all the windows are closed, unless I call PostQuitMessage somehow, the application keeps running with no windows open (obviously). I can't call PostQuitMessage in the message handler in response to the WM_DESTROY message because that will close all the windows when the first one is closed, even if there are twenty others still open.

My question is how do I know when to call PostQuitMessage(0) to actually terminate the application?

like image 443
Seth Carnegie Avatar asked Sep 15 '25 00:09

Seth Carnegie


1 Answers

If, for some reason, you really can't count how many windows the application opens, you can still use EnumThreadWindows() and when there are no more windows, you PostQuitMessage(). If you have several threads, make sure you enumerate through those too.

From MSDN

BOOL WINAPI EnumThreadWindows(
  __in  DWORD dwThreadId,
  __in  WNDENUMPROC lpfn,
  __in  LPARAM lParam
);
like image 96
Coincoin Avatar answered Sep 16 '25 14:09

Coincoin