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?
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
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With