读书人

listview中的文件拖到资源管理器怎么

发布时间: 2012-09-27 11:11:17 作者: rapoo

listview中的文件拖到资源管理器,如何获取当前资源管理器中文件夹的路径?
listview中的文件拖到资源管理器,如何获取当前资源管理器中文件夹的路径?

[解决办法]

Delphi(Pascal) code
unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls,shellapi;typeTForm1 = class(TForm)    ListBox1: TListBox;    ListBox2: TListBox;    Button1: TButton;    procedure FormCreate(Sender: TObject);private    { Private declarations }public    procedure DragFile(Var Msg : TMessage); Message WM_DropFILES;end;varForm1: TForm1;implementation{$R *.dfm}procedure TForm1.DragFile(var Msg: TMessage);varvFileCount : integer;i : integer;vFileName : string;vWidth : integer;beginvFileCount := DragQueryFile(Msg.WParam,$FFFFFFFF,nil,0);for i := 0 to vFileCount -1 dobegin    SetLength(vfilename,80);    DragQueryFile(Msg.WParam,i,pchar(vFileName),80);    ListBox1.Items.Append(vFileName);end;vWidth := 0;for i := 0 to ListBox1.Count -1 dobegin    if vWidth < ListBox1.Canvas.TextWidth(ListBox1.Items.Strings[i]) then     vWidth := ListBox1.Canvas.TextWidth(ListBox1.Items.Strings[i]);end;SendMessage(ListBox1.Handle,LB_SETHORIZONTALEXTENT,vWidth+50,0);DragFinish(Msg.WParam);end;procedure TForm1.FormCreate(Sender: TObject);beginListBox1.ItemIndex := 0;DragAcceptFiles(ListBox1.Handle,true);end;end. 

读书人网 >.NET

热点推荐