windows – 如何在Delphi中允许拖动特定控件的文件
发布时间:2020-12-14 04:37:58 所属栏目:Windows 来源:网络整理
导读:有人将文件丢弃到特定控件(例如TMemo)时,我想接受文件.我从这个例子开始: http://delphi.about.com/od/windowsshellapi/a/accept-filedrop.htm并将其修改为: procedure TForm1.FormCreate(Sender: TObject);begin DragAcceptFiles( Memo1.Handle,True ) ;e
有人将文件丢弃到特定控件(例如TMemo)时,我想接受文件.我从这个例子开始:
http://delphi.about.com/od/windowsshellapi/a/accept-filedrop.htm并将其修改为:
procedure TForm1.FormCreate(Sender: TObject); begin DragAcceptFiles( Memo1.Handle,True ) ; end; 这允许控件显示拖动图标但是没有调用正确的WM_DROPFILES消息,因为DragAcceptFiles需要一个(Parent?)窗口句柄.我可以在WMDROPFILES过程中确定MemoHandle,但我不知道如何,加上拖动光标现在适用于所有控件.如何允许拖动特定控件(并阻止其他控件拖动)? 解决方法
你应该确实传递memo控件的窗口句柄,但是你还需要监听发送给它的WM_DROPFILES消息:
unit Unit5; interface uses Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,StdCtrls,ShellAPI; type TMemo = class(StdCtrls.TMemo) protected procedure WMDropFiles(var Message: TWMDropFiles); message WM_DROPFILES; procedure CreateWnd; override; procedure DestroyWnd; override; end; TForm5 = class(TForm) Memo1: TMemo; procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form5: TForm5; implementation {$R *.dfm} procedure TForm5.FormCreate(Sender: TObject); begin end; { TMemo } procedure TMemo.CreateWnd; begin inherited; DragAcceptFiles(Handle,true); end; procedure TMemo.DestroyWnd; begin DragAcceptFiles(Handle,false); inherited; end; procedure TMemo.WMDropFiles(var Message: TWMDropFiles); var c: integer; fn: array[0..MAX_PATH-1] of char; begin c := DragQueryFile(Message.Drop,$FFFFFFFF,fn,MAX_PATH); if c <> 1 then begin MessageBox(Handle,'Too many files.','Drag and drop error',MB_ICONERROR); Exit; end; if DragQueryFile(Message.Drop,MAX_PATH) = 0 then Exit; Text := fn; end; end. 上面的示例只接受丢弃的单个文件.文件名将放在备忘录控件中.但您也可以删除多项选择: VAR c := DragQueryFile(Message.Drop,MAX_PATH); Clear; for i := 0 to c - 1 do begin if DragQueryFile(Message.Drop,i,MAX_PATH) = 0 then Exit; Lines.Add(fn); end; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- windows – NTFS元数据中包含哪些信息?
- 使用WebShellKiller检查服务器后门文件
- Windows Server 2012 R2上的随机BSOD
- uitableview – Windows Phone 7中的表视图
- Windows上的TensorFlow:ImportError:没有名为’
- windows-phone-7 – 是否可以为Windows Phone 7模
- 为什么RMI注册表忽略了java.rmi.server.codebase
- 批处理文件 – 如何将今天的日期与文件的上次修改
- Cryptoapi签名/验证无法在Windows 8.1上运行
- windows-server-2003 – 如何最好地将服务器迁移
热点阅读