[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

File changed notification

Posted on 2000-05-07
3
Medium Priority
?
199 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 800 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Suggested Courses

656 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