[plt-scheme] Letting Windows close DrScheme

From: Gordon Weakliem (gweakliem at oddpost.com)
Date: Wed Jul 28 17:33:29 EDT 2004

Well, I can't tell you about specific mods to MrEd, I have a hard time understanding the abstractions in WxWindows, but I can describe what Windows does.  Essentially, when you ask Windows to shutdown, it first asks all the running apps if it's OK to shutdown, and then tells them to shut themselves down.  Specifically, Windows sends a WM_QUERYENDSESSION to every application running.  If any application returns 0 to this message, the shutdown is cancelled.  Then, Windows sends WM_ENDSESSION to every application with a wParam set to 1 if the system is shutting down.  So you can get a WM_QUERYENDSESSION, return non-zero, and get a WM_ENDSESSION with wParam = 0, which means somebody else cancelled the shutdown.  You can also test the lParam of the WM_ENDSESSION to test whether it's a logoff or shutdown, but you probably don't care about that. 
So I'm sure what's happening is that MrEd returns 0 to WM_QUERYENDSESSION and kills the shutdown.  You'll need to catch that message, return 1, and then in WM_ENDSESSION, do the normal shutdown routine as if the user had closed the app.  I would recommend bypassing the "do you really want to exit?" prompt in this case, because if this dialog isn't dismissed, Windows will decide the app is unresponsive and ask to kill it.  As far as saving unsaved files, it seems like a lot of apps will display a dialog to prompt for save, I don't think you can get around that, you can't make a reasonable save/nosave decision without asking. 
For extra credit, you could handle WM_POWERBROADCAST to handle power events :-) 
Gordon Weakliem 
-----Original Message from Michael Sperber <sperber at informatik.uni-tuebingen.de>-----
For list-related administrative tasks: 

When I shut down Windows on a machine running DrScheme (or any other 
application running under MrEd), all "normal" Windows application 
happily quit, only DrScheme remains completely unfazed by this.  As a 
result, Windows seems to silently cancel the shutdown. 

I'm really interested in running my own application under MrEd that 
would quit under these circumstances---does anyone have any idea how 
to detect the event of the user shutting down? 

Cheers =8-} Mike 
Friede, Völkerverständigung und überhaupt blabla

Posted on the users mailing list.