Do you want to drag from Windows File Explorer or Windows Internet Explorer? For the latter you need a third-party drag and drop component such as Raize Drag and Drop. For the former you need to Set DragAcceptFiles to true and then handle the WMDROPFILES event to obtain the dropped filenames.
Drag From Windows File Explorer
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.ExtCtrls, hyieutils, iexBitmaps, hyiedefs, iesettings, imageenview,
ieview, iemview, Vcl.ComCtrls;
type
TForm1 = class(TForm)
ImageEnMView1: TImageEnMView;
ImageEnView1: TImageEnView;
Splitter1: TSplitter;
StatusBar1: TStatusBar;
procedure FormCreate(Sender: TObject);
procedure ImageEnMView1ImageSelect(Sender: TObject; idx: Integer);
private
{ Private declarations }
AFilePath: string;
AFilename: string;
procedure WMDROPFILES(var Message: TWMDropFiles); message WM_DROPFILES;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses Winapi.ShlObj, Winapi.ShellAPI;
procedure TForm1.FormCreate(Sender: TObject);
begin
{ Accept dragged files - this is important }
DragAcceptFiles(Handle, True);
ImageEnMView1.SetModernStyling(False, 200, 150);
ImageEnView1.Blank;
end;
procedure TForm1.ImageEnMView1ImageSelect(Sender: TObject; idx: Integer);
var
iBitDepth: Integer;
iColors: string;
begin
ImageEnMView1.CopyToIEBitmap(idx, ImageEnView1.IEBitmap);
ImageEnView1.IO.Params.Assign(ImageEnMView1.MIO.Params[idx]);
ImageEnView1.Update;
StatusBar1.Panels[0].Text :=
ExtractFileDir(ImageEnMView1.MIO.Params[idx].FileName);
StatusBar1.Panels[1].Text :=
ExtractFileName(ImageEnMView1.MIO.Params[idx].FileName);
StatusBar1.Panels[3].Text := 'Frame: ' + IntToStr(idx + 1);
StatusBar1.Panels[4].Text := IntToStr(ImageEnMView1.MIO.Params[idx].Width) +
' x ' + IntToStr(ImageEnMView1.MIO.Params[idx].Height);
iBitDepth := ImageEnMView1.MIO.Params[idx].BitsPerSample *
ImageEnMView1.MIO.Params[idx].SamplesPerPixel;
if iBitDepth = 32 then
iColors := 'RGBA' + IntToStr(iBitDepth) + '-Bit'
else
iColors := 'RGB' + IntToStr(iBitDepth) + '-Bit';
StatusBar1.Panels[5].Text := iColors;
end;
procedure TForm1.WMDROPFILES(var Message: TWMDropFiles);
{ Handle opening files from Windows File Explorer Drag & Drop. }
const
iMaxLength = 255;
var
i: Integer;
iFileCount: Integer;
iDroppedFileName: array [0 .. MAX_PATH] of Char;
iDroppedFilePath: string;
iFileName: string;
iFrameCount: Integer;
iIndex: Integer;
iBitDepth: Integer;
iColors: string;
begin
inherited;
iFileCount := DragQueryFile(message.Drop, $FFFFFFFF, nil, 0);
if iFileCount = 1 then
begin { Single file dropped }
DragQueryFile(Message.Drop, 0, iDroppedFileName, MAX_PATH);
iDroppedFilePath := iDroppedFileName;
if FileExists(iDroppedFilePath) then
begin
iFrameCount := IEGetFileFramesCount(iDroppedFilePath);
if iFrameCount = 1 then
begin
{ Single frame file }
AFilePath := iDroppedFilePath;
AFilename := ExtractFileName(iDroppedFilePath);
iIndex := ImageEnMView1.AppendImage(AFilePath);
ImageEnMView1.ImageBottomText[iIndex] := AFilename;
ImageEnMView1.ImageInfoText[iIndex] :=
IntToStr(ImageEnMView1.MIO.Params[iIndex].Width) + ' x ' +
IntToStr(ImageEnMView1.MIO.Params[iIndex].Height);
ImageEnMView1.SelectedImage := iIndex;
StatusBar1.Panels[0].Text :=
ExtractFileDir(ImageEnMView1.MIO.Params[iIndex].FileName);
StatusBar1.Panels[1].Text := AFilename;
StatusBar1.Panels[2].Text := 'Frames: ' + IntToStr(iFrameCount);
StatusBar1.Panels[3].Text := 'Frame: ' + IntToStr(iIndex + 1);
StatusBar1.Panels[4].Text :=
IntToStr(ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].Width) + ' x ' +
IntToStr(ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].Height);
iBitDepth := ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].BitsPerSample *
ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].SamplesPerPixel;
if iBitDepth = 32 then
iColors := 'RGBA' + IntToStr(iBitDepth) + '-Bit'
else
iColors := 'RGB' + IntToStr(iBitDepth) + '-Bit';
StatusBar1.Panels[5].Text := iColors;
end
else
begin
{ Multiple frame file }
ImageEnMView1.Clear;
iFileName := iDroppedFilePath;
for i := 0 to iFrameCount - 1 do
begin
ImageEnMView1.AppendImage(iFileName + IEM_Path_Index_Delimiter +
IntToStr(i));
ImageEnMView1.ImageBottomText[i] := ExtractFileName(iFileName);
ImageEnMView1.ImageInfoText[i] := 'Frame: ' + IntToStr(i + 1);
end;
ImageEnMView1.SelectedImage := 0;
StatusBar1.Panels[0].Text :=
ExtractFileDir(ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage]
.FileName);
StatusBar1.Panels[1].Text := ExtractFileName(iFileName);
StatusBar1.Panels[2].Text := 'Frames: ' + IntToStr(iFrameCount);
StatusBar1.Panels[3].Text := 'Frame: ' + IntToStr(ImageEnMView1.SelectedImage + 1);
StatusBar1.Panels[4].Text :=
IntToStr(ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].Width) + ' x ' +
IntToStr(ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].Height);
iBitDepth := ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].BitsPerSample *
ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].SamplesPerPixel;
if iBitDepth = 32 then
iColors := 'RGBA' + IntToStr(iBitDepth) + '-Bit'
else
iColors := 'RGB' + IntToStr(iBitDepth) + '-Bit';
StatusBar1.Panels[5].Text := iColors;
end;
end;
end
else { Multiple files dropped }
begin
for i := 0 to iFileCount - 1 do
begin
{ Get filenames dropped }
DragQueryFile(Message.Drop, i, iDroppedFileName, iMaxLength);
iFileName := iDroppedFileName;
ImageEnMView1.InsertImage(i, iFileName);
ImageEnMView1.ImageBottomText[i] := ExtractFileName(iFileName);
ImageEnMView1.ImageInfoText[i] :=
IntToStr(ImageEnMView1.MIO.Params[i].Width) + ' x ' +
IntToStr(ImageEnMView1.MIO.Params[i].Height);
end;
ImageEnMView1.SelectedImage := 0;
StatusBar1.Panels[0].Text :=
ExtractFileDir(ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage]
.FileName);
StatusBar1.Panels[1].Text :=
ExtractFileName(ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage]
.FileName);
StatusBar1.Panels[2].Text := 'Frames: ' + IntToStr(ImageEnMView1.ImageCount);
StatusBar1.Panels[3].Text := 'Frame: ' + IntToStr(ImageEnMView1.SelectedImage + 1);
StatusBar1.Panels[4].Text := IntToStr(ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].Width) +
' x ' + IntToStr(ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].Height);
iBitDepth := ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].BitsPerSample *
ImageEnMView1.MIO.Params[ImageEnMView1.SelectedImage].SamplesPerPixel;
if iBitDepth = 32 then
iColors := 'RGBA' + IntToStr(iBitDepth) + '-Bit'
else
iColors := 'RGB' + IntToStr(iBitDepth) + '-Bit';
StatusBar1.Panels[5].Text := iColors;
end;
end;
end.
Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development