• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Delphi使窗口支持文件拖放的简单例子,附源代码

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

  使窗口支持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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap