Delphi使窗口支持文件拖放的简单例子,附源代码
来源:互联网 发布:iptv与网络电视的区别 编辑:程序博客网 时间:2024/06/05 23:54
使窗口支持Windows Shell的文件拖放功能简单的方式是使用Windows API: DragAcceptFiles,然后使用Delphi的VCL消息函数重载机制处理WM_DROPFILES消息,调用DragQueryFile即可.
DragAcceptFiles Function
--------------------------------------------------------------------------------
Registers whether a window accepts dropped files.
Syntax
VOID DragAcceptFiles( HWND hWnd,
BOOL fAccept
);
Parameters
hWnd
Identifier of the window that is registering whether it will accept dropped files.
fAccept
Value that indicates if the window identified by the hWnd parameter accepts dropped files. This value is TRUE to accept dropped files or FALSE to discontinue accepting dropped files.
Return Value
No return value.
Remarks
An application that calls DragAcceptFiles with the fAccept parameter set to TRUE has identified itself as able to process the WM_DROPFILES message from File Manager.
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
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
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 Me/98/95 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.
示例源代码:
unit fm_DropFiles;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,ShellApi,ShlObj, ExtCtrls, StdCtrls,ActiveX;
type
TfmDropFiles = class(TForm)
DropFileList: TListBox;
procedure FormCreate(Sender: TObject);
private
procedure WMDROPFILES(var Msg:TWMDROPFILES);message WM_DROPFILES;
public
{ Public declarations }
end;
var
fmDropFiles: TfmDropFiles;
implementation
{$R *.dfm}
procedure TfmDropFiles.FormCreate(Sender: TObject);
begin
DragAcceptFiles(Handle,True);
end;
procedure TfmDropFiles.WMDROPFILES(var Msg: TWMDROPFILES);
var
DropFileName:string;
DropCount:integer;
I:integer;
begin
inherited;
SetLength(DropFileName,MAX_PATH);
DropCount:=DragQueryFile(Msg.Drop,$FFFFFFFF,nil,0);
for I := 0 to DropCount-1 do
begin
DragQueryFile(Msg.Drop,I,PChar(DropFileName),MAX_PATH);
DropFileList.Items.Add(DropFileName);
end;
DragFinish(Msg.Drop);
end;
end.
下载:http://www.ctdisk.com/file/5490633
- Delphi使窗口支持文件拖放的简单例子,附源代码
- 使MFC支持拖放文件的方法
- 使MFC支持拖放文件的方法
- 让窗口支持拖放(文件,文本,URL...)
- 支持文件拖放的ListBox
- Delphi文件操作所涉及的一些函数 附例子
- 实现文件的拖放功能(Delphi)
- Delphi实现文件的拖放功能
- Delphi : 文件的拖放和打开,拖拽
- [转]使MFC支持拖放文件的方法
- IDropTarget 封装 让窗口支持拖放(文件,文本,URL...)
- 用Delphi开发易语言支持库,附源代码
- Delphi 拖放文件编程
- Delphi文件拖放示例
- 实现窗口的文件拖放功能
- 使对话框支持 文件拖放操作
- 使对话框支持 文件拖放操作
- 文件拖放支持
- 面试100题系列之6给出洗牌的一个算法,并把洗好的牌放在一个整型的数组里
- 对JSP页面传值中文乱码的简单解决方法
- C程序设计课程-2012电子信息 第六堂课后作业
- 多个Activity-利用BaseActivity提供共性
- ajax,struts,jsp验证用户名是否存在
- Delphi使窗口支持文件拖放的简单例子,附源代码
- 代码实现增加View对象
- HDU 3236 Gift Hunting - 分组背包 相当于两个01背包
- html5之canvas动画
- Programming Best Practices Tidbits
- JDK1.5新特性
- android102--MVC原理 和在安卓中的应用
- HDU 1011 Starship Troopers - 01树形dp 有坑啊!!
- SQL中的循环、for循环、游标