This project makes it possible to monitor your directories and/or your files. The control will generate an event whenever a file or subdirectory is created, updated or deleted.
If you want to know how you can use this control in a MFC application, then look at the page: How to use an ATL-control with MFC.
I've written this project in Visual C++ 6.0 with ATL 3.0, because you can't use multithreading in Visual Basic.
When set to
true, the monitor will start watching the directories.
True if the monitor is started.
False when it is not started.
ByVal sPathName as String
|Adds a directory for monitoring.|
ByVal sPathName as String
|Removes a directory.|
ByVal sPathName As String,
ByVal nType As Integer
|Notifies the control that a file (|
nType = 1) or a subdirectory (
nType = 0) is changed, deleted or created in the directory
It's recommended that you first add all the directories you want to monitor before you start monitoring, because when the monitor is running, it will always be stopped and started again when you add a new directory.
The control was tested on Windows NT and Windows 98.
The control is written with Visual C++ 6.0 using ATL 3.0. The control was tested with Visual Basic 6.0
These are the resources I've used to create this project:
- PRB: Firing Event in Second Thread Causes IPF or GPF
Because I use multithreading in this control and it's not possible to fire an event from within a thread, I used the following trick to fire the event.
The control is created as a window. I pass a pointer of the control to the thread function where I can use the window handle of the control to send a message. This message will be handled and will fire the event to the container of the control.
class ATL_NO_VTABLE CWatch :
public CComCoClass<CWatch, &CLSID_Watch>,
public IDispatchImpl<IWatch, &IID_IWatch, &LIBID_FILEMONITOR>,
public CProxy_IWatchEvents< CWatch >
m_bStarted = false;
m_hEvent = NULL;
m_hThread = NULL;
LRESULT OnWatchNotify(UINT uMsg, WPARAM wParam,
LPARAM lParam, BOOL &bHandled)
The thread is created as follows in the
m_hThread = CreateThread(NULL, 0, ThreadFunc, (LPVOID) this, 0, &m_dwThreadId);
As you can see, I pass the
this-pointer to the
- 11 May 2000 - fixed a bug in the
- 12 Dec 2000 - The major change is that the thread for monitoring the directories is created only once.
In the past, the thread was recreated when you added or removed a path. Now I use an event to notify the thread. When the thread receives the event, it will automatically refresh the
Check my website for updates.