CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 1999
    Posts
    42

    File contents changes, how to update view

    Hi:

    I am currently using Stingray OE, OT & OG. We are using Stingray library to help loading the project file and resources and display on the screen.
    The issue is: If I use a different editor or DLL that performing some task changes the file in the disk.

    The view did not get refreshed automatically, or notify the use that the file content has changed. The document in memory is not automatically notified.

    I found out that Microsoft Developer Studio caches information about each open file and upon receiving a WM_MDIACTIVATE message compares the cached information with the current file information. If the file has changed, it then asks the user if they would like to load the changed file. Unfortunately, this functionality is not built into the Microsoft MDI classes upon which the Stingray SECMDI classes are derived.

    Any pointer where to get a sample code ?


  2. #2
    Join Date
    Apr 1999
    Location
    Alabama, USA
    Posts
    261

    Re: File contents changes, how to update view

    Stingray's Knowledge Base is the best anywhere. I would think that would be the best place to look for answers. I know you probably already thought of that, so forgive me please for giving such a dumb answer.

    Good Luck.





  3. #3
    Join Date
    Jun 1999
    Posts
    42

    Re: File contents changes, how to update view

    Hi John:

    Actually I have not...

    BTW, I posted the same question to the Stingray support and they have no solution on it yet.

    Regards,

    Vincent


  4. #4
    Join Date
    Apr 1999
    Location
    Alabama, USA
    Posts
    261

    Re: File contents changes, how to update view

    Here are some Win32 functions that you may find useful.

    FindFirstChangeNotification()
    FindNextChangeNotification()

    perhaps you can use one of these functions to notify you when the file has changed, and then if your program wasn't responsible for the change, it can reload the file.

    Good Luck.




  5. #5
    Join Date
    Jun 1999
    Posts
    42

    Re: File contents changes, how to update view

    I was writing some test code regarding the solution you mentioned. Pls see code as below:

    BOOL CAdsApp::OnIdle(LONG lCount)
    {
    // This is a good area to firing up some maintainance code
    // The drawback is it might slow down the application.

    // Bug #009 & #010
    HANDLE dwChangeHandles;
    DWORD dwWaitStatus;
    CString strPathName;
    TCHAR szPath[DSP_MAX_TEXT_LENGTH];


    GetCurrentDirectory( DSP_MAX_TEXT_LENGTH, szPath );
    strPathName = szPath;


    dwChangeHandles = FindFirstChangeNotification(
    strPathName, // current working directory to watch
    TRUE, // watch the subtree
    FILE_NOTIFY_CHANGE_LAST_WRITE); // watch file last write time


    if (dwChangeHandles == INVALID_HANDLE_VALUE)
    ExitProcess(GetLastError());
    else
    {

    dwWaitStatus = WaitForSingleObject(dwChangeHandles, INFINITE);

    if (dwWaitStatus == WAIT_OBJECT_0)
    {
    // Get extended error information if the functioins fail
    if ( FindNextChangeNotification( dwChangeHandles) == FALSE ) ExitProcess(GetLastError());
    // Add your code here


    }
    }

    return CWinApp::OnIdle(lCount);
    }

    The problem is I need to to use WaitForSingleObject function to monitor the return by the handler, the whole application is hung due to this wait function. Is there a wait function that will run as background task ?


  6. #6
    Join Date
    Apr 1999
    Location
    Alabama, USA
    Posts
    261

    Re: File contents changes, how to update view

    You're on the right track, but don't wait in your App's OnIdle() or you'll hang the entire app. (I guess you noticed that huh??) What you'll want to do is start another thread and have it do the waiting. Then when the file changes, your new thread can notify the app, reload the file, or whatever is appropriate.

    None of the wait functions will run as a background task, but you can get the same effect by creating a thread that waits.


    Happy Coding,
    John






Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured