Delphi WebBrowser右键的方法

uses MSHtml;

//在控件标签additional中找到TApplicationEvents控件,拖到窗体上.在TApplicationEvents的OnMessage事件中加入以下代码:
//替换右键菜单

procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
var
  mPoint: TPoint;
begin
  if IsChild(WebBrowser.Handle, Msg.Hwnd) and
    ((Msg.Message = WM_RBUTTONDOWN) or (Msg.Message = WM_RBUTTONUP)) then
  begin
    GetCursorPos(mPoint); //得到光标位置
    pm5.Popup(mPoint.X, mPoint.Y); //弹出popupmenu1的菜单
    Handled := True;
  end;
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;

你可能感兴趣的:(Delphi,WebBrowser)