在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1.添加引用ShellAPI。 unit mainForm; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls,StrUtils, WinSkinData, SkinCaption,ShellAPI;//添加ShellAPI引用 type TForm1 = class(TForm) Button1: TButton; OpenDialog1: TOpenDialog; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } procedure DropFiles(var Msg: TMessage); message WM_DROPFILES; end; var Form1: TForm1; implementation {$R *.dfm} { TForm1 } //显示文件路径 procedure TForm1.Button1Click(Sender: TObject); begin if OpenDialog1.Execute then begin ShowMessage('当前文件路径为:'+OpenDialog1.FileName); end; end; //功能同上,显示文件路径 procedure TForm1.DropFiles(var Msg: TMessage); var buffer: array[0..1024] of Char; begin inherited; buffer[0] := #0; DragQueryFile(Msg.WParam, 0, buffer, sizeof(buffer)); //第一个文件 ShowMessage('当前文件路径为:'+buffer); end; //初始化,接受外部拖放 procedure TForm1.FormCreate(Sender: TObject); begin DragAcceptFiles(Handle,True);//第二个参数为False时,不启用文件拖放 end; end.
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论