1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 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} |
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | 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
本文标题: 《Let them drag and drop files on your program》
本文链接地址: http://h4ck.org.cn/2011/11/let-them-drag-and-drop-files-on-your-program/