unit DemoFrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TDemoForm =
class(TForm)
Edit: TEdit;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
OldEditWindowProc: TWndMethod;
procedure WMDROPFILES(
var Msg: TMessage);
procedure EditWindowProc(
var Message: TMessage);
end;
var
DemoForm: TDemoForm;
implementation
{$R *.dfm}
uses
ShellApi;
procedure TDemoForm.WMDROPFILES(
var Msg: TMessage);
var
pcFileName: PChar;
i, iSize, iFileCount: integer;
s: TStrings;
begin
s := TStringList.Create;
pcFileName := '
';
// to avoid compiler warning message
iFileCount := DragQueryFile(Msg.wParam, $FFFFFFFF, pcFileName, 255);
for i := 0
to Pred(iFileCount)
do
begin
iSize := Succ(DragQueryFile(Msg.wParam, i,
nil, 0));
pcFileName := StrAlloc(iSize);
DragQueryFile(Msg.wParam, i, pcFileName, iSize);
s.Add(pcFileName);
StrDispose(pcFileName);
end;
DragFinish(Msg.wParam);
Edit.Text := s.CommaText;
s.Free;
end;
procedure TDemoForm.EditWindowProc(
var Message: TMessage);
begin
if Message.Msg = WM_DROPFILES
then
WMDROPFILES(
Message);
OldEditWindowProc(
Message);
end;
procedure TDemoForm.FormCreate(Sender: TObject);
begin
OldEditWindowProc := Edit.WindowProc;
Edit.WindowProc := EditWindowProc;
DragAcceptFiles(Edit.Handle, True);
end;
procedure TDemoForm.FormDestroy(Sender: TObject);
begin
Edit.WindowProc := OldEditWindowProc;
DragAcceptFiles(Edit.Handle, False);
end;
end.