防止TWebBrowser接受删除的文件

Bog*_*atu 2 delphi file droppable twebbrowser

我有一个接受要拖放的文件的表单,以及放在同一表单上的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;
Run Code Online (Sandbox Code Playgroud)

先感谢您.任何线索将非常感激.

RRU*_*RUZ 5

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

有关示例delphi代码,请尝试本文 How to handle drag and drop in a TWebBrowser control