给一个例子,是拖动文件的,不过我想原理是一样的。该例子取自DelphiFaq(从Inprise公司Down来的)<br>Question:How do I accept files that are dropped on my application?<br>Answer:<br> You must interface with the Windows Shell API module to let<br>Windows know that your application accepts dropped files (this<br>can be done in your main form's create event), and then you must<br>respond to the drag events as they happen by creating an event handler.<br><br>The following is an example of a Delphi form that accepts dropped<br>files and adds the names of the files to a memo component:<br><br>unit Unit1;<br><br>interface<br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Memo1: TMemo;<br> procedure FormCreate(Sender: TObject);<br> private<br> procedure WMDROPFILES(var Message: TWMDROPFILES);<br> message WM_DROPFILES;<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br> var<br> Form1: TForm1;<br><br> implementation<br><br> {$R *.DFM}<br><br> uses ShellApi;<br><br> procedure TForm1.FormCreate(Sender: TObject);<br> begin<br> {Let Windows know we accept dropped files}<br> DragAcceptFiles(Form1.Handle, True);<br> end;<br><br> procedure TForm1.WMDROPFILES(var Message: TWMDROPFILES);<br> var<br> NumFiles : longint;<br> i : longint;<br> buffer : array[0..255] of char;<br> begin<br> {How many files are being dropped}<br> NumFiles := DragQueryFile(Message.Drop,<br> -1,<br> nil,<br> 0);<br> {Accept the dropped files}<br> for i := 0 to (NumFiles - 1) do begin<br> DragQueryFile(Message.Drop,<br> i,<br> @buffer,<br> sizeof(buffer));<br> Form1.Memo1.Lines.Add(buffer);<br> end;<br> end;<br><br> end.