gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 09:50:20 25 4
gpt4 key购买 nike

我试图在 Chromium Embedded (DCEF3) 的窗口中禁用鼠标右键(上下文菜单),但我没有得到,我没有找到任何本地执行此操作的设置。

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

注意:我在 DLL "Chromium.dll"中使用它,这是一个与 "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 事件并清除其 model范围。这就是引用文献所说的(我强调):

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;

关于inno-setup - 在 Chromium Embedded 3 (DCEF3) 中禁用上下文菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18640725/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com