Click here to Skip to main content
15,851,711 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is there a built-in way to distinguish if my file save code is being called from Restart Manager or from a manual click?

What I have tried:

Auto-save calls OnSaveDocument directly, whereas clicking on the File->Save menu calls OnSave, which in turn calls OnSaveDocument, so I could set a "manual save" flag in the OnSave event handler, but I am wondering if there's a built-in way of telling the two apart.
Posted
Updated 15-Feb-17 0:14am

1 solution

You must implement an own flag for that use case. A bool class member should be enough.

Tip: Remember to reset the flag after use, so both cases can be differentiated.
 
Share this answer
 
Comments
hairy_hats 15-Feb-17 6:02am    
The simplest way seems to be to compare the requested file save path with the auto-save path in OnSaveDocument and set a manual/auto-save flag appropriately before saving the file:

BOOL CMyDoc::OnSaveDocument(LPCTSTR lpszPathName) 
{
	CDataRecoveryHandler* autohandler = AfxGetApp()->GetDataRecoveryHandler();
	CString autosavepath = autohandler->GetAutosavePath();
	BOOL success = FALSE;

	if (CString(lpszPathName).Left(autosavepath.GetLength()).CompareNoCase(autosavepath) == 0)
	{
		// autosaving - just call the default
		m_manualSave = false;

		success = CDocument::OnSaveDocument(lpszPathName);
	}
	else
	{
		// manual save - do whatever is needed
		m_manualSave = true;

		success = CDocument::OnSaveDocument(lpszPathName);
	}
	
	return success;
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900