I'm developing an app using Win32 that should quit when the last window is closed. This is the default behavior of apps like File Explorer, Chromium, etc. My app is similar to these examples in the sense that there is no one "main" window that should quit the app when closed — all windows are important.
From the tutorials, I know I can call PostQuitMessage(0)
under WM_DESTROY
, but this quits the app when any window is destroyed. If I don't call PostQuitMessage(0)
, the app remains open after the last window is destroyed.
How can I ensure the application quits when all windows are destroyed? Do I have to manually keep track of the # of windows created and destroyed, only quitting when the count is 0? Surely there is a more native Win32 solution.
My app is similar to these examples in the sense that there is no one "main" window that should quit the app when closed — all windows are important.
Yes, as you asked and @IInspectable answered, you need to track. And there is not a uniform solution. You can implement it as you like.