Wanna get notified when a file gets created, renamed or deleted on the system? Need to know the exact folder and file name? Let's start monitoring system shell changes! What a great extension to your "Big Brother" Delphi code toolkit - part 3.

Here we go again ... in the last two episodes of "The Big Brother" Delphi Code Toolkit article series, I've presented to you some code examples (and tricks) to help you hide your Delphi application from the system, disable system hot keys and various Windows shell elements (Start button, Desktop); how to detect and even prevent system shut down...

This time you'll see how to enable your Delphi projects to monitor system shell changes! In other words, you will learn how to enrich your application to be capable of tracking system changes, including file creation, folder creation, file deletion, etc.

Delphi Shell Components - not powerful enough for our task!

A quick overview of something you might think does the job, but does not...
To be able to monitor and track system shell changes we need to search for some shell related Windows API calls. Thanks to Borland Delphi development team, some shell related components ship with Delphi, but unfortunately you will not find them on the component palette?!

Take a quick look at the contents of the $(DELPHI)\Demos\ShellControls folder, you'll find a Delphi package hosting 4 Delphi components: ShellTreeView, ShellComboBox, ShellListView and ShellChangeNotifier. The first three components enable you to write your own Windows Explorer. The fourth component, ShellChangeNotifier, seems to be the one we are looking for.

Note: after you install the package containing those components (vclshlctrls.dpk), the component will be placed on the Samples tab of the component palette.

The TShellChangeNotifier component acts as a wrapper around the SHChangeNotify API function. Unfortunately, when you look for TShellChangeNotifier properties and more importantly the events, you'll find the component is equipped with just one event: OnChange. The OnChange event gets fired whenever some of the selected shell change events specified for the NotifyFilters property occur. Even more, the OnChange event has no shell-change specific parameters like what is the exact name (and location) of the file that, for example, was created somewhere on the system. The only thing you will be notified using this component is that *something* has happened *somewhere* in the monitored folder / subfolder.

This, of course, is not enough for what we want - time to write our own wrapper around the SHChangeNotify API function that gives us the full control over the shell changes - or even better, search the Internet for some ready made component.

Don't leave now, since this article is getting hot on the next page...