• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

Save Before Close

I thought this was default behavior for any SDI app...but it is not happening in mine. Before a user closes an application...I want it to ask them if they want to save changes to the current document...and only if it has been modified. How is this done?
0
SGyves
Asked:
SGyves
1 Solution
 
KurtVonCommented:
Use the CDocument::SetModifiedFlag function to tell the document that it has been modified.  Unless you overrode the save handler this should be all you need to do.

Hope this helps.
0
 
jkrCommented:
You'd call the 'IsModified()' member of your 'CDocument' derived class and, dpending of the modified state, prompt the user.
0
 
SGyvesAuthor Commented:
Then from the document...how do I call the save routine
0
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
KurtVonCommented:
CDocument::SaveModified() prompts the user if teh document is set to modified.

Hope this helps.
0
 
SGyvesAuthor Commented:
So it looks like as long as you set the flag...the save routine gets called
0
 
luvjdCommented:
Easiest way is to....handle WM_CLOSE message..
in the class wizard...in the MainFrame...handle WM_CLOSE message...

MFC adds the following function...
everytime the user closes the application control comes here...

void CMainFrame::OnClose()
{
      
      CFrameWnd::OnClose();//If u comment this line the application does not close..
}

Now u can modify it as...
void CMainFrame::OnClose()
{
      if(m_bNotSaved)
                      CFrameWnd::OnClose();                  
                else
                //Call u r Save routine here
                PromptForSave() ;
               CFrameWnd::OnClose();
}
Luv ..
Jd
               

}


0
 
KurtVonCommented:
Unless you override the save routine, the framework automatically checks the modified status, prompts if the document is modified, and then serializes if the user chooses "yes."

So all you need to do is set the modified flag when the document is modified (and it is okay to call this multiple times, so you don't even need to check it) and override the ::Serialize function to write out the ocument.  MFC should handle everything else for you.

Hope this helps.
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

Tackle projects and never again get stuck behind a technical roadblock.
Join Now