unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes,
Graphics, Controls, Forms, Dialogs,
StdCtrls, shellapi; // uses shellapi;
type
TForm1 = class(TForm)
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
private
procedure FinishDropped(var Msg: TMessage);
message WM_DropFiles;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1 : TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
{ UAC权限 使用这三行
ChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD);
ChangeWindowMessageFilter(WM_COPYDATA, MSGFLT_ADD);
ChangeWindowMessageFilter(WM_COPYGLOBALDATA , MSGFLT_ADD);
}
DragAcceptFiles(Handle, True);
end;
procedure TForm1.FinishDropped(var Msg: TMessage);
var
hDrop : THandle;
iFile : Uint;
lpszFile : pchar;
CountOfFiles : integer;
FileIndex : integer;
ReSults : string;
begin
hDrop := Msg.WParam;
getmem(lpszFile, 255);
iFile := $FFFFFFFF;
CountOfFiles := DragQueryFile(hDrop, iFile, lpszFile, 254);
ReSults := '';
for FileIndex := 0 to CountOfFiles - 1 do
begin
iFile := FileIndex;
DragQueryFile(hDrop, iFile, lpszFile, 254);
ReSults := ReSults + #13#10 + lpszFile;
end;
Dispose(lpszFile);
Memo1.Clear;
Memo1.lines.add('你拖放了 ' + IntToStr(CountOfFiles) + '个文件' + ReSults);
DragFinish(hDrop);
end;
end.
Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号
执行时间: 0.23657393455505 seconds