procedure TForm1.DropFiles(var Message: TMessage); var i: Integer; p: array[0..254] of Char; begin i := DragQueryFile(Message.wParam, $FFFFFFFF, nil, 0); for i := 0 to i - 1 do begin DragQueryFile(Message.wParam, i, p, 255); ShowMessage(StrPas(p)); end; end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,shellapi;type
TForm1 = class(TForm)
ListBox1: TListBox;
ListBox2: TListBox;
Button1: TButton;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
procedure DragFile(Var Msg : TMessage); Message WM_DropFILES;
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.DragFile(var Msg: TMessage);
var
vFileCount : integer;
i : integer;
vFileName : string;
vWidth : integer;
begin
vFileCount := DragQueryFile(Msg.WParam,$FFFFFFFF,nil,0);
for i := 0 to vFileCount -1 do
begin
SetLength(vfilename,80);
DragQueryFile(Msg.WParam,i,pchar(vFileName),80);
ListBox1.Items.Append(vFileName);
end;vWidth := 0;
for i := 0 to ListBox1.Count -1 do
begin
if vWidth < ListBox1.Canvas.TextWidth(ListBox1.Items.Strings[i]) then
vWidth := ListBox1.Canvas.TextWidth(ListBox1.Items.Strings[i]);
end;
SendMessage(ListBox1.Handle,LB_SETHORIZONTALEXTENT,vWidth+50,0);
DragFinish(Msg.WParam);
end;procedure TForm1.FormCreate(Sender: TObject);
begin
ListBox1.ItemIndex := 0;
DragAcceptFiles(ListBox1.Handle,true);
end;end.
上周沒事做,寫的。你參考下
A拖入B, A告知B拖入的内容或信息,B只是接收方只回应是否能接收,不提供具体的路径什么的信息
procedure TForm1.DropFiles(var Message: TMessage);
var
i: Integer;
p: array[0..254] of Char;
begin
i := DragQueryFile(Message.wParam, $FFFFFFFF, nil, 0);
for i := 0 to i - 1 do begin
DragQueryFile(Message.wParam, i, p, 255);
ShowMessage(StrPas(p));
end;
end;