📄 jvqbrowsefolder.pas
字号:
{******************************************************************************}
{* WARNING: JEDI VCL To CLX Converter generated unit. *}
{* Manual modifications will be lost on next release. *}
{******************************************************************************}
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: JvBrowseFolder.PAS, released on 2001-02-28.
The Initial Developer of the Original Code is S閎astien Buysse [sbuysse att buypin dott com]
Portions created by S閎astien Buysse are Copyright (C) 2001 S閎astien Buysse.
All Rights Reserved.
Contributor(s):
Michael Beck [mbeck att bigfoot dott com]
Roman Kovbasiouk [roko att users dott sourceforge dott net]
Remko Bonte [remkobonte att myrealbox dott com]
You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net
Known Issues:
-----------------------------------------------------------------------------}
// $Id: JvQBrowseFolder.pas,v 1.6 2004/09/07 23:11:15 asnepvangers Exp $
unit JvQBrowseFolder;
{$I jvcl.inc}
{$I windowsonly.inc}
interface
// BCB5 doesn't have the shtypes.h file, so we have to cope with it
(*$HPPEMIT 'namespace shlobj_h'*)
(*$HPPEMIT '{'*)
(*$HPPEMIT '#include <shlobj.h>'*)
(*$HPPEMIT '}'*)
(*$HPPEMIT 'using namespace shlobj_h;'*)
(*$HPPEMIT '#define _ITEMIDLIST shlobj_h::_ITEMIDLIST'*)
uses
Qt, QWindows,
Windows, Messages, Classes, ShlObj,
JvQBaseDlg;
const
{ Interfaces from ShObjIdl.h }
IID_IFolderFilterSite: TGUID = (
D1: $C0A651F5; D2: $B48B; D3: $11D2; D4: ($B5, $ED, $00, $60, $97, $C6, $86, $F6));
SID_IFolderFilterSite = '{C0A651F5-B48B-11d2-B5ED-006097C686F6}';
type
IFolderFilterSite = interface(IUnknown)
[SID_IFolderFilterSite]
function SetFilter(punk: IUnknown): HResult; stdcall;
end;
const
IID_IFolderFilter: TGUID = (
D1: $9CC22886; D2: $DC8E; D3: $11D2; D4: ($B1, $D0, $00, $C0, $4F, $8E, $EB, $3E));
SID_IFolderFilter = '{9CC22886-DC8E-11d2-B1D0-00C04F8EEB3E}';
type
IFolderFilter = interface(IUnknown)
[SID_IFolderFilter]
function ShouldShow(psf: IShellFolder; pidlFolder, pidlItem: PItemIDList): HResult; stdcall;
function GetEnumFlags(psf: IShellFolder; pidlFolder: PItemIDList; const phWnd: HWND;
var pgrfFlags: DWORD): HResult; stdcall;
end;
type
{ (rb) Stupid name, feel free to change :) }
TJvBrowsableObjectClass = (
ocFolders, //SHCONTF_FOLDERS,
ocNonFolders, //SHCONTF_NONFOLDERS,
ocIncludeHidden, //SHCONTF_INCLUDEHIDDEN,
ocInitOnFirstNext, //SHCONTF_INIT_ON_FIRST_NEXT,
ocNetPrinterSrch, //SHCONTF_NETPRINTERSRCH,
ocSharable, //SHCONTF_SHAREABLE,
ocStorage //SHCONTF_STORAGE
);
TJvBrowsableObjectClasses = set of TJvBrowsableObjectClass;
TJvBrowseAcceptChange = procedure(Sender: TObject; const NewFolder: string;
var Accept: Boolean) of object;
TJvShouldShowEvent = procedure(Sender: TObject; const Item: string;
var DoShow: Boolean) of object;
TJvGetEnumFlagsEvent = procedure(Sender: TObject; const AFolder: string;
var Flags: TJvBrowsableObjectClasses) of object;
TJvDirChange = procedure(Sender: TObject; const Directory: string) of object;
TJvValidateFailedEvent = procedure(Sender: TObject; const AEditText: string;
var CanCloseDialog: Boolean) of object;
TFromDirectory = (
fdNoSpecialFolder, { 0 }
fdRootFolder, { 0 }
fdRecycleBin, { CSIDL_BITBUCKET }
fdControlPanel, { CSIDL_CONTROLS }
fdDesktop, { CSIDL_DESKTOP }
fdDesktopDirectory, { CSIDL_DESKTOPDIRECTORY }
fdMyComputer, { CSIDL_DRIVES }
fdFonts, { CSIDL_FONTS }
fdNetHood, { CSIDL_NETHOOD }
fdNetwork, { CSIDL_NETWORK }
fdPersonal, { CSIDL_PERSONAL }
fdPrinters, { CSIDL_PRINTERS }
fdPrograms, { CSIDL_PROGRAMS }
fdRecent, { CSIDL_RECENT }
fdSendTo, { CSIDL_SENDTO }
fdStartMenu, { CSIDL_STARTMENU }
fdStartup, { CSIDL_STARTUP }
fdTemplates, { CSIDL_TEMPLATES }
fdStartUpNonLocalized, { CSIDL_ALTSTARTUP }
fdCommonStartUpNonLocalized, { CSIDL_COMMON_ALTSTARTUP }
fdCommonDocuments, { CSIDL_COMMON_DOCUMENTS }
fdCommonFavorites, { CSIDL_COMMON_FAVORITES }
fdCommonPrograms, { CSIDL_COMMON_PROGRAMS }
fdCommonStartUp, { CSIDL_COMMON_STARTUP }
fdCommonTemplates, { CSIDL_COMMON_TEMPLATES }
fdCookies, { CSIDL_COOKIES }
fdFavorites, { CSIDL_FAVORITES }
fdHistory, { CSIDL_HISTORY }
fdInternet, { CSIDL_INTERNET }
fdMyMusic, { CSIDL_MYMUSIC }
fdPrinthood, { CSIDL_PRINTHOOD }
fdConnections, { CSIDL_CONNECTIONS }
{ Version 4.71 }
fdAppData, { CSIDL_APPDATA }
{ Version 4.72 }
fdInternetCache, { CSIDL_INTERNET_CACHE }
{ Version 5.00 }
fdAdminTools, { CSIDL_ADMINTOOLS }
fdCommonAdminTools, { CSIDL_COMMON_ADMINTOOLS }
fdCommonAppData, { CSIDL_COMMON_APPDATA }
fdLocalAppData, { CSIDL_LOCAL_APPDATA }
fdMyPictures, { CSIDL_MYPICTURES }
fdProfile, { CSIDL_PROFILE }
fdProgramFiles, { CSIDL_PROGRAM_FILES }
fdProgramFilesCommon, { CSIDL_PROGRAM_FILES_COMMON }
fdSystem, { CSIDL_SYSTEM }
fdWindows, { CSIDL_WINDOWS }
{ Version 6.00 }
fdCDBurnArea, { CSIDL_CDBURN_AREA }
fdCommonMusic, { CSIDL_COMMON_MUSIC }
fdCommonPictures, { CSIDL_COMMON_PICTURES }
fdCommonVideo, { CSIDL_COMMON_VIDEO }
fdMyDocuments, { CSIDL_MYDOCUMENTS }
fdMyVideo, { CSIDL_MYVIDEO }
fdProfiles, { CSIDL_PROFILES }
{ Unknown version }
fdResources, { CSIDL_RESOURCES }
fdResourcesLocalized,
fdCommonOEMLinks, { CSIDL_COMMON_OEM_LINKS }
fdComputersNearMe { CSIDL_COMPUTERSNEARME }
);
TJvFolderPos = (fpDefault, fpScreenCenter, fpFormCenter, fpTopLeft,
fpTopRight, fpBottomLeft, fpBottomRight);
TOptionsDirectory = (odBrowseForComputer, odOnlyDirectory, odOnlyPrinters,
odNoBelowDomain, odSystemAncestorsOnly, odFileSystemDirectoryOnly,
odStatusAvailable, odIncludeFiles, odIncludeUrls, odEditBox,
odNewDialogStyle, odShareable, odUsageHint, odNoNewButtonFolder, odValidate);
// (p3) shouldn't TOptionsDir be changed to T(Jv)OptionsDirectories?
TOptionsDir = set of TOptionsDirectory;
TJvBrowseForFolderDialog = class(TJvCommonDialogF, IFolderFilter)
private
// (rom) changed names to Window and type to HWND
{ Handle to the owner form of the dialog, used if Position = fpFormCenter }
FOwnerWindow: HWND;
{ Handle to the MS "Browse for folder" dialog }
FDialogWindow: HWND;
FHelpContext: THelpContext;
FTitle: string;
FOptions: TOptionsDir;
FUsedOptions: TOptionsDir;
FDisplayName: string;
FRootDirectory: TFromDirectory;
FRootDirectoryPath: string;
FDirectory: string;
FPosition: TJvFolderPos;
FPidl: PItemIDList;
FStatusText: string;
FHelpButtonHandle: THandle;
FHelpButtonHeightDelta: Integer;
FOnInit: TNotifyEvent;
FOnChange: TJvDirChange;
FOnAcceptChange: TJvBrowseAcceptChange;
FOnShouldShow: TJvShouldShowEvent;
FOnGetEnumFlags: TJvGetEnumFlagsEvent;
FOnValidateFailed: TJvValidateFailedEvent;
{ For hooking the control }
FDefWndProc: Pointer;
FObjectInstance: Pointer;
FPositionSet: Boolean;
// (p3) updates the status text. NOTE: doesn't work if odNewDialogStyle is true (MS limitation)!!!
procedure UpdateStatusText(AText: string);
procedure WMShowWindow(var Msg: TMessage); message WM_SHOWWINDOW;
procedure WMSize(var Msg: TWMSize); message WM_SIZE;
function GetRootDirectoryPath: string;
function IsRootDirectoryPathStored: Boolean;
procedure SetRootDirectory(const Value: TFromDirectory);
procedure SetRootDirectoryPath(const Value: string);
procedure SetOptions(const Value: TOptionsDir);
protected
{ Messages from the browser }
procedure DoInitialized;
procedure DoIUnknown(const Unknown: IUnknown);
procedure DoSelChanged(IDList: PItemIDList);
function DoValidateFailed(AEditText: PChar): Integer;
function DoValidateFailedW(AEditText: PWideChar): Integer;
function DoShouldShow(const AItem: string): Boolean;
function DoGetEnumFlags(const AFolder: string; var Flags: TJvBrowsableObjectClasses): Boolean;
function GetOwnerWindow: HWND;
procedure MainWndProc(var Msg: TMessage);
procedure HookDialog;
{ IFolderFilter }
function ShouldShow(psf: IShellFolder; pidlFolder, pidlItem: PItemIDList): HResult; stdcall;
function GetEnumFlags(psf: IShellFolder; pidlFolder: PItemIDList; const phWnd: HWND;
var pgrfFlags: DWORD): HResult; stdcall;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure DefaultHandler(var Msg); override;
{ Messages to the browser }
procedure SetSelection(const APath: string); overload;
procedure SetSelection(IDList: PItemIDList); overload;
procedure SetStatusText(const AText: string);
procedure SetStatusTextW(const AText: WideString);
procedure SetOKEnabled(const Value: Boolean);
procedure SetOKText(const AText: string);
procedure SetOKTextW(const AText: WideString);
procedure SetExpanded(const APath: string); overload;
procedure SetExpandedW(const APath: WideString);
procedure SetExpanded(IDList: PItemIDList); overload;
property Pidl: PItemIDList read FPidl;
property Handle: HWND read FDialogWindow;
function Execute: Boolean; override;
published
property Directory: string read FDirectory write FDirectory;
property DisplayName: string read FDisplayName write FDisplayName stored False;
property HelpContext: THelpContext read FHelpContext write FHelpContext default 0;
property Options: TOptionsDir read FOptions write SetOptions default
[odStatusAvailable, odNewDialogStyle];
property Position: TJvFolderPos read FPosition write FPosition default fpScreenCenter;
property RootDirectory: TFromDirectory read FRootDirectory write SetRootDirectory default fdNoSpecialFolder;
property RootDirectoryPath: string read GetRootDirectoryPath write SetRootDirectoryPath
stored IsRootDirectoryPathStored;
property Title: string read FTitle write FTitle;
property StatusText: string read FStatusText write FStatusText;
property OnAcceptChange: TJvBrowseAcceptChange read FOnAcceptChange write FOnAcceptChange;
property OnChange: TJvDirChange read FOnChange write FOnChange;
property OnGetEnumFlags: TJvGetEnumFlagsEvent read FOnGetEnumFlags write FOnGetEnumFlags;
property OnInitialized: TNotifyEvent read FOnInit write FOnInit;
property OnShouldShow: TJvShouldShowEvent read FOnShouldShow write FOnShouldShow;
property OnValidateFailed: TJvValidateFailedEvent read FOnValidateFailed write FOnValidateFailed;
end;
function BrowseForFolder(const ATitle: string; AllowCreate: Boolean;
var ADirectory: string; AHelpContext: THelpContext = 0): Boolean;
function BrowseForComputer(const ATitle: string; AllowCreate: Boolean;
var ADirectory: string; AHelpContext: THelpContext = 0): Boolean;
// (p3) moved from JvFileUtil, deprecated removed
function BrowseDirectory(var AFolderName: string; const DlgText: string;
AHelpContext: THelpContext): Boolean;
// (p3) moved from JvFileUtil, deprecated removed
function BrowseComputer(var AComputerName: string; const DlgText: string;
AHelpContext: THelpContext): Boolean;
implementation
uses
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
SysUtils, ActiveX, QControls, QForms, QConsts,
JclShell,
JvQJCLUtils, JvQJVCLUtils, JvQConsts, JvQResources, JvQTypes;
type
TMessage = Messages.TMessage;
type
TSHGetFolderPathProc = function(hWnd: HWND; CSIDL: Integer; hToken: THandle;
dwFlags: DWORD; pszPath: PAnsiChar): HResult; stdcall;
var
SHGetFolderPathProc: TSHGetFolderPathProc = nil;
const
{ Taken from ShlObj.h & ShObjIdl.h }
BIF_RETURNFSANCESTORS = $0008;
BIF_EDITBOX = $0010; // Add an editbox to the dialog
BIF_VALIDATE = $0020; // insist on valid result (or CANCEL)
BIF_NEWDIALOGSTYLE = $0040; // Use the new dialog layout with the ability to resize
// Caller needs to call OleInitialize() before using this API
BIF_BROWSEINCLUDEURLS = $0080; // Allow URLs to be displayed or entered. (Requires BIF_USENEWUI)
BIF_UAHINT = $0100; // Add a UA hint to the dialog, in place of the edit box.
// May not be combined with BIF_EDITBOX
BIF_NONEWFOLDERBUTTON = $0200; // Do not add the "New Folder" button to the dialog.
// Only applicable with BIF_NEWDIALOGSTYLE.
BIF_BROWSEINCLUDEFILES = $4000; // Browsing for Everything
BIF_SHAREABLE = $8000; // sharable resources displayed (remote shares, requires BIF_USENEWUI)
SHCONTF_INIT_ON_FIRST_NEXT = $0100; // allow EnumObject() to return before validating enum
SHCONTF_NETPRINTERSRCH = $0200; // hint that client is looking for printers
SHCONTF_SHAREABLE = $0400; // hint that client is looking sharable resources (remote shares)
SHCONTF_STORAGE = $0800; // include all items with accessible storage and their ancestors
CSIDL_MYDOCUMENTS = $000C; // logical "My Documents" desktop icon
CSIDL_MYMUSIC = $000D; // "My Music" folder
CSIDL_MYVIDEO = $000E; // "My Videos" folder
CSIDL_LOCAL_APPDATA = $001C; // <user name>\Local Settings\Applicaiton Data (non roaming)
CSIDL_COMMON_APPDATA = $0023; // All Users\Application Data
CSIDL_WINDOWS = $0024; // GetWindowsDirectory()
CSIDL_SYSTEM = $0025; // GetSystemDirectory()
CSIDL_PROGRAM_FILES = $0026; // C:\Program Files
CSIDL_MYPICTURES = $0027; // C:\Program Files\My Pictures
CSIDL_PROFILE = $0028; // USERPROFILE
CSIDL_PROGRAM_FILES_COMMON = $002B; // C:\Program Files\Common
CSIDL_COMMON_TEMPLATES = $002D; // All Users\Templates
CSIDL_COMMON_DOCUMENTS = $002E; // All Users\Documents
CSIDL_COMMON_ADMINTOOLS = $002F; // All Users\Start Menu\Programs\Administrative Tools
CSIDL_ADMINTOOLS = $0030; // <user name>\Start Menu\Programs\Administrative Tools
CSIDL_CONNECTIONS = $0031; // Network and Dial-up Connections
CSIDL_COMMON_MUSIC = $0035; // All Users\My Music
CSIDL_COMMON_PICTURES = $0036; // All Users\My Pictures
CSIDL_COMMON_VIDEO = $0037; // All Users\My Video
CSIDL_RESOURCES = $0038; // Resource Direcotry
CSIDL_RESOURCES_LOCALIZED = $0039; // Localized Resource Direcotry
CSIDL_COMMON_OEM_LINKS = $003A; // Links to All Users OEM specific apps
CSIDL_CDBURN_AREA = $003B; // USERPROFILE\Local Settings\Application Data\Microsoft\CD Burning
CSIDL_COMPUTERSNEARME = $003D; // Computers Near Me (computered from Workgroup membership)
CSIDL_PROFILES = $003E; // ??
BFFM_SETOKTEXT = WM_USER + 105; // Unicode only
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -