王朝百科
分享
 
 
 

DragQueryFile

王朝百科·作者佚名  2010-06-18  
宽屏版  字体: |||超大  

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

用于一个成功文件拖拽后获取文件名称。

Syntax 语法UINT DragQueryFile(

HDROPhDrop,

UINTiFile,

LPTSTRlpszFile,

UINTcch

);

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 theiFileparameter is 0xFFFFFFFF,DragQueryFilereturns a count of the files dropped. If the value of theiFileparameter is between zero and the total number of files dropped,DragQueryFilecopies the file name with the corresponding value to the buffer pointed to by thelpszFileparameter.

文件索引编号(用于指明所要查询文件的序号, 如果拖进多个文件,则索引编号从零开始),如果iFile值为 0xFFFFFFFF 时,返回的是拖曳到窗体上的文件的个数。如果iFile值在0和拖拽文件总数之间时,DragQueryFile拷贝与文件名存储缓冲区大小适应的文件名称到缓冲区中。

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,DragQueryFilereturns the required size, in characters, of the buffer.

函数返回时,用于存储拖拽文件名称的缓冲区指针。文件名称是一个以空终止“”结尾的字符串。如果此参数是NULL,DragQueryFile函数返回拖拽的文件数目。函数DragQueryFile得到的文件名,是带完整路径的文件名。

cch

Size, in characters, of thelpszFilebuffer.

存储拖拽文件名称缓冲区的大小,即lpszFile指针所指缓冲区的字符数。

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.

如果函数拷贝文件名称到缓冲区中,返回值就是拷贝的字符数,不包括终止的NULL字符。

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.

如果文件索引值是0xFFFFFFFF,则返回值是被拖拽的文件总数,注意文件索引变量的值将保持不变,依然为0xFFFFFFFF。

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

如果文件索引值在0和拖拽文件总数之间时,并且lpszFile值为NULL时,返回值是存储此被拖拽文件的名称所需要的缓冲区大小值,此值是不包括终止NULL字符的字符数。

Windows 95/98/Me:DragQueryFileis 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.dll version 4.0 or later

Custom Implementation

No

Header

shellapi.h

Import library

shell32.lib

Minimum operating systems

Windows NT 3.1, Windows 95

Unicode

Implemented as ANSI and Unicode versions.

相关拓展VC实现文件管理器拖拽(Drag-and-Drop)

在日常的程序中,为了操作的方便,经常需要使用鼠标拖拽的方式把文件管理器中的文件拖拽到我们自己写的程序中,以下就简单介绍以下实现该操作的方法。

其实文件管理器的拖拽方式实现起来很简单,主要通过几个函数来实现,消息WM_DROPFILES的响应函数OnDropFiles,还有三个API函数:DragQueryFile,DragQueryPoint和DragFinish。 在启动拖拽动作时,操作系统会分配一块内存存储拖拽的文件的信息,并通过一个HDROP类型的句柄把该块内存的地址传递给函数OnDropFiles函数。

文件管理器拖拽方式的实质就是处理WM_DROPFILES消息,要让窗口或控件响应该消息,需要先设置Accept Files属性,可以通过在窗口或控件的属性页中勾选Accept Files,也可以通过调用CWnd类的成员函数DragAcceptFiles(TRUE)或API函数DragAcceptFiles(HWND hWnd,BOOL fAccept),可以在OnCreate或OnInitDialog之类的函数中调用,它们的效果都是一样的。

设置了Accept Files属性后,就可以添加WM_DROPFILES消息的响应函数OnDropFiles了,ClassWizard不支持该函数,所以需要手动添加此函数,然后在该函数中调用上述的三个API函数,其代码如下:

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);

m_listCtrl.AddString(szFileName);

}

// 结束此次拖拽操作,并释放分配的资源

DragFinish(hDrop);

}

其中三个API函数的具体用法可以参照MSDN。由于本例的操作是直接拖拽的对话框上,所以不需要通过DragQueryPoint来取得鼠标松开时的位置,在实际的实现中,最好是为空间派生出一个类,在该类中定义消息响应函数OnDropFiles,这样就不需要查询鼠标的位置,也不需要设置鼠标的指针样式。

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
如何用java替换看不见的字符比如零宽空格&#8203;十六进制U+200B
 干货   2023-09-10
网页字号不能单数吗,网页字体大小为什么一般都是偶数
 干货   2023-09-06
java.lang.ArrayIndexOutOfBoundsException: 4096
 干货   2023-09-06
Noto Sans CJK SC字体下载地址
 干货   2023-08-30
window.navigator和navigator的区别是什么?
 干货   2023-08-23
js获取referer、useragent、浏览器语言
 干货   2023-08-23
oscache遇到404时会不会缓存?
 干货   2023-08-23
linux下用rm -rf *删除大量文件太慢怎么解决?
 干货   2023-08-08
刀郎新歌破世界纪录!
 娱乐   2023-08-01
js实现放大缩小页面
 干货   2023-07-31
生成式人工智能服务管理暂行办法
 百态   2023-07-31
英语学习:过去完成时The Past Perfect Tense举例说明
 干货   2023-07-31
Mysql常用sql命令语句整理
 干货   2023-07-30
科学家复活了46000年前的虫子
 探索   2023-07-29
英语学习:过去进行时The Past Continuous Tense举例说明
 干货   2023-07-28
meta name="applicable-device"告知页面适合哪种终端设备:PC端、移动端还是自适应
 干货   2023-07-28
只用css如何实现打字机特效?
 百态   2023-07-15
css怎么实现上下滚动
 干货   2023-06-28
canvas怎么画一个三角形?
 干货   2023-06-28
canvas怎么画一个椭圆形?
 干货   2023-06-28
canvas怎么画一个圆形?
 干货   2023-06-28
canvas怎么画一个正方形?
 干货   2023-06-28
中国河南省郑州市金水区蜘蛛爬虫ip大全
 干货   2023-06-22
javascript简易动态时间代码
 干货   2023-06-20
感谢员工的付出和激励的话怎么说?
 干货   2023-06-18
 
>>返回首页<<
 
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
© 2005- 王朝网络 版权所有