为什么当文件丢弃时,我的表单不接收WM_DropFiles? [英] Why doesn't my form receive WM_DropFiles when files are dropped on it?

查看:119
本文介绍了为什么当文件丢弃时,我的表单不接收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. 您的进程中的其他内容干扰了拖放。不知道你的应用程序是什么,很难猜到这可能是什么。开始删除应用程序的部分,直到没有任何内容,但问题中的代码。

选项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天全站免登陆