Let them drag and drop files on your program

unit dropfile;
 interface
 uses
   Windows, Messages, SysUtils, Classes,
   Graphics, Controls, Forms, Dialogs;
 type
   TForm1 = class(TForm)
     procedure FormCreate(Sender: TObject);
   private
     { Private declarations }
   public
     { Public declarations }
     // declare our DROPFILES message handler
     procedure AcceptFiles( var msg : TMessage );
     message WM_DROPFILES;
   end;
 var
   Form1: TForm1;
 implementation
 uses
   // this unit contains certain functions that we'll be using
   ShellAPI;
 {$R *.DFM}

 procedure TForm1.AcceptFiles( var msg : TMessage );
 const
   cnMaxFileNameLen = 255;
 var
   i,
   nCount     : integer;
   acFileName : array [0..cnMaxFileNameLen] of char;
 begin
   // find out how many files we're accepting
   nCount := DragQueryFile( msg.WParam,
                            $FFFFFFFF,
                            acFileName,
                            cnMaxFileNameLen );
   // query Windows one at a time for the file name
   for i := 0 to nCount-1 do
   begin
     DragQueryFile( msg.WParam, i,
                    acFileName, cnMaxFileNameLen );
     // do your thing with the acFileName
     MessageBox( Handle, acFileName, '', MB_OK );
   end;
   // let Windows know that you're done
   DragFinish( msg.WParam );
 end;
 procedure TForm1.FormCreate(Sender: TObject);
 begin
   // tell Windows that you're accepting drag and drop files
   DragAcceptFiles( Handle, True );
   //< <<
 end;
 end.

link:http://www.chami.com/tips/delphi/111196D.html

☆版权☆

* 网站名称:obaby@mars
* 网址:https://oba.by/
* 个性:https://oba.by/
* 本文标题: 《Let them drag and drop files on your program》
* 本文链接:https://oba.by/2011/11/3291
* 短链接:https://oba.by/?p=3291
* 转载文章请标明文章来源,原文标题以及原文链接。请遵从 《署名-非商业性使用-相同方式共享 2.5 中国大陆 (CC BY-NC-SA 2.5 CN) 》许可协议。


You may also like

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注