-
April 13th, 2012, 01:38 AM
#1
MFC Document changed
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
#2
Re: MFC Document changed
You can handle WM_MDIACTIVATE message and get the last modified time of the document's file.
Example
Code:
void CChildFrame::OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd)
{
CMDIChildWnd::OnMDIActivate(bActivate, pActivateWnd, pDeactivateWnd);
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
#3
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.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|