Unit BrowseFolder |
--------------------------------------------------------------------------------------------------------// TBrowseFolder Component Written by Todd Fast Copyright © 1996-97 by Pencilneck Software. All rights reserved. Version 1.0, lego 9-25-96 Version 2.0, lego 5-7-97 Version 2.1, lego 5-12-97 Version 2.2, lego 6-19-97 Description: Native Delphi component that encapsulates the SHBrowseForFolder interface, which allows Win32 users to select a directory using the standard shell dialog. In addition, TBrowseFolder allows the developer to add a custom button to the dialog. This feature allows you to extend the features of the shell and is found exclusively in this component. Author: Todd Fast Please reach me at one of the following addresses if you have any questions, comments, or contributions. tfast@eden.com pencilneck@hotmail.com http://www.eden.com/~tfast/pencilneck.html Constributors: Alin Flaider aflaidar@datalog.ro 7-4-97 - Multiple instance update Ahto Tanner ahto@moonsoftware.ee http://www.moonsoftware.ee 5-6-97 - Property editor and choice enhancement update 6-19-97 - Support for custom button type (check box) Distribution: This component is freeware. As such, Pencilneck Software gives no warranty to its accuracy, fitness for any particular use, effects of use, or reliability. This component may not be distributed as a part of another component package without Pencilneck Software's written consent. It may be freely distributed, although it must be distributed with all original files in their original format intact. If you use this component in your software, please include an acknowledgment that portions are copyrighted by Pencilneck Software. Please contact the author, Todd Fast, at one of the above addresses with questions, comments, bug-reports or any updates you make to the component. Comments: This component wraps a few of the Win32 shell functions to display the Windows standard folder browse dialog. I originally hacked this component together over the course of a couple of evenings based on Microsoft's sketchy documentation and some of their C header files, and with some contributions and some free time, have since improved it to be the most flexible component of its type available. Hints: - The SetStatusText, SetSelectionPIDL, SetSelectionPath, and EnableOK methods ecapsulate the messages you can send to the browse dialog while it is active (see the Microsoft docs on SHBrowseFolder for more information.) Use these functions from within the TBrowseFolder event handlers to make changes to the browse dialog instead of using SendMessage (although that would be perfectly acceptable, and this file defines all the constants you would need.) - TUse the SHGetFileInfo function to retrieve extended information about the selected folder. You can also use the ImageIndex and DisplayName properties of the component for additional information. - TFor more information, lookup SHBrowseForFolder, BROWSEINFO, and BrowseCallbackProc in the Win32 online help. - TBeware! The Microsoft documentation on these functions shipped with Delphi is not entirely accurate. In most cases, they've reversed the location of certain parameters sent to the callback function or of messages you can send to the browse dialog. Compare my implementation below with the documentation for more information. --------------------------------------------------------------------------------------------------------// Note: Comment this line if you are using Delphi 2 {$DEFINE DELPHI3
Classes |
TBrowseFolder - TBrowseFolder
Functions |
BreakApart - --------------------------------------------------------------------------------------------------------// {Breaks a string into tokens at the specified separator string
BrowserCallbackProc - Callback procedure; must be declared with stdcall since Windows will be calling it
--------------------------------------------------------------------------------------------------------// {Callback procedure; Windows calls this procedure upon certain events in the browse dialog.
CompressString - Utility functions
Utility functions --------------------------------------------------------------------------------------------------------// {Compresses a string by replacing one or more components with the replacement string
CustomWndProc - Custom window procedure that we use to replace the default dialog window procedure.
GetIDListFromPath - --------------------------------------------------------------------------------------------------------// {This procedure compliments SHGetPathFromIDList in the Win32 API, and allows you to obtain a PIDL
from a path string.
Register - Note: The following function is alluded to in the Shlobj.
Types |
TBrowseInfoFlags
TBrowseInfoFlagSet
TBrowserInitializedEvent
TCustomButtonClickEvent
TCustomButtonType
TSelectionChangedEvent
TSHFolders
Constants |
BROWSE_FLAG_ARRAY
NUMBER_OF_BROWSE_INFO_FLAGS
SH_FOLDERS_ARRAY
Variables |
Functions |
--------------------------------------------------------------------------------------------------------// {Callback procedure; Windows calls this procedure upon certain events in the browse dialog. This fucntion calls any defined event handlers for the associated TBrowseFolder instance.
Utility functions --------------------------------------------------------------------------------------------------------// {Compresses a string by replacing one or more components with the replacement string
--------------------------------------------------------------------------------------------------------// {This custom window procedure lets us intercept any messages that the dialog receives and process any messages we need to (like a button click). After doing its own custom processing, it passes the call through to the default dialog procedure.
--------------------------------------------------------------------------------------------------------//
Types |
TBrowseInfoFlags=(bfFileSysDirsOnly,bfDontGoBelowDomain,bfStatusText,bfFileSysAncestors,bfBrowseForComputer,bfBrowseForPrinter);
TBrowseInfoFlagSet=set of TBrowseInfoFlags
TBrowserInitializedEvent=procedure(Sender: TBrowseFolder; DialogHandle: HWND) of objectBrowser notification events
TCustomButtonClickEvent=procedure(Sender: TBrowseFolder; DialogHandle: HWND) of object
TCustomButtonType=(btPushButton, btCheckBox);
TSelectionChangedEvent=procedure(Sender: TBrowseFolder; DialogHandle: HWND; const ItemIDList: PItemIDList; const Directory: String) of object
TSHFolders=(foDesktop,foDesktopExpanded,foPrograms,foControlPanel,foPrinters,foPersonal,foFavorites,foStartup,foRecent, foSendto,foRecycleBin,foStartMenu,foDesktopDirectory,foMyComputer,foNetwork,foNetworkNeighborhood, foFonts,foTemplates);
Constants |
Variables |