Click to See Complete Forum and Search --> : Help! 'x' box at top right of window


zach
April 9th, 1999, 09:04 AM
Hello. When you click on the 'x' box on the top right of the window, it sends a WM_DESTROY message. In the OnDestroy function, I have my code calling SetModifiedFlag(TRUE), however, I never get a prompt asking to save the document. What would be the correct way to save information from a form upon exiting from the form? Thanks.

LALeonard
April 9th, 1999, 06:16 PM
Well, the correct way is to call SetModifiedFlag(true) at the point where the user modifies the data.

But, if you just want to force the user to always be prompted, call SetModifiedFlag(true) in the WM_CLOSE handler, not the WM_DESTROY handler. There is much confusion in the world about the meaning of these two messages.

WM_CLOSE is sent by Windows to say, "I have been asked to close this window - is that okay with you?". If it's okay with you, your OnClose( ) handler should call the base class CWnd::OnClose( ) method; that method will, in turn, post a WM_DESTROY message. (If it's not okay with you, simply don't call the base method.)

WM_DESTROY is Windows' way of saying, "This window is closing, whether you like it or not. Do whatever cleanup you need to do, because this is your last chance!"

HTH.


LA Leonard - Definitive Solutions, Inc.