I changed for Delphi 10.3 and its default TOpenDialog contains a preview pane. I made some searches and found the IFileDialogCustomize interface provided by Microsoft to customize standard WinAPI dialogs. I know I have to use the OnSelectionChange event handler to modify the picture of the pane. The big question for me is : how can I access the preview pane image by IFileDialogCustomize? What is the ItemID for this? I couldn't find any answer to this question on the net. Somebody know the answer? Then please share with me and the community! :)
I replaced some code fragments by ... for the sake of brevity, because these are trivial or app dependent sections.
procedure TMainWindow.OnSelectionChange( Sender : TObject );
var
dc : HDC;
aBMP : TBitmap;
function isSelectedFilePreviewAble : boolean;
begin
result := ...;
end;
functon getPreviewPictureDC : HDC;
var
iCustomize : IFileDialogCustomize;
h : THandle;
begin
if OpenDialog1.QueryInterface( IFileDialogCustomize, iCustomize ) = S_OK then
begin
h := iCustomize.??? this is the missing code fragment
result := GetDC( h );
end else
result := 0;
end;
procedure generatePreviewPicture;
begin
...
end;
begin
dc := getPreviewPictureDC;
if ( dc <> 0 ) then
begin
aBMP := TBitmap.Create;
try
if ( isSelectedFilePreviewAble ) then
generatePreviewPicture;
StretchBlt( aBMP.Handle, ...);
finally
aBMP.Free;
ReleaseDC( dc );
end;
end;
end;
First,
IFileDialogCustomizedoes not "customize standard WinAPI dialogs". It customizes onlyIFileOpenDialogandIFileSaveDialogdialogs, no others.Second,
TOpenDialogprimarily uses the legacy Win32 APIGetOpenFileName()function. On Windows Vista+,GetOpenFileName()usesIFileOpenDialoginternally with basic options enabled, so that legacy apps can still have a modern look.Although, under the following conditions,
TOpenDialogwill instead useIFileOpenDialogdirectly rather than usingGetOpenFileName():Win32MajorVersionis >= 6 (Vista+)UseLatestCommonDialogsis TrueStyleServices.Enabledis TrueTOpenDialog.Templateis nilTOpenDialog.OnIncludeItem,TOpenDialog.OnClose, andTOpenDialog.OnShoware unassigned.But even so,
TOpenDialogstill does not give you access to its internalIFileOpenDialoginterface, when it is used.If you really want to access the dialog's
IFileOpenDialogand thus itsIFileDialogCustomize, you need to useTFileOpenDialoginstead ofTOpenDialog(just know that dialog won't work on XP and earlier systems, if you still need to support them).You don't. The preview pane is not a dialog customization, so it can't be accessed via
IFileDialogCustomize. Even if you could get a control ID for the preview pane (which you can't), there is no function ofIFileDialogCustomizethat would allow you to access the preview pane'sHWNDorHDC, or otherwise alter the content of the preview pane in any way. The preview pane is an integral and private component ofIFileDialogfor any file type that supports previews. It is not something that you can access and draw on directly.IFileOpenDialogitself will update the preview pane as needed when the user selects a file that has (or lacks) a preview to display.The correct way to handle that on Vista+ is to create a Preview Handler for your custom file types. Then, any Shell component that wants to display previews of your files, including
IFileOpenDialog, can use your handler.