If you are using VC++ then serialize your data (in the Serialize function) and use SetModifiedFlag() to mark your document as dirty. This is done when you add or modify a variable in your program.
I started with an SDI Project from the MFC AppWizard and I chose my view class to de derived from CRecordView. The app will save automatically when the user moves through the record using the premade toolbar buttons or menu options, but it won't save the latest change if the user exits the program without moving throught the record first. I can make a button that saves when clicked by having it run the code:
void somefunction()
{
//check to see if the user created a new record
if (m_UpdateMode) //new record was created
{
UpdateData(TRUE);
if (m_pSet->CanUpdate())
m_pSet->Update();
m_pSet->Requery();
}
else //only edits of current records were made
{
if (m_pSet->CanUpdate())
{
m_pSet->Edit();
UpdateData(TRUE);
m_pSet->Update();
}
}
m_UpdateMode = FALSE;
UpdateData(FALSE);
}
Now if I could put this code in a place that always runs before the View Class is destroyed, I think I'd be set.
If you are using MFC, just override CWinApp::ExitInstance and put there all code for destruct/saving/closing handles/files/databases/connections... John Fill
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.