【问题标题】:Prevent TWebBrowser from accepting dropped files阻止 TWebBrowser 接受丢弃的文件
【发布时间】:2012-07-12 13:26:47
【问题描述】:

我有一个接受拖放文件的表单,以及放置在同一表单上的 TPanel 控件上的 TWebBrowser 控件。

主要的是,当我在窗体上放置一个文件时,它的路径被添加到一个 TEdit 控件中。但是,当用户将文件拖放到表单上时,有时他们实际上可能会将其拖放到 TWebBrowser 上,该浏览器根据文件类型为用户提供保存或运行文件。这实际上是我不想发生的事情,我只想让 TWebBrowser 要么忽略删除的文件,要么像表单一样处理它。

这是我用来处理 WM_DROPFILES 消息的代码:

procedure TMainForm.AcceptFiles( var msg : TMessage );
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,
                           $FFFFFFFF,
                           acFileName,
                           cnMaxFileNameLen );

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

    // do your thing with the acFileName
    //MessageBox( Handle, acFileName, '', MB_OK );
    Edit1.Text := acFileName;
  end;

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

提前谢谢你。任何线索将不胜感激。

【问题讨论】:

    标签: delphi file droppable twebbrowser


    【解决方案1】:

    要拦截 TWebBrowser 中的拖放操作,您必须实现 IDropTargetIDocHostUIHandler 接口。那么你必须使用 GetDropTarget 方法来传递你自己的 IDropTarget 实现。

    对于示例 delphi 代码,请尝试这篇文章 How to handle drag and drop in a TWebBrowser control

    【讨论】:

    • 谢谢@RRUZ,这正是我想要的。
    猜你喜欢
    • 1970-01-01
    • 2010-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-07
    • 2023-03-05
    • 2017-11-11
    • 1970-01-01
    相关资源
    最近更新 更多