我有一个框架,其中包含一个 TWebBrowser
组件并被我的一些应用程序使用,我需要禁用 TWebBrowser
的默认弹出菜单。
我找到了一个适用于应用程序级别的解决方案,通过这种方式使用 TApplicationEvents
组件及其 OnMessage
事件处理程序:
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
begin
if (Msg.Message = WM_RBUTTONDOWN) or (Msg.Message = WM_RBUTTONDBLCLK) then
begin
if IsChild(WebBrowser1.Handle, Msg.hwnd) then
begin
Handled := True;
end;
end;
end;
我正在寻找一种在框架/TWebBrowser
级别工作的解决方案,而无需在应用程序级别添加代码。
我已尝试分配 TWebBrowser
的 TPopupMenu
属性,但它仅在 WebBrowser 上加载页面之前有效。
我已尝试分配 TWebBrowser
的 WindowProc
,但在 WebBrowser 中加载页面后,不再执行代码。
private
FPrevBrowWindowProc : TWndMethod;
procedure BrowWindowProc(var AMessage: TMessage);
...
procedure TFrame1.BrowWindowProc(var AMessage: TMessage);
begin
if(AMessage.Msg = WM_RBUTTONDOWN) or (AMessage.Msg = WM_RBUTTONDBLCLK) then
Exit;
if(Assigned(FPrevBrowWindowProc))
then FPrevBrowWindowProc(AMessage);
end;
constructor TFrame1.Create(AOwner : TComponent);
begin
inherited;
FPrevBrowWindowProc := WebBrowser1.WindowProc;
VS_Brow.WindowProc := BrowWindowProc;
end;