?
Solved

File changed notification

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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

800 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