Destructicons: Closing Down in Win95

Dear Dr. GUI:

We're finding that under Windows 95, if you use the "Start->Shutdown->Close all Programs and Logon as different user" option to log out of Windows and log back on, the destructors for our App/Doc/Frame/... don't get called!

I guess I could either SendMessage(WM_CLOSE) to the frame during OnEndSession or DestroyWindow the frame there, but that still means the application's destructor won't be called. (Luckily, we aren't doing much of anything in the app destructor—most of the work is in our doc's constructor, which should be called with this workaround, me thinks.)

Gman

Dr. GUI replies:

Destructicons. Obviously a play on my kid's toy Decepticons. These are little toy trucks, forklifts, and Cessna airplanes that unfold into robots. My kid loves them. I despise them. Each morning I run the gauntlet from my bed to the bathroom, dodging the stupid things, wondering if I had a tetanus shot recently. These silly things even have names: Optimus Prime, Trashcan, Prime Directive, Destined-for-garbage. Perhaps I should talk about destructors.

Yes, the destructors for the applications are not being called. The idea is that a user wants to exit Windows 95 without watching all 20 programs that are running disappear from the desktop one-by-one.

Sending WM_CLOSE would be pretty sloppy, as the user will notice your application disappear from the desktop before the desktop goes away, which would be different from other applications out there. The following suggestions will help you clean up after yourself in a reliable way:

· Handle most of the cleanup in your document's OnCloseDocument or its destructor (your document's destructor will be called unless you have set CDocument::m_bAutoDelete to FALSE).

· Have the application-related shutdown done in ExitInstance (yes, it will be called).

Finally, consider using CWinApp::CloseAllDocuments. It is even passed a flag that indicates that the Windows session is ending.