

Then, when you get the close command and display the user prompt, you can check that flag. It seems to me that the best you can do is use the WndProc() override to track incoming messages, so that you can reset a flag when non-close-command messages come in. The only access to window messages you get is to override the Control.WndProc() method, and by the time you get the close command, the most recent window message there will always be the SC_CLOSE. Otherwise, you'll just see the WM_SYSCOMMAND itself.īut you can't apply the same approach in WPF, because WPF doesn't provide a GetCurrentMessage() method or its equivalent (as far as I know). If it was user input that was translated to a close command, there will be some type of user input (keyboard, mouse, etc.) as the current message. the context of the other question), you can call AfxGetCurrentMessage() to retrieve information about what actually instigated the SC_CLOSE message. The system is simply sending the messages to the windows in sequence. That said…Īs the question you've found points out, there is no built-in way to distinguish the "Close all windows" from a regular "Close window" command. And while annoying, it seems like a minor annoyance, and frankly one that might teach the user to not use the "Close all windows" option when they have left a bunch of these windows open. I can see how having several prompts to save/cancel changes could be annoying, but it doesn't seem confusing to me. Personally, I would just leave things as they are.

Odd form closing behavior when using taskbar's Close All Windows This question is somehow related to this one:

(see How can I distinguish between "Close All Windows" and "Close" individual windows in MFC with Windows 7?)īut how can I evaluate this, before I execute the closing-routine for any other window?ĬomponentDispatcher.ThreadPreprocessMessage in my mainwindow comes too late, it fires after some other window has started the closing procedure. I have already found out, that I probably need to check the Windows Message Loop of my MainWindow for some WM_SYSCOMMAND with wparam SC_CLOSE. If yes, all windows should close silently, otherwise stay open.īut my MainWindow is not the first one, to process the closing procedure. What I want is: If the MainWindow is asked for closing, I want to prompt once, if that's ok. This is annoying and confusing if there are many of those. Some of my windows may ask before closing, if it's okay to cancel pending changes. If it is clicked, each Window of my application gets an individual close-command in an order I cannot control. If these windows get grouped in the taskbar, windows will provide the action "Close all Windows" in the taskbar context menu. there is always one MainWindow and optionally many others with no owner. I have a WPF-application with multiple unrelated Windows, i.e.
