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

前端之家收集整理的这篇文章主要介绍了inno-setup – 禁用Chromium Embedded 3(DCEF3)中的上下文菜单前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试在Chromium Embedded(DCEF3)的窗口中禁用鼠标右键(上下文菜单),但我没有得到,我没有找到任何设置来本机执行此操作.

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

注意:我在DLL“Chromium.dll”中使用这个libray与“Inno Setup”一起使用,等同于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事件并清除其模型参数.这就是参考文献所指出的内容(我强调):

OnBeforeContextMenu

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.

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

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;
原文链接:https://www.f2er.com/delphi/101923.html

猜你在找的Delphi相关文章