Click to See Complete Forum and Search --> : File contents changes, how to update view


vlim
June 11th, 1999, 04:14 PM
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 ?

John Holifield
June 11th, 1999, 04:38 PM
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.

vlim
June 11th, 1999, 04:47 PM
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

John Holifield
June 11th, 1999, 04:55 PM
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.

vlim
June 15th, 1999, 04:59 PM
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 ?

John Holifield
June 15th, 1999, 05:35 PM
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