Detect user closing application window

The windows and Mac versions of my app have the traditional window controls in the corner (minimize, maximize, and close). I’d like to catch the event if they hit the window close icon so that I can ask for a confirmation. Is this possible?

thanks!

For Windows (Win32 apps) you would need to handle the WM_CLOSE message, and you may be able to stop the process from closing (so it doesn’t send out a WM_QUIT message).

https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getmessage
https://en.wikipedia.org/wiki/Message_loop_in_Microsoft_Windows

There is plenty of info and examples on the net about how to handle these Windows messages, and perhaps there is something similar for Mac OS X.

1 Like

on MacOS there is a difference between closing a window and exiting an app. I’ve done this before.

Check out this thread

1 Like