Here is one way to do it.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs, imageenview, ieview, ComCtrls;
type
TForm1 = class(TForm)
ImageEnView1: TImageEnView;
StatusBar1: TStatusBar;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
protected
{ Protected declarations }
procedure WMDropFiles(var Message: TWMDropFiles); message WM_DROPFILES;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses ShellAPI, hyieutils, imageenio;
procedure TForm1.FormCreate(Sender: TObject);
begin
{ Activate accepting files from the Windows shell }
DragAcceptFiles(Self.Handle, True);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
{ Deactivate accepting files from the Windows shell }
DragAcceptFiles(Self.Handle, False);
end;
procedure TForm1.WMDropFiles(var Message: TWMDropFiles);
{ Handle dropping files to the form from Windows Explorer }
var
i: Integer;
iFilename: array [0 .. 256] of char;
iNumberOfFiles: Integer;
DropInfo: HDROP;
begin
Screen.Cursor := crHourGlass;
try
try
iNumberOfFiles := DragQueryFile(message.Drop, $FFFFFFFF, nil, 0);
if iNumberOfFiles = 1 then
begin
DragQueryFile(message.Drop, 0, iFilename, SizeOf(iFilename));
if (FileExists(iFilename)) and (IsKnownFormat(iFilename)) then
begin
ImageEnView1.IO.LoadFromFile(iFilename);
ImageEnView1.Proc.ClearAllUndo;
ImageEnView1.Proc.ClearAllRedo;
ImageEnView1.MouseInteract := [];
StatusBar1.Panels[0].Text := ExtractFileDir(iFilename);
StatusBar1.Panels[1].Text := ExtractFileName(iFilename);
end
else
begin
MessageBox(0, 'The file is not supported.', 'Warning',
MB_ICONWARNING or MB_OK);
end;
end
else
MessageBox(0,
'This application only allows dropping one file at a time.',
'Warning', MB_ICONWARNING or MB_OK);
finally
DragFinish(message.Drop);
end;
inherited;
finally
Screen.Cursor := crDefault;
end;
end;
end.
William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html