Article View: borland.public.cppbuilder.nativeapi
Article #10711Re: FindFirstChangeNotification - which File(s) was/were changed
From: Dave
Date: Sat, 27 Mar 2004 04:57
Date: Sat, 27 Mar 2004 04:57
129 lines
5385 bytes
5385 bytes
On Fri, 26 Mar 2004 11:26:20 -0800, Remy Lebeau (TeamB) wrote:
>
> "Dave" <dave_xse@-spam-hotmail.com> wrote in message
> news:gtsccansk388.1njug0ildrjsr$.dlg@40tude.net...
>
>> I'm using FindFirstNotification to watch for changes in
>> Files in a Directory. It get the signal fine when changes
>> occur however i don't know which files have changed.
>> Is there any simple way of knowing it ? = not having to
>> create my own... :-)
>
> Not with FindFirstChangeNotification(), no. It only tells you that a chance
> has occured, but not what the change actually is. If you need that
> information, then you should use SHChangeNotifyRegister() instead. When a
> change occurs, you are provided with the ITEMIDLIST for the affect file(s).
> An ITEMIDLIST is the OS's internal version of a filename, but much more
> flexible. If you want to know the filename that changed, you can pass the
> ITEMIDLIST to SHGetPathFromIDList().
>
>
> Gambit
I have done it but it just won't work yet...
The event is newer trapped by the Form's message handler
somehow...
can you have a look at the code? (compiles with NO_WIN32_LEAN_AND_MEAN)
Thanks Guys,
Dave
Here's Unit1.cpp
//-------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//-------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
HANDLE hNotify;
HANDLE hShell;
//-------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
LPCITEMIDLIST ItemID;
BROWSEINFO BrowsingInfo;
char DirPath[MAX_PATH];
char FolderName[MAX_PATH];
memset(&BrowsingInfo, 0, sizeof(BROWSEINFO));
memset(DirPath, 0, MAX_PATH);
BrowsingInfo.hwndOwner = Handle;
BrowsingInfo.pszDisplayName = FolderName;
BrowsingInfo.lpszTitle = "Hello"; //Title.c_str();
ItemID = SHBrowseForFolder(&BrowsingInfo);
NOTIFYREGISTER Mine;
Mine.pidlPath = ItemID;
Mine.bWatchSubtree = true;
DWORD cItems = 1;
hShell = LoadLibrary("SHELL32");
if (!hShell){
ShowMessage("Shell loading failed.");
return;
}
SHChangeNotifyRegister = (HANDLE(*)(HWND, DWORD, LONG, UINT, DWORD,
NOTIFYREGISTER)) GetProcAddress(hShell, (char *) 2);
SHChangeNotifyDeRegister = (bool(*)(HWND)) GetProcAddress(hShell, (char
*) 4);
if (SHChangeNotifyRegister){
hNotify = SHChangeNotifyRegister(Form1->Handle, SHCNF_ACCEPT_INTERRUPTS
| SHCNF_ACCEPT_NON_INTERRUPTS, SHCNE_ALLEVENTS, WM_USER, cItems, Mine);
if (!hNotify) ShowMessage("SHChangeNotifyRegister Failed");
}
}
//-------------------------------------------------------------------------
void __fastcall TForm1::DirectoryHasChanged(TMessage &Msg)
{
Edit1->Text = "Some stuff happened";
}
//-------------------------------------------------------------------------
And this is it's header file
#ifndef Unit1H
#define Unit1H
//-------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Dialogs.hpp>
//-------------------------------------------------------------------------
#include "shlobj.h"
#define SHCNF_ACCEPT_INTERRUPTS 0x0001
#define SHCNF_ACCEPT_NON_INTERRUPTS 0x0002
#define SHCNRF_RECURSIVE_INTERRUPT 0x1000
typedef struct {
LPCITEMIDLIST pidlPath;
BOOL bWatchSubtree;
} NOTIFYREGISTER;
HANDLE (*SHChangeNotifyRegister)(HWND, DWORD, LONG, UINT, DWORD,
NOTIFYREGISTER);
bool (*SHChangeNotifyDeRegister)(HWND);
//-------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TEdit *Edit1;
// void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
void __fastcall DirectoryHasChanged(TMessage &Msg);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_USER, TMessage, DirectoryHasChanged)
END_MESSAGE_MAP(TForm)
};
//-------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//-------------------------------------------------------------------------
#endif
Technical Details
Message-ID:
<1cj24pzpnk6kq.7n0lajrj0cil$.dlg@40tude.net>Path:
arc1-ca.pugleaf.net!archiver1.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-mailReferences:
<gtsccansk388.1njug0ildrjsr$.dlg@40tude.net> <40648199@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,255fcfa7b17a92b2 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-03-26 21:09:25 PST From: Dave <dave_xse@-spam-hotmail.com> Subject: Re: FindFirstChangeNotification - which File(s) was/were changed Newsgroups: borland.public.cppbuilder.nativeapi MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit References: <gtsccansk388.1njug0ildrjsr$.dlg@40tude.net> <40648199@newsgroups.borland.com> Date: Sat, 27 Mar 2004 12:57:59 +0800 Message-ID: <1cj24pzpnk6kq.7n0lajrj0cil$.dlg@40tude.net> User-Agent: 40tude_Dialog/2.0.5.1 NNTP-Posting-Host: 202.72.161.99 X-Trace: newsgroups.borland.com 1080363481 202.72.161.99 (26 Mar 2004 20:58:01 -0800) Lines: 129 Path: arc1-ca.pugleaf.net!archiver1.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