Solved

Save Before Close

Posted on 2003-12-08
7
307 Views
Last Modified: 2013-11-20
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
Comment
Question by:SGyves
7 Comments
 
LVL 11

Accepted Solution

by:
KurtVon earned 250 total points
ID: 9898675
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
 
LVL 86

Expert Comment

by:jkr
ID: 9898709
You'd call the 'IsModified()' member of your 'CDocument' derived class and, dpending of the modified state, prompt the user.
0
 

Author Comment

by:SGyves
ID: 9898871
Then from the document...how do I call the save routine
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 11

Expert Comment

by:KurtVon
ID: 9899212
CDocument::SaveModified() prompts the user if teh document is set to modified.

Hope this helps.
0
 

Author Comment

by:SGyves
ID: 9901646
So it looks like as long as you set the flag...the save routine gets called
0
 
LVL 1

Expert Comment

by:luvjd
ID: 9902423
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
 
LVL 11

Expert Comment

by:KurtVon
ID: 9904112
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
not able to insert into temp table 68 157
Use of condition with 'serial' in ansible 2 49
Dell Alienware Graphics Amplifier Driver for non-Alienware systems 18 193
Problem to event 3 78
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now