Reputation: 908
For example, when I select three images in Windows Explorer and press enter the default image viewer opens and I can browse through the images.
This code works fine for one image but I can't browse throught the images:
ShellExecute(Handle, PChar('open'), PChar(filename), PChar(''), PChar(path), SW_SHOWNORMAL);
I tried it with a semicolon as a filename separator like this:
var
path, filename: string;
filenames: TStringList;
begin
path := IncludeTrailingPathDelimiter(TPath.GetTempPath);
filenames := TStringList.Create;
try
filenames.Delimiter := ';';
ForEachSelectedRecordInGrid(
DragDBGrid1,
procedure begin
filename := Trim(ExtractFileName(DateienQDateiname.AsString));
if (filename <> '') then begin
filename := path + filename;
DateienQDatei.SaveToFile(filename);
filenames.Add(filename);
end;
end
);
if (filenames.Count > 0) then
ShellExecute(Handle, PChar('open'), PChar(filenames.DelimitedText), PChar(''), PChar(path), SW_SHOWNORMAL);
finally
filenames.Free;
end;
end;
The content of filenames.DelimitedText is
C:\Users\completestranger\AppData\Local\Temp\cat.png;C:\Users\completestranger\AppData\Local\Temp\dog.png;C:\Users\completestranger\AppData\Local\Temp\mouse.png
No luck with that.
Any idea?
Upvotes: 0
Views: 562
Reputation: 597916
You can't open multiple files at one time with ShellExecute/Ex()
. You would have to open them individually, and let the Shell/ImageViewer handle them as it sees fit.
Otherwise, you can obtain an IContextMenu
interface representing multiple files (ie, get the IShellFolder
of the parent folder, and then use IShellFolder.GetUIObjectOf()
with an array of relative file ITEMID
s), and then invoke the 'open'
verb via the IContextMenu.InvokeCommand()
method.
See:
Win32 iContextMenu: How to generate context menu for multi-selected items?
Displaying a property sheet for multiple files
Upvotes: 1