Shell Folders Unit
Demo Program ReadMe
Introduction
This project is provided with the DelphiDabbler Shell Folders Unit
to demonstrate how to use some of the code in the unit.
The project was created with Delphi 4 and Delphi 2006 and compiles on all
Win32 Delphis from v4 to 2006.
Installing the Demo Project
The demo project is provided in the same zip file as the Shell Folders
Unit. Ensure the unit's components are installed before trying to
compile this demo. Copy the code from the Demo
subfolder of
the zip drive to some suitable location on your hard drive then open the
ShellFolderDemo.dpr
project in Delphi.
Overview
The demo program exercises much of the main code in
PJShellFolders.pas
. On starting the program displays
information about each of the supported special shell folders in the main
part of the window. This information is:
-
ID: the symbolic constant associated with the folder.
-
Display name: the display name of the folder (or <not supported>
if the folder is not supported by the underlying operating system).
-
Folder path: the path to the folder in the file system. If the folder is
not part of the physical file system, i.e. is virtual, then <virtual
folder> is displayed. No entry is present for unsupported folders.
Below the main display are several controls:
-
Browse selected folder button: Clicking this button displays
the Browse for Folder dialog box with the selected special
folder as the root in the display. Click the button to experiment with
the dialog, the behaviour of which changes according to the state of
some other controls. If the selected folder is not supported by the
operating system the button is disabled. The dialog can also be
displayed by double clicking the folder's entry in the display. Note
that the dialog box is customised with an extra text box that appears
between the tree view and the buttons and displays the symbolic constant
of the folder being browsed.
-
Permit Virtual Folders check box: When checked the Browse
for folder dialog box will display virtual sub folders and these
may be chosen in the dialog box. When the check box is cleared the
Browse for Folder dialog will not display virtual sub-folders,
and they may not be chosen (the OK button will be disabled when
virtual folders are selected). NOTE: The OK button is always
enabled when the Use OnSelChange radio button is checked.
-
New Style Dialog check box: When checke the Browse for
folder dilaog box will display in the "new style". When
using this style the dialog box will not be customised at all
(the customisation code does not allow for the changed size of the
dialog) and no status text will be displayed since this is not supported
by the new style dialog box. However a New Folder button
will be displayed in place of the Help button and the dialog
will be resizeable.
-
Use OnSelChange radio button: When this button is checked the
browse dialog box component uses the OnSelChange event
handler when the selected folder changes. The event handler displays the
name of the selected folder in the dialog's status text and ensures the
OK button is enabled. This event handler does not display
status text when the New Style Dialog check box is checked
since the new style shell folder dialog does not support status text.
-
Use OnSelChangeEx radio button: When this button is checked the
browse dialog box component uses the OnSelChangeEx event
handler when the selected folder changes. The event handler displays the
following information in the dialog's status text: whether the selected
folder is virtual or part of the file system; the folder display name or
path; and the index of the folder's large icon in the system list. In
addition, the large icon associated with the folder is displayed in the
main form. This event handler does not display status text when the
New Style Dialog check box is checked, but the folder icons are
updated.
Source Code
The main purpose of this demo is to examine the source code. The code of the
ShellFolderDemoForm
unit illustrates the following:
-
The DisplaySpecialFolders method (called from
FormCreate) uses the IPJSpecialFolderEnum
interface, implemented by the TPJSpecialFolderEnum class, to
display details of all supported folders in the main window. The code
uses the TPJSpecialFolderInfo component to get the
information to display.
-
The IsSelectionSupported method uses the
TPJSpecialFolderInfo component to test to see if the
currently highlighted folder is supported by the operating system.
-
The BrowseButtonClick event handler sets up the
TPJBrowseDialog component to display the Browse for
Folders dialog using the selected special folder as its root node.
The TPJBrowseDialog.Execute method is called to display the
dialog box. This causes the component's OnInitialise event to fire
– how this is handled is described below.
-
The BrowseDialogInitialise method handles the
TPJBrowseDialog.OnInitialise event and adds an additional
text control to the browse dialog. This text control is used to display
the symbolic constant of the special folder used as root folder in the
dialog. The method does nothing if the dialog box has the new style.
-
As folders are selected in the the browse dialog either the
TPJBrowseDialog.OnSelChange or
TPJBrowseDialog.OnSelChangeEx events are handled by the
BrowseDlgSelChange or BrowseDlgSelChangeEx methods
respectively, according to the state of the Use OnSelChange and
Use OnSelChangeEx radio buttons. These event handlers perform
as follows:
-
BrowseDlgSelChange: This event handler simply
displays the selected folder's display name in the dialog's
status text and ensures the dialog's OK button is
always enabled. Status text is ignored if the dialog box has the
new style.
-
BrowseDlgSelChangeEx: This event handler gets the
display name and path from the PIDL passed to the handler and
displays folder information according to whether the folder is
virtual in the dialog's status text. It then gets the handle of
the icon associated with the folder and displays it in the main
form. Status text is ignored if the dialog has the new style.
-
When the browse dialog is closed, the TPJBrowseDialog.OnClose
event is triggered and handled by the BrowseDlgClose event
handler. This simply ensures that any icon displayed in the main window
is cleared.
Please run the program and examine the source code to get an idea about how
to use the PJShellFolders
unit.