Intercept closing the window on Windows.

When I close the window, I want to pop up a the dialog that asks if I want to save my changes first.

Using this code and some Winforms magic I made it work.

var form = (Form)Form.FromHandle(handle);
form.Closing += ClosingForm;

But - only on WindowsDX. When I run the same thing on DesktopGL, Form.FromHandle returns null. On further inspection, Application.OpeForms has no forms at all, which makes me suspect DesktopGL uses something else. I don’t need this for Macos or for Linux, I just need a Windows-only solution for DesktopGL.

DesktopGL uses SDL. From the looks of it this functionality isn’t built into Monogame but it’s just a simple change if you build from the source code.

The line which signals the close button is pressed is here:

Then the line which uses this value to close the program is here:

Also the SDL documention regarding the Quit event is here:

Replacing _isExiting with your own request and send objects that can be accessed in your game code should be all that is needed.

Hope that helps.

Problem is, I don’t.