Article View: borland.public.cppbuilder.nativeapi
Article #10173Using Damon Chandler's FindNextChangeNotification example
From: JD
Date: Fri, 21 May 2004 11:34
Date: Fri, 21 May 2004 11:34
51 lines
2654 bytes
2654 bytes
I'm using Damon's example that can be found here:
http://bcbcaq.freeservers.com/Project_Monitor.html
Aside from some minor name changes, the only differences are
that I overrode the WndProc method instead of using a message
map and that I'm only looking for FILE_NOTIFY_CHANGE_LAST_WRITE
so that my application can receive notification that any file in
the directory was modified.
The problem is that my application get's the notification twice.
//--------------------------------------------------------------
void __fastcall TMain::WndProc( TMessage &Message )
{
if( Message.Msg == APP_WATCHFOLDER_FILECHANGE )
{
ShowMessage("A File was changed");
}
else TForm::WndProc(Message);
}
//--------------------------------------------------------------
void __fastcall TMonitorThread::Execute()
{
while( !Terminated && ChangeHandle != INVALID_HANDLE_VALUE )
{
bool TimedOut = true;
while( TimedOut && !Terminated && !Suspended )
{
DWORD dwStatus = WaitForMultipleObjects( 1, &ChangeHandle, false, 2000 );
if( dwStatus == WAIT_OBJECT_0 && !Terminated )
{
Synchronize( NotifyApplication );
if( !FindNextChangeNotification(ChangeHandle) ) break;
}
else if( dwStatus == WAIT_TIMEOUT && !Terminated ) TimedOut = true;
else TimedOut = false;
}
}
Terminate();
}
//--------------------------------------------------------------
void __fastcall TMonitorThread::NotifyApplication()
{
// TargetControl is the main form passed a param to the c'tor
if( TargetControl ) TargetControl->Perform( APP_WATCHFOLDER_FILECHANGE, 0, 0 );
}
//--------------------------------------------------------------
~ JD
Technical Details
Message-ID:
<40ade94f$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!controlnews3.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,32a59cffbb6bea4a,start X-Google-Attributes: gid10cc67,public From: "JD" <nospam@nospam.com> Sender: "JD" <nospam@nospam.com> Reply-To: "JD" <nospam@nospam.com> Subject: Using Damon Chandler's FindNextChangeNotification example Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 172.132.239.110 NNTP-Posting-Host: 207.105.83.66 Message-ID: <40ade94f$1@newsgroups.borland.com> Date: 21 May 2004 04:34:39 -0700 X-Trace: newsgroups.borland.com 1085139279 207.105.83.66 (21 May 2004 04:34:39 -0700) Lines: 52 Path: arc1-ca.pugleaf.net!controlnews3.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail