delphi接收文件拖放  
官方Delphi 学习QQ群: 682628230(三千人)
频道

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.


推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.048013925552368 seconds