MFC Document changed
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: MFC Document changed

  1. #1
    Join Date
    Sep 2010
    Posts
    29

    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.

  2. #2
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,023

    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.
             // ...
          }
       }
    }
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  3. #3
    Join Date
    Sep 2010
    Posts
    29

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center