delphi从外部拖拽文件  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi从外部拖拽文件


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