windows - 拖放在我的 delphi 项目中不再起作用

标签 windows delphi file drag-and-drop messages

这个话题显然已经在这里被反复提及,但现在从我的角度来看,我已经没有选择了。

操作系统:Windows XP SP3

所以,这是我在我的应用中使用的 RichEdit 的拖放示例:

procedure TForm1.AcceptFiles( var msg : TMessage ); // or TWMDROPFILES
const
  cnMaxFileNameLen = 255;
var
  i,
  nCount     : integer;
  acFileName : array [0..cnMaxFileNameLen] of char;
begin
  // find out how many files we're accepting
  nCount := DragQueryFile( msg.WParam, // or msg.Drop
                           $FFFFFFFF,
                           acFileName,
                           cnMaxFileNameLen );

  // query Windows one at a time for the file name
  for i := 0 to nCount-1 do
  begin
    DragQueryFile( msg.WParam, { or msg.Drop} i,
                   acFileName, cnMaxFileNameLen );

    // do your thing with the acFileName
    MessageBox( Handle, acFileName, '', MB_OK );
  end;

  // let Windows know that you're done
  DragFinish( msg.WParam ); // or msg.Drop
end;

问题是在最近的一些更改之后(不幸的是我没有使用任何 SVN,所以我无法跟踪哪个提交引入了这个问题)拖放不再起作用。

我在每个可能以某种方式相关(称为)的事件中运行断点但没有成功:

RichEditMouseOver;

RichEditChange;

FormClick;

我的应用正在处理这些 WM:

procedure WMDropFiles(var Msg: TWMDROPFILES); message WM_DROPFILES;

procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;

procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA;

procedure WMGetMinMaxInfo(var AMsg: TWMGetMinMaxInfo); message WM_GETMINMAXINFO;

procedure CMDialogKey(var Msg: TCMDialogKey ); message CM_DIALOGKEY;

在表单上使用 TRichEdit 的空白项目中 - 一切正常。

还尝试更改 DragAcceptFiles() Form1.HandleRichEdit.Handle - 还是不行。

当回显 nCountacFileName 参数时,acFileName 没有拖动文件的文件路径...为什么????

目前我只是不知道是什么导致 acFileName 参数丢失拖动的文件路径。您能指出问题出在哪里吗?

最佳答案

摘自 official Microsoft support forum :

A possible reason for the not being able to drag & drop files to the application could be UAC integrity level (IL). With UAC enabled in Vista or Win7, drag and drop is not allowed to happen from low IL process to high IL process by default. Please check whether your application is elevated (run as admin) when the problem happens.

如果您不想禁用 UAC,您可以尝试只禁用 UIPI(用户界面特权隔离)。

打开注册表并转到:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System

添加一个名为 EnableUIPI 的新 DWORD(32 位)值并将其设置为 0。

重新启动机器,看看它的行为是否如您所愿。

关于windows - 拖放在我的 delphi 项目中不再起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4345643/

相关文章:

Windows Azure : asp.net <appsetting> 未找到 ChatHttpHandler

windows - Windows命令在cmd中工作,但不是.bat文件

c - 为什么 fread 返回零以及文件何时包含内容

c++ - 在 winapi CALLBACK 函数上返回 FALSE 时出现意外行为(跳过循环?)

python - 如何在 Windows 上配置 Tor 代理?

delphi - 像 PsSuspend 一样暂停/恢复进程

c# - WCF 和 Delphi - 我应该使用 bytes[] 还是字符串?

c# - 如何从多维 PSafeArray 获取数据?

python 2.7 文件困难

java - 将 Java txt 文件保存到文件夹