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

 在对Windows中我们有时候会通过拖放文件来进行对文件的访问和操作,这个函数用来获得拖放的文件个数和全路径名字。

我们先对窗口添加接受拖放文件的消息WM_DROPFILES,就会生成一个与该消息对应的函数OnDropFiles(HDROP hDropInfo)。我们可以在这个函数内使用DragQueryFile()来获得拖放的文件个数和名字。代码如下:

void CFlipFileDlg::OnDropFiles(HDROP hDropInfo)
{
 char *lpszFileName=new char[512];
 int nCharactersLen;

 nChararctersLen = ::DragQueryFile(hDropInfo,0,NULL,100);
//获得文件名的长度

 ::DragQueryFile(hDropInfo,0,lpszFileName,nChararctersLen+1);
 //把文件名写入数组


 m_FileName = (CString)lpszFileName;
 //m_FileName对应一个文本编辑框的CString类型变量


 delete lpszFileName;
 CDialog::OnDropFiles(hDropInfo);
}

当你进行拖放的时候,以上的代码就可以在相应的文本框中显示文件的全路径名。

OnDropFiles函数介绍:

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

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 Versionshell32.dll version 4.0 or later
Custom ImplementationNo
Headershellapi.h
Import libraryshell32.lib
Minimum operating systemsWindows NT 3.1, Windows 95
UnicodeImplemented as ANSI and Unicode versions.

在MSDN上的相应


 UpdateData(false);
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值