unit uMyFileOpenDialog;
{ ====> By SMP3 <==== }
interface
uses
System.SysUtils,
System.Classes,
Winapi.Windows,
Winapi.Messages,
Winapi.ShlObj,
Vcl.Dialogs;
type
TMyFileOpenDialogEvents = class(TInterfacedObject, IFileDialogEvents,
IFileDialogControlEvents)
{ IFileDialogEvents Proc }
function OnFileOk(const pfd: IFileDialog): HResult; stdcall;
function OnFolderChanging(const pfd: IFileDialog;
const psiFolder: IShellItem): HResult; stdcall;
function OnFolderChange(const pfd: IFileDialog): HResult; stdcall;
function OnSelectionChange(const pfd: IFileDialog): HResult; stdcall;
function OnShareViolation(const pfd: IFileDialog; const psi: IShellItem;
out pResponse: DWORD): HResult; stdcall;
function OnTypeChange(const pfd: IFileDialog): HResult; stdcall;
function OnOverwrite(const pfd: IFileDialog; const psi: IShellItem;
out pResponse: DWORD): HResult; stdcall;
{ IFileDialogControlEvents Proc }
function OnItemSelected(const pfdc: IFileDialogCustomize; dwIDCtl: DWORD;
dwIDItem: DWORD): HResult; stdcall;
function OnButtonClicked(const pfdc: IFileDialogCustomize; dwIDCtl: DWORD)
: HResult; stdcall;
function OnCheckButtonToggled(const pfdc: IFileDialogCustomize;
dwIDCtl: DWORD; bChecked: BOOL): HResult; stdcall;
function OnControlActivating(const pfdc: IFileDialogCustomize;
dwIDCtl: DWORD): HResult; stdcall;
end;
TMyFileOpenDialog = class(TFileOpenDialog)
private
FDialogEvents: IFileDialogEvents;
FEvents: TMyFileOpenDialogEvents;
FInitDialog: Boolean;
FCookie: DWORD;
protected
function Execute(ParentWnd: HWND): Boolean; overload; virtual;
function GetResults: HResult; virtual;
procedure DoOnExecute; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
implementation
const
D4ABtnID = 1;
{ TMyFileOpenDialog }
constructor TMyFileOpenDialog.Create(AOwner: TComponent);
begin
inherited;
FEvents := nil;
FInitDialog := False;
end;
destructor TMyFileOpenDialog.Destroy;
begin
inherited;
end;
procedure TMyFileOpenDialog.DoOnExecute;
var
MyCustDlg: IFileDialogCustomize;
begin
inherited;
if Dialog.QueryInterface(IFileDialogCustomize, MyCustDlg) = S_OK then
with MyCustDlg do
begin
StartVisualGroup(0, 'My Group');
AddPushButton(D4ABtnID, 'Delphi4Arab');
EndVisualGroup;
MakeProminent(0);
FEvents := TMyFileOpenDialogEvents.Create;
FEvents.QueryInterface(IFileDialogEvents, FDialogEvents);
Dialog.Advise(FDialogEvents, FCookie);
FInitDialog := True;
end;
end;
function TMyFileOpenDialog.Execute(ParentWnd: HWND): Boolean;
begin
inherited;
if FInitDialog then
Dialog.Unadvise(FCookie);
end;
function TMyFileOpenDialog.GetResults: HResult;
begin
inherited;
end;
{ TMyFileOpenDialogEvents }
function TMyFileOpenDialogEvents.OnButtonClicked
(const pfdc: IFileDialogCustomize; dwIDCtl: DWORD): HResult;
begin
if dwIDCtl = D4ABtnID then
begin
// Button Clicked .
ShowMessage('Delphi4Arab');
end;
Result := S_OK;
end;
function TMyFileOpenDialogEvents.OnCheckButtonToggled
(const pfdc: IFileDialogCustomize; dwIDCtl: DWORD; bChecked: BOOL): HResult;
begin
Result := S_OK;
end;
function TMyFileOpenDialogEvents.OnControlActivating
(const pfdc: IFileDialogCustomize; dwIDCtl: DWORD): HResult;
begin
Result := S_OK;
end;
function TMyFileOpenDialogEvents.OnFileOk(const pfd: IFileDialog): HResult;
begin
Result := S_OK;
end;
function TMyFileOpenDialogEvents.OnFolderChange(const pfd: IFileDialog)
: HResult;
begin
Result := S_OK;
end;
function TMyFileOpenDialogEvents.OnFolderChanging(const pfd: IFileDialog;
const psiFolder: IShellItem): HResult;
begin
Result := S_OK;
end;
function TMyFileOpenDialogEvents.OnItemSelected
(const pfdc: IFileDialogCustomize; dwIDCtl, dwIDItem: DWORD): HResult;
begin
Result := S_OK;
end;
function TMyFileOpenDialogEvents.OnOverwrite(const pfd: IFileDialog;
const psi: IShellItem; out pResponse: DWORD): HResult;
begin
Result := S_OK;
end;
function TMyFileOpenDialogEvents.OnSelectionChange
(const pfd: IFileDialog): HResult;
begin
Result := S_OK;
end;
function TMyFileOpenDialogEvents.OnShareViolation(const pfd: IFileDialog;
const psi: IShellItem; out pResponse: DWORD): HResult;
begin
Result := S_OK;
end;
function TMyFileOpenDialogEvents.OnTypeChange(const pfd: IFileDialog): HResult;
begin
Result := S_OK;
end;
end.