Use shellapi;
procedure TForm1.FormCreate(Sender: TObject);
begin
DragAcceptFiles(form1.Handle,true);
end;
procedure TForm1.TFfile(var Msg:TMessage);
var
buffer:array[0..1024] of Char;
mouse:TPoint;
mouse_in_memo:Boolean;
begin
GetCursorPos(mouse);
mouse:=ScreenToClient(mouse);
if (mouse.Y <= (shape1.Top+shape1.Height))and(mouse.Y >= shape1.Top)and(mouse.x <= (shape1.left+shape1.width))and(mouse.x>= shape1.left) then
mouse_in_memo:=true
else
mouse_in_memo:=false;
if mouse_in_memo=true then
begin
inherited;
buffer[0]:=#0;
DragQueryFile(Msg.WParam,0,buffer,sizeof(buffer)); //获取拖入文件名称
label1.Caption:=PChar(@buffer);//字符数组转换成字符串
edit1.Text:=PChar(@buffer);
end;
end;
标签:文件,begin,end,buffer,true,memo,mouse,拖放 From: https://www.cnblogs.com/sixty-five/p/17298309.html