Inno setup 禁用Chromium Embedded 3(DCEF3)中的上下文菜单

Inno setup 禁用Chromium Embedded 3(DCEF3)中的上下文菜单,inno-setup,chromium-embedded,Inno Setup,Chromium Embedded,我正在尝试禁用Chromium Embedded(DCEF3)窗口中的鼠标右键(上下文菜单),但是我没有得到,我没有找到任何本机设置 例如,我可以禁用“查看源代码”,我正在使用下面的代码,但我真正想要的是禁用上下文菜单,或者不希望它出现 注意:我在DLL“Chromium.DLL”库中使用它,该库将和“Inno设置”一起使用,相当于Inno Web浏览器 procedure TInnoChromium.OnContextMenuCommand(Sender: TObject; const b

我正在尝试禁用Chromium Embedded(DCEF3)窗口中的鼠标右键(上下文菜单),但是我没有得到,我没有找到任何本机设置

例如,我可以禁用“查看源代码”,我正在使用下面的代码,但我真正想要的是禁用上下文菜单,或者不希望它出现

注意:我在DLL“Chromium.DLL”库中使用它,该库将和“Inno设置”一起使用,相当于Inno Web浏览器

procedure TInnoChromium.OnContextMenuCommand(Sender: TObject;
  const browser: ICefBrowser; const frame: ICefFrame;
  const params: ICefContextMenuParams; commandId: Integer;
  eventFlags: TCefEventFlags; out Result: Boolean);
begin
if (commandId = 132) then Result := True; // MENU_ID_VIEW_SOURCE
end;

要禁用DCEF 3中的上下文菜单,您需要处理事件并清除其
model
参数。这就是参考书中所说的(我强调):

OnBeforeContextMenu

在显示关联菜单之前调用|params |提供 有关上下文菜单状态的信息|模型|最初包含 默认上下文菜单可以清除|模型|以显示否 上下文菜单或修改为显示自定义菜单。不保留 在此回调之外对| params |或| model |的引用

因此,要完全禁用上下文菜单,您将编写如下内容:

uses
  cefvcl, ceflib;

type
  TInnoChromium = class
  ...
  private
    FChromium: TChromium;
    procedure BeforeContextMenu(Sender: TObject; const browser: ICefBrowser;
      const frame: ICefFrame;
  public
    constructor Create;
  end;

implementation

constructor TInnoChromium.Create;
begin
  FChromium := TChromium.Create(nil);
  ...
  FChromium.OnBeforeContextMenu := BeforeContextMenu;
end;

procedure TInnoChromium.BeforeContextMenu(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame; const params: ICefContextMenuParams; const model: ICefMenuModel);
begin
  // to disable the context menu clear the model parameter
  model.Clear;
end;

<>注释:在C++版本中:

void ClientHandler::OnBeforeContextMenu(
    CefRefPtr<CefBrowser> browser,
    CefRefPtr<CefFrame> frame,
    CefRefPtr<CefContextMenuParams> params,
    CefRefPtr<CefMenuModel> model) {
  CEF_REQUIRE_UI_THREAD();

    //Clear disables the context menu
    model->Clear();
  }
}
void ClientHandler::OnBeforeContextMenu(
CefRefPtr浏览器,
CefRefPtr框架,
CefRefPtr参数,
CefRefPtr模型){
CEF_REQUIRE_UI_THREAD();
//清除将禁用关联菜单
模型->清除();
}
}

不客气!是的,这是再容易不过了:-)但例如,在CEF 1中是这样的;在CEF 3中这并不明显。我在CEF 1中看到了这篇文章,尽管在DCEF3 xDCefContextMenuHandler::OnBeforeContextMenu(…)中更容易看到