DragQueryFile Function

Retrieves the names of dropped files that result from a successful drag-and-drop operation.

Syntax

UINT DragQueryFile(      
    HDROP hDrop,
    UINT iFile,
    LPTSTR lpszFile,
    UINT cch
);

Parameters

hDrop
Identifier of the structure containing the file names of the dropped files.
iFile
Index of the file to query. If the value of the iFile parameter is 0xFFFFFFFF, DragQueryFile returns a count of the files dropped. If the value of the iFile parameter is between zero and the total number of files dropped, DragQueryFile copies the file name with the corresponding value to the buffer pointed to by the lpszFile parameter.
lpszFile
The address of a buffer to receive the file name of a dropped file when the function returns. This file name is a null-terminated string. If this parameter is NULL, DragQueryFile returns the required size, in characters, of the buffer.
cch
Size, in characters, of the lpszFile buffer.

Return Value

When the function copies a file name to the buffer, the return value is a count of the characters copied, not including the terminating null character.

If the index value is 0xFFFFFFFF, the return value is a count of the dropped files. Note that the index variable itself returns unchanged, and will therefore remain 0xFFFFFFFF.

If the index value is between zero and the total number of dropped files and the lpszFile buffer address is NULL, the return value is the required size, in characters, of the buffer, not including the terminating null character.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Delphi中,要实现拖拽文件夹并获取其路径,可以按照以下步骤进行操作: 1. 添加控件:在窗体上添加一个TListBox控件用于显示拖拽的文件夹路径。 2. 设置TListBox为可接受拖拽文件:在TForm的OnCreate事件中添加以下代码,将TListBox的DragMode属性设置为dmAutomatic,使其可以接受文件拖拽操作。 ``` procedure TForm1.FormCreate(Sender: TObject); begin ListBox1.DragMode := dmAutomatic; end; ``` 3. 处理拖拽事件:在TListBox的OnDragDrop事件中添加以下代码,用于处理拖拽文件夹的操作。 ``` procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer); var i: Integer; DropFiles: TStrings; begin DropFiles := TStringList.Create; try if Source is TListBox then begin DropFiles.AddStrings(TListBox(Source).Items); for i := 0 to DropFiles.Count - 1 do ListBox1.Items.Add(DropFiles[i]); end; finally DropFiles.Free; end; end; ``` 4. 显示文件夹路径:在TListBox的OnDragOver事件中添加以下代码,用于在拖拽过程中显示文件夹路径。 ``` procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); begin Accept := Source is TListBox; if Accept then begin if State = dsDragEnter then ListBox1.Items.Clear; ListBox1.Items.Add(GetDroppedFileName); end; end; ``` 5. 获取文件夹路径:最后,我们还需要添加一个函数GetDroppedFileName,用于获取文件夹路径。 ``` function TForm1.GetDroppedFileName: string; var DropHandle: THandle; FileCount, i: Integer; FileName: array[0..MAX_PATH] of Char; begin Result := ''; DropHandle := DragQueryFile(DragQueryFile(DragQueryFile(DragQueryFile(Handle, Cardinal(-1), nil, 0), 0, nil, 0), 0, @FileName[0], Length(FileName)), 0, nil, 0); if DropHandle <> Cardinal(-1) then begin FileCount := DragQueryFile(Handle, DragHandle, nil, 0); if FileCount > 0 then begin DragQueryFile(DragHandle, 0, @FileName[0], Length(FileName)); Result := FileName; end; end; DragFinish(DragHandle); end; ``` 以上就是在Delphi中使用拖拽操作获取文件夹路径的步骤和代码。希望能对您有所帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值