1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Panel1: TPanel;
procedure FormDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure FormCreate(Sender: TObject);
private
{ Déclarations privées }
OriginalFormWindowProc : TWndMethod;
public
{ Déclarations publiques }
procedure FormWindowProc(var Msg : TMessage);
procedure FormFileDrop(var Msg: TWMDROPFILES) ;
end;
var
Form1: TForm1;
implementation
Uses ShellApi;
{$R *.dfm}
procedure TForm1.FormWindowProc(var Msg : TMessage);
var
Fn : Array [0..255] of Char;
begin
if Msg.Msg = WM_DROPFILES then
FormFileDrop(TWMDROPFILES(Msg))
else
OriginalFormWindowProc(Msg);
end;
procedure TForm1.FormDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept := True;
end;
procedure TForm1.FormFileDrop(var Msg: TWMDROPFILES) ;
var
numFiles : longInt;
buffer : array[0..MAX_PATH] of char;
begin
numFiles := DragQueryFile(Msg.Drop, $FFFFFFFF, nil, 0) ;
if numFiles > 1 then
begin
ShowMessage('You can drop only one image file at a time!') ;
end
else
begin
DragQueryFile(Msg.Drop, 0, @buffer, sizeof(buffer)) ;
Form1.Caption := Buffer ;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
OriginalFormWindowProc := Form1.WindowProc;
Form1.WindowProc := FormWindowProc;
DragAcceptFiles(Form1.Handle,true) ;
end;
end. |
Partager