Quantcast
Channel: The Old New Thing
Viewing all articles
Browse latest Browse all 3085

How can I determine the reason why my window is closing?

$
0
0

A customer wanted to know whether their MFC program can determine why their window is closing, similar to how WinForms does.

The source code for WinForms is online. You can see how they do it, and then translate that to MFC.

Many of the Close­Reason values refer to actions that occurred within WinForms itself, so those are naturally generated by WinForms. Three of the reasons are external to WinForms.

The “provided it wasn’t already set by someone else with better information” is important, because many of the window closing scenarios lead to WM_CLOSE. For example, the default handling for the SC_CLOSE system menu command is to send the WM_CLOSE message, so you will see the SC_CLOSE first, followed by the WM_CLOSE message.

Note that Task­Manager­Closing is inferred by the fact a WM_CLOSE message arrives without any of the known preliminaries. While it’s true that Task Manager uses the WM_CLOSE message to encourage an app to exit, it’s not the only program that does it.

A better name might be External or Programmatic.

The post How can I determine the reason why my window is closing? appeared first on The Old New Thing.


Viewing all articles
Browse latest Browse all 3085

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>