在Chromium Embedded 3(DCEF3)中禁用上下文菜单 [英] Disable context menu in Chromium Embedded 3 (DCEF3)

查看:63
本文介绍了在Chromium Embedded 3(DCEF3)中禁用上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试禁用Chromium Embedded(DCEF3)窗口中的鼠标右键(上下文菜单),但是我没有得到,我没有发现任何设置可以原生进行此操作。

I'm trying to disable the right mouse button (the context menu) in the window of Chromium Embedded (DCEF3) but I'm not getting, I did not find any settings to do this natively.

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

I can for example disable the "View Source", I am using the code below, but I really want is to disable the context menu, or do not want it to appear.

注意:我正在DLL Chromium.dll中使用此库,该库与 Inno Setup一起使用,等同于Inno Web Brower。

Note: I'm using this in DLL "Chromium.dll" a libray to be used with the "Inno Setup", equal to Inno Web Brower.

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中的上下文菜单,您将需要处理 OnBeforeContextMenu 事件并清除其 model 参数。这就是引用所陈述的内容(我强调):

To disable the context menu in DCEF 3 you'll need to handle the OnBeforeContextMenu event and clear its model parameter. That's what the reference states (emphasized by me):


OnBeforeContextMenu

在显示上下文菜单之前调用。 |参数|提供有关上下文菜单状态的
信息。 |型号|最初包含
的默认上下文菜单。 |型号|可以清除以不显示
上下文菜单
,也可以修改以显示自定义菜单。不要保留
对| params |的引用。或| model |

Called before a context menu is displayed. |params| provides information about the context menu state. |model| initially contains the default context menu. The |model| can be cleared to show no context menu or modified to show a custom menu. Do not keep references to |params| or |model| outside of this callback.

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

So, to completely disable the context menu you will write something like this:

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;

这篇关于在Chromium Embedded 3(DCEF3)中禁用上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆