Solved

File changed notification

Posted on 2000-05-07
3
168 Views
Last Modified: 2013-11-20
Hi,
I need to do the following in my MDI application:
If the file associated with the active view changes by other application then when the user returns to my application
one message box must warn this.

I have think to do the following: Save the modified time and each the OnSetFocus message is sent to the view, compare it with a new modified time reading.
The problem is that this message is always being sent after the message box ends. More each window in my application that loses focus to my view will trigger this message.
Can I filter this to only accept OnSetFocus from alien windows?
Is there a better way to spy file changes?

I am looking for comments on my solution and of course how to solve the problem if this is the right way to do things.
0
Comment
Question by:lsimaozinho
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 2786003
The easiest way to do this is opening a notification handle for this file in a separate thread and send a message to your application when the file is modified, e.g.

('pseudocode', error checking omitted for brevity)

HANDLE      g_hFileWatcher;
DWORD       g_dwTID;

    g_hFileWatcher  =   CreateThread    (   NULL,
                                            0,
                                            FileWatcher,
                                            (PVOID) "c:\\docs\\whatever.txt",
                                            0,
                                            &g_dwTID
                                        );


int WINAPI FileWatcher  (   LPVOID  pv)
{
    HANDLE  hNotify;
    DWORD   dwWaitResult;
    char*   pszFile =   ( char*) pv;

    OutputDebugString   (   "FileWatcher(): here i am!!!\n");

    hNotify =   FindFirstChangeNotification (   pszFile,
                                                FALSE,
                                                FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_LAST_WRITE
                                            );

    if  (   INVALID_HANDLE_VALUE    ==  hNotify)
            OutputDebugString   (   "Error acquiring handle file!!!\n");

    for (   ;;)
        {
            dwWaitResult    =   WaitForSingleObject (   hNotify,
                                                        INFINITE
                                                    );

            if  (   WAIT_ABANDONED  ==  dwWaitResult)
                    return( dwWaitResult);

            OutputDebugString   (   "FileWatcher(): there has been some change...\n");

            SendMessage ( WM_THEFILEHASCHANGED, ...)

            FindNextChangeNotification  (   hNotify);
        };

    return( 0);
}

Feel free to ask if you need more information!
0
 
LVL 86

Expert Comment

by:jkr
ID: 2786097
Ooops, forgot something - be sure to insert 'CloseHandle ( hNotify);' before the 'return' statement... Sorry ;-)
0
 

Author Comment

by:lsimaozinho
ID: 2786109
Thanks jkr
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Host to IP 7 78
difference between String.subString() and String.subSequence() 6 196
Path of Workbook 3 77
Making an alias 7 95
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question