为什么我的表单在文件被丢弃时没有收到 WM_DropFiles? [英] Why doesn't my form receive WM_DropFiles when files are dropped on it?

查看:12
本文介绍了为什么我的表单在文件被丢弃时没有收到 WM_DropFiles?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Embarcadero RAD Studio XE 开发应用程序.我正在尝试使用以下代码将文件拖放到应用程序中

I am using Embarcadero RAD Studio XE to develop an application. I am trying catch the file(s) drag and drop to the application with the following code

TMainForm = class(TForm)
public:
  procedure WMDropFiles(var Msg: TWMDropFiles); message WM_DROPFILES;
end;

procedure TMainForm.FormCreate(Sender: TObject);
begin
  DragAcceptFiles(Self.Handle, True);
end;

procedure TMainForm.FormDestroy(Sender: TObject);
begin
  DragAcceptFiles(Self.Handle, False);
end;

procedure TMainForm.WMDropFiles(var Msg: TWMDropFiles);
begin
  inherited;
  showmessage('catch here');
  // some code to handle the drop files here
  Msg.Result := 0;
end;

这段代码没有问题.另外,当我拖放文件时,光标显示状态更改为拖放,但在拖放后,什么也没有发生(也没有显示消息).这有什么问题吗?

This code complied without problem. Also, when I drag and drop files, the cursor show that the status changed to drag and drop but after things dropped, nothing happen (no message shown too). Is that anything wrong with that?

推荐答案

在普通的 vanilla 应用程序中,问题中的代码会导致在将对象拖放到表单上时执行 WMDropFiles.因此,显然还有其他事情发生以阻止它工作.最明显的潜在原因是:

In a plain vanilla application, the code in the question results in WMDropFiles executing when an object is dropped on the form. So, clearly there's something else happening to stop it working. The most obvious potential causes are:

  1. 在初始调用 DragAcceptFiles 后重新创建主窗体的窗口句柄.
  2. 您的进程运行的完整性级别高于在其上删除文件的进程.例如,您是否以管理员身份运行进程.请注意,以管理员身份运行 Delphi IDE 会导致您的进程在从 IDE 启动时以管理员身份运行.
  3. 您的流程中有其他因素干扰了拖放操作.在不知道您的应用程序中有什么的情况下,很难猜测这可能是什么.开始删除应用的某些部分,直到只剩下问题中的代码.
  1. The main form's window handle is re-created after the initial call to DragAcceptFiles.
  2. Your process is running at a higher integrity level than the process that is dropping files on it. For example, are you running your process as administrator. Note that running the Delphi IDE as administrator would lead to your process running as administrator when started from the IDE.
  3. Something else in your process is interfering with drag/drop. Without knowing what's in your app, it's hard to guess what this could be. Start removing portions of your app until there's nothing left but the code in the question.

选项 2 似乎很合理.要了解更多信息,请参阅:问:为什么当我的应用程序运行提升时拖放不起作用?– A:强制性完整性控制和 UIPI

Option 2 seems quite plausible. To learn more see: Q: Why Doesn’t Drag-and-Drop work when my Application is Running Elevated? – A: Mandatory Integrity Control and UIPI

这篇关于为什么我的表单在文件被丢弃时没有收到 WM_DropFiles?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆