CanClose should rarely return false.
Instead, CanClose should perform any actions necessary to return true. CanClose should return false only if it's unable to do something necessary for orderly shutdown, or if the user wants to keep the application running. For example, suppose you are creating a text editor. A possible procedure to follow in the CanClose member function would be to
- Check to see if the editor text had changed
- If so, prompt the user to ask whether the text should be saved before closing, using a message box with Yes, No, and Cancel buttons
- Check the return value from the message box: – If the user clicks Yes, save the file, return true from the CanClose function. – If the user clicks No, simply return true from the CanClose function without saving the file. – If the user clicks Cancel indicating that the user does not want to close the application yet, return false from the CanClose function without saving the file.