我正在使用Embarcadero RAD Studio XE开发应用程序。我正在尝试使用以下代码将文件拖放到应用程序
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;
这段代码没有问题。此外,当我拖放文件时,光标显示状态已更改为拖放,但在删除后,没有任何反应(也未显示任何消息)。这有什么不对吗?
答案 0 :(得分:8)
在一个普通的vanilla应用程序中,当一个对象被删除在表单上时,问题中的代码会导致WMDropFiles
执行。所以,显然还有其他事情可以阻止它发挥作用。最明显的潜在原因是:
DragAcceptFiles
后,将重新创建主窗体的窗口句柄。选项2似乎很合理。要了解详情,请参阅:Q: Why Doesn’t Drag-and-Drop work when my Application is Running Elevated? – A: Mandatory Integrity Control and UIPI
答案 1 :(得分:4)
TForm.Create
中的使用两行
ChangeWindowMessageFilter (WM_DROPFILES, MSGFLT_ADD);
ChangeWindowMessageFilter (WM_COPYGLOBALDATA, MSGFLT_ADD);
全部