Hi everyone,
I created a MFC MDI Application. I want to manage it in order to check, every time a View get focus, that its Document has been changed or not (for example using another hinstance of the same application or a text editor), notifying with a MessageBox something like this "(file name): this file has been modified by another program, do you want to reload it?".
How can I manage this behaviour?
Thanks a lot for your help.
April 13th, 2012, 03:17 AM
ovidiucucu
Re: MFC Document changed
You can handle WM_MDIACTIVATE message and get the last modified time of the document's file. Example
if(bActivate)
{
CDocument* pDoc = ((CFrameWnd*)pActivateWnd)->GetActiveDocument();
const CString& strFile = pDoc->GetPathName();
if(!strFile.IsEmpty())
{
CFileStatus fileStatus;
VERIFY(CFile::GetStatus(strFile, fileStatus));
CTime m_TimeModified = fileStatus.m_mtime;
// Next, compare the actual modified time with last modified time,
// which may be one previously stored in document's class.
// ...
}
}
}
April 17th, 2012, 02:02 AM
symreds
Re: MFC Document changed
It works, except that this update is not on application focus, but on Document switching. Anyway, I put this code in CMainFrame::OnActivateApp and it works perfectly!
Thanks a lot.