A
amourz
Unregistered / Unconfirmed
GUEST, unregistred user!
我用下面的代码,发现只能把文件拖放到根下,好像根本无法取得子节点,哪位大侠能解决这个
问题?100分送上.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls,shellapi;
type
TForm1 = class(TForm)
TreeView1: TTreeView;
procedure FormCreate(Sender: TObject);
procedure TreeView1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
private
{ Private declarations }
procedure WMDropFiles(VAR Msg: TWMDropFiles);message WM_DROPFILES;
procedure AppOnMessage(VAR Msg: TMsg;VAR Handled : Boolean);
public
{ Public declarations }
end;
var
Form1: TForm1;
s:string;
CurrentNode:TTreeNode;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
DragAcceptFiles(Handle, True);
DragAcceptFiles(Application.Handle, True);
Application.OnMessage := AppOnMessage;
end;
procedure TForm1.WMDropFiles(VAR Msg: TWMDropFiles);
VAR
N : Word;
buffer : ARRAY[0..180] OF Char;
BEGIN
WITH Msg DO
BEGIN
FOR N := 0 TO DragQueryFile(Drop, $FFFFFFFF, buffer,1)-1 DO
BEGIN
DragQueryFile(Drop, N, Buffer, 80);
s:=StrPas(Buffer);
TreeView1.Items.AddChild(CurrentNode,s);
END;
DragFinish(Drop);
END;
END;
procedure TForm1.AppOnMessage(VAR Msg: TMsg;
VAR Handled : Boolean);
VAR WMD : TWMDropFiles;
BEGIN
IF Msg.message = WM_DROPFILES then
BEGIN
WMD.Msg := Msg.message;
WMD.Drop := Msg.wParam;
WMD.Unused := Msg.lParam;
WMD.Result := 0;
WMDropFiles(WMD);
Handled := TRUE;
END;
END;
procedure TForm1.TreeView1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
CurrentNode:=TreeView1.GetNodeAt(x,y);
end;
end.
问题?100分送上.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls,shellapi;
type
TForm1 = class(TForm)
TreeView1: TTreeView;
procedure FormCreate(Sender: TObject);
procedure TreeView1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
private
{ Private declarations }
procedure WMDropFiles(VAR Msg: TWMDropFiles);message WM_DROPFILES;
procedure AppOnMessage(VAR Msg: TMsg;VAR Handled : Boolean);
public
{ Public declarations }
end;
var
Form1: TForm1;
s:string;
CurrentNode:TTreeNode;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
DragAcceptFiles(Handle, True);
DragAcceptFiles(Application.Handle, True);
Application.OnMessage := AppOnMessage;
end;
procedure TForm1.WMDropFiles(VAR Msg: TWMDropFiles);
VAR
N : Word;
buffer : ARRAY[0..180] OF Char;
BEGIN
WITH Msg DO
BEGIN
FOR N := 0 TO DragQueryFile(Drop, $FFFFFFFF, buffer,1)-1 DO
BEGIN
DragQueryFile(Drop, N, Buffer, 80);
s:=StrPas(Buffer);
TreeView1.Items.AddChild(CurrentNode,s);
END;
DragFinish(Drop);
END;
END;
procedure TForm1.AppOnMessage(VAR Msg: TMsg;
VAR Handled : Boolean);
VAR WMD : TWMDropFiles;
BEGIN
IF Msg.message = WM_DROPFILES then
BEGIN
WMD.Msg := Msg.message;
WMD.Drop := Msg.wParam;
WMD.Unused := Msg.lParam;
WMD.Result := 0;
WMDropFiles(WMD);
Handled := TRUE;
END;
END;
procedure TForm1.TreeView1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
CurrentNode:=TreeView1.GetNodeAt(x,y);
end;
end.