Kermia
Kermia

Reputation: 4221

How to disable right click in WebBrowser when we're using Flash ! (Delphi)

How can i disable the menu of flash player when I'm navigating a flash file with WebBrowser ?

Upvotes: 4

Views: 4191

Answers (2)

Serkan Ekşioğlu
Serkan Ekşioğlu

Reputation: 251

Heres another way.

procedure TForm1.FormMouseActivate(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y, HitTest: Integer;
  var MouseActivate: TMouseActivate);
begin
  if Button=mbRight then
  begin
    if (x >= WebBrowser1.Left) and
       (x <= WebBrowser1.Left + WebBrowser1.Width ) and
       (y >= WebBrowser1.Top) and
       (y <= WebBrowser1.Top + WebBrowser1.Height ) then
      MouseActivate := maNoActivateAndEat;
  end;
end;

Upvotes: 2

Stijn Sanders
Stijn Sanders

Reputation: 36840

All messages that are sent to the WebBrowser, pass through your Delphi application as well, so by using a TApplicationEvents component and checking for the right-click event in the OnMessage event on the Handle of WebBrowser, or any of it's child handles (use IsChild) and set Handled, you should be able to block it.

The code could look like this

procedure TMyForm.ApplicationEvents1Message(var Msg: tagMSG;
  var Handled: Boolean);
begin
  if (Msg.message=WM_RBUTTONDOWN) and IsChild(WebBrowser1.Handle,Msg.hwnd) then
   begin
    PopupMenu1.Popup(Msg.pt.X,Msg.pt.Y);
    Handled:=true;
   end;
end;

Upvotes: 5

Related Questions