学习 http://www.delphitop.com/html/wenjian/3072.html
unit DropFile_Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ShellAPI, StdCtrls;
type
TForm1 = class(TForm)
Mmo1: TMemo;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
procedure WmDropFiles(var Msg: TMessage); message WM_DROPFILES;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.WmDropFiles(var Msg: TMessage);
var
P:array[0..254] of Char;
i:Word;
str:string;
begin
Inherited;
{$IFDEF WIN32}
i:=DragQueryFile(Msg.wParam,$FFFFFFFF,nil,0);
{$ELSE}
i:=DragQueryFile(Msg.wParam,$FFFF,nil,0);
{$ENDIF}
//Caption:=IntToStr(i);
for i:=0 to i-1 do
begin
DragQueryFile(Msg.wParam,i,P,255);
//Mmo1.Lines.Add(StrPas(P));
end;
Caption := StrPas(P);
str := ExtractFileExt(StrPas(P));
if (str = '.txt') or (str = '.pas') then
begin
Mmo1.Lines.Clear;
Mmo1.Lines.LoadFromFile(StrPas(P));
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
{ UAC权限 使用这三行
ChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD);
ChangeWindowMessageFilter(WM_COPYDATA, MSGFLT_ADD);
ChangeWindowMessageFilter(WM_COPYGLOBALDATA , MSGFLT_ADD);
}
DragAcceptFiles(Form1.Handle, True);
end;
end.