1. Technology

Your suggestion is on its way!

An email with a link to:

http://delphi.about.com/od/kbwinshell/l/aa030403a.htm

was emailed to:

Thanks for sharing About.com with others!

Monitoring System Shell Changes using Delphi
Page 1: Delphi Shell components.
 More of this Feature
• Page 2: Monitoring Shell Changes - the proper way

• Download full source CODE
 Join the Discussion
"Post your views, comments, questions and doubts to this article."
Discuss!
 Related Resources
• Part 1 of this article
• Part 2 of this article
• Windows/Shell/API programming
 Elsewhere on the Web
• Undocumented API calls

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?!

TShellNotify in Object ExpolorerTake 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.

Delphi Shell components

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...

Next page > Delphi Shell Change Monitoring - the proper way! > Page 1, 2, 3

©2014 About.com. All rights reserved.