# DragQueryFile 函数

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

# 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

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 返回值

hen 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.

Windows 95/98/Me: DragQueryFile is supported by the Microsoft Layer for Unicode. To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.

## Function Information

Minimum DLL Version shell32.dllversion 4.0 or later
Custom Implementation No
Import library shell32.lib
Minimum operating systems Windows NT 3.1, Windows 95
Unicode Implemented as ANSI and Unicode versions.

# 相关拓展

VC实现文件管理器拖拽（Drag-and-Drop）

void DragDemo::OnDropFiles(HDROP hDrop)
{
// 定义一个缓冲区来存放读取的文件名信息
char szFileName[MAX_PATH + 1] = {0};
// 通过设置iFiles参数为0xFFFFFFFF,可以取得当前拖动的文件数量，
// 当设置为0xFFFFFFFF,函数间忽略后面连个参数。
UINT nFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
// 通过循环依次取得拖动文件的File Name信息，并把它添加到ListBox中
for(UINT i=0; i<nFiles; i++)
{
DragQueryFile(hDrop, i, szFileName, MAX_PATH);
}