Delphi接收文件拖放


本文整理自网络,侵删。

  

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ShellAPI, StdCtrls;

type
TForm1 = class(TForm)
    ListBox1: TListBox;
    procedure FormCreate(Sender: TObject);
private
    { Private declarations }
public
    procedure WMDropFile(var msg: TWMDropFiles); message WM_DROPFILES;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
begin

// register form as the recipient of drop files www.delphitop.com

 

{ UAC权限 使用这三行

ChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD);

ChangeWindowMessageFilter(WM_COPYDATA, MSGFLT_ADD);

ChangeWindowMessageFilter(WM_COPYGLOBALDATA , MSGFLT_ADD);

}

DragAcceptFiles(Handle, True);
end;

procedure TForm1.WMDropFile(var msg: TWMDropFiles);
var
FileCount: Cardinal ;
FileName: PChar;
I: Cardinal;
begin
GetMem(FileName, MAX_PATH + 1);
// if index is $FFFFFFFF, return filecount
FileCount := DragQueryFile(msg.Drop, Cardinal(-1), nil, 0);
for I := 0 to FileCount - 1 do begin
    DragQueryFile(msg.Drop, I, FileName, MAX_PATH + 1);
    ListBox1.Items.Add(FileName);
end;

// release memory of files name buffer
DragFinish(msg.Drop);
msg.Result := 0;
end;

end.

相关阅读 >>

Delphi 将label的caption内容竖向显示

Delphi申请和释放内存

扩展 Delphi 线程 使之传递参数.(给匿名线程增加参数)

Delphi 提升进程令牌

Delphi图像二值化

Delphi memo 手动选择txt文本编码并读取

Delphi x秒生成大量垃圾字符

Delphi idhttp造成程序假死的解决办法

Delphi控制程序在任务栏显示与隐藏

Delphi tstringlist 保存txt文本文件最后一行不留空行

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...