问一个难题(50分)

  • 主题发起人 主题发起人 homerocker
  • 开始时间 开始时间
H

homerocker

Unregistered / Unconfirmed
GUEST, unregistred user!
我写了一个程序,form1上有一个panel,我现在的用意是:从我的电脑中拖动一个文件
的图标到这个panel上,然后要求form接收这个拖入文件的文件名,并触发我的事件
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=108049

JJLEI (1999-5-22 10:18:00)
给一个例子,是拖动文件的,不过我想原理是一样的。该例子取自DelphiFaq(从Inprise公司Down来的)
Question:How do I accept files that are dropped on my application?
Answer:
You must interface with the Windows Shell API module to let
Windows know that your application accepts dropped files (this
can be done in your main form's create event), and then you must
respond to the drag events as they happen by creating an event handler.

The following is an example of a Delphi form that accepts dropped
files and adds the names of the files to a memo component:

unit Unit1;

interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
private
procedure WMDROPFILES(var Message: TWMDROPFILES);
message WM_DROPFILES;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

uses ShellApi;

procedure TForm1.FormCreate(Sender: TObject);
begin
{Let Windows know we accept dropped files}
DragAcceptFiles(Form1.Handle, True);
end;

procedure TForm1.WMDROPFILES(var Message: TWMDROPFILES);
var
NumFiles : longint;
i : longint;
buffer : array[0..255] of char;
begin
{How many files are being dropped}
NumFiles := DragQueryFile(Message.Drop,
-1,//-1更改为$FFFFFFFF
nil,
0);
{Accept the dropped files}
for i := 0 to (NumFiles - 1) do begin
DragQueryFile(Message.Drop,
i,
@buffer,
sizeof(buffer));
Form1.Memo1.Lines.Add(buffer);
end;
end;

end.

 
后退
顶部