unit DropFileListBox;interface
uses
Windows, Messages, Classes, StdCtrls, ShellApi;
type
TDropFileNotifyEvent = procedure (Sender: TObject;FileNames : TStringList) of object;TDropFileListBox = class(TListBox)
private
FEnabled : Boolean;
FDropFile : TDropFileNotifyEvent;
procedure DropFiles(var Msg : TMessage); message WM_DROPFILES;
procedure SetDropEnabled(bEnabled : Boolean);
public
constructor Create(AOwner : TComponent); override;
published
property OnDropFiles : TDropFileNotifyEvent read FDropFile write FDropFile;
property DropEnabled : Boolean read FEnabled write SetDropEnabled;
end;procedure Register;implementationprocedure Register;
begin
RegisterComponents('SwlmSoft', [TDropFileListBox]);
end;constructor TDropFileListBox.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
FEnabled := true;
end;procedure TDropFileListBox.SetDropEnabled(bEnabled : Boolean);
begin
FEnabled := Enabled;
DragAcceptFiles(Handle, bEnabled);//api
end;procedure TDropFileListBox.DropFiles(var Msg : TMessage);
var
FileNames : TStringList;
FileName : array [0 .. MAX_PATH - 1] of char;
i, nCount : integer;
begin
FileNames := TStringList.Create();
try
nCount := DragQueryFile(Msg.WParam, $FFFFFFFF, @FileName, MAX_PATH);//api
For i := 0 to nCount - 1 do
begin
DragQueryFile(Msg.WParam, i, FileName, MAX_PATH);//api
FileNames.Add(FileName);
end;
if Assigned(FDropFile) then FDropFile(self, FileNames);
finally
DragFinish(Msg.WParam);//api
FileNames.Free();
end;
end;end.
写好上面的组件后并成本注册后,我新建一个应用程序,拖了它放在窗体上,并照它的意思写了下面代码
procedure TForm1.DropFileListBox1DropFiles(Sender: TObject;
FileNames: TStringList);
begin
DropFileListBox1.Items.AddStrings(FileNames);
end;照道理说,只要文件夹拖到它上面放开,应该就会解析出这个文件夹中的所有文件,可是我程序没有预期效果,各位达人帮我解惑一下,谢谢我查了一下,是组件中的nCount为1,这里到底是怎么回事?
uses
Windows, Messages, Classes, StdCtrls, ShellApi;
type
TDropFileNotifyEvent = procedure (Sender: TObject;FileNames : TStringList) of object;TDropFileListBox = class(TListBox)
private
FEnabled : Boolean;
FDropFile : TDropFileNotifyEvent;
procedure DropFiles(var Msg : TMessage); message WM_DROPFILES;
procedure SetDropEnabled(bEnabled : Boolean);
public
constructor Create(AOwner : TComponent); override;
published
property OnDropFiles : TDropFileNotifyEvent read FDropFile write FDropFile;
property DropEnabled : Boolean read FEnabled write SetDropEnabled;
end;procedure Register;implementationprocedure Register;
begin
RegisterComponents('SwlmSoft', [TDropFileListBox]);
end;constructor TDropFileListBox.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
FEnabled := true;
end;procedure TDropFileListBox.SetDropEnabled(bEnabled : Boolean);
begin
FEnabled := Enabled;
DragAcceptFiles(Handle, bEnabled);//api
end;procedure TDropFileListBox.DropFiles(var Msg : TMessage);
var
FileNames : TStringList;
FileName : array [0 .. MAX_PATH - 1] of char;
i, nCount : integer;
begin
FileNames := TStringList.Create();
try
nCount := DragQueryFile(Msg.WParam, $FFFFFFFF, @FileName, MAX_PATH);//api
For i := 0 to nCount - 1 do
begin
DragQueryFile(Msg.WParam, i, FileName, MAX_PATH);//api
FileNames.Add(FileName);
end;
if Assigned(FDropFile) then FDropFile(self, FileNames);
finally
DragFinish(Msg.WParam);//api
FileNames.Free();
end;
end;end.
写好上面的组件后并成本注册后,我新建一个应用程序,拖了它放在窗体上,并照它的意思写了下面代码
procedure TForm1.DropFileListBox1DropFiles(Sender: TObject;
FileNames: TStringList);
begin
DropFileListBox1.Items.AddStrings(FileNames);
end;照道理说,只要文件夹拖到它上面放开,应该就会解析出这个文件夹中的所有文件,可是我程序没有预期效果,各位达人帮我解惑一下,谢谢我查了一下,是组件中的nCount为1,这里到底是怎么回事?
解决方案 »
- 买书(二手的,新的想转让的也行,TCP/IP详解 卷?)
- Delphi ActiveXForm 和网页交互问题
- 关于ParamCount,调试时与直接运动EXE时值不同;
- 请高手帮助帮助我!谢谢了!
- 寻求这样的控件 http://www.queenball.com/hm/a1.gif
- 请问用html help workshop制作的chm文档怎么显示不了图片?
- 请解决了clientdataset的filter中使用like过滤中文单汉字的高手进来解决一下
- 用dbgrid显示查询的结果,希望将某一个域值相同的记录合并成一条显示,如何做?
- 光标移动问题
- delphi2010使用comport控件出现错误
- 如何实现对 某 word 文件的读取,并搜索在该文件中的是否存在某个关键字????分不够可以加!!!!!!!!
- 如何实现对 某 word 文件的读取,并搜索在该文件中的是否存在某个关键字????分不够可以加!!!!!!!!
并沒有递归檢查下級目錄文件的代碼