Solved

File changed notification

Posted on 2000-05-07
3
179 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
repeatSeparator  java  challenge 13 59
Best tools for Backup and restore of Wordpress site 6 58
twoTwo  challenge 35 118
How do I get Window Title of all opened process? 4 58
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.

738 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