本文介绍了如何在Delphi中通过事件处理和消息过滤,阻止WebBrowser控件中的右键菜单以及防止用户使用Ctrl+N快捷键。通过`ProcessMsg`和`ApplicationEvents1Message`等方法实现对浏览器行为的控制。
{
关键字=webbrowser屏蔽右键菜单 防止右键 防止ctrl N
采集软件=MKM - 我的知识管理
采集日期=2023-11-23 21:44:46
数字签名=B1779CEF8D102A9A324F1118A5BD04C2
}
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms,
Dialogs, StdCtrls, OleCtrls, SHDocVw, ExtCtrls, MSHtml,
AppEvnts, ActiveX,
ComCtrls;
procedure TForm1.ProcessMsg(var Msg: TMsg; var Handled: Boolean);
begin
{webbrowser屏蔽右键菜单
防止右键
防止ctrl+N
}
//防止ctrl+N
if (Msg.Message = WM_KEYdown) and (Msg.wParam = 78) and ((GetKeyState(VK_CONTROL) and $8000) <> 0) then
begin
Handled := true;
exit;
end;
//防止右键
if (Msg.Message = WM_RBUTTONDOWN) or (Msg.Message = WM_RBUTTONUP) or (Msg.Message = WM_CONTEXTMENU) then
begin
Handled := true;
exit;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
WebBrowser1.Silent := true;
Application.OnMessage := ProcessMsg;
end;
procedure TForm1.ApplicationEvents1ActionExecute(Action: TBasicAction;
var Handled: Boolean);
begin
end;
//屏蔽右键菜单
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
begin
with Msg do
begin
if not IsChild(WebBrowser1.Handle, hWnd) then exit;
Handled := (Message = WM_RBUTTONDOWN) or (Message = WM_RBUTTONUP) or (Message = WM_CONTEXTMENU);
end;
end;
————————————————
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/fogbow622/article/details/134673998