我在程序里面用TWebBrowser调用了一个Web页面,可是我不想用户在这个Web页面里单击鼠标右键。那位知道怎么做呀,告诉小弟一声。谢谢了。

解决方案 »

  1.   

    比如子类化TWebBrowser,然后收到鼠标消息时判断是不是点击的右键,是的话就不调用默认的窗口函数..文档区有这方面的贴子,你找找吧.
      

  2.   

    给body元素添加一个属性:oncontextmenu="return false;"
      

  3.   

    禁止WebBrowser的右键菜单    
      disable the Context Menu in a TWebbrowser? var
    HookID: THandle;
    function MouseProc(nCode: Integer; wParam, lParam: Longint): Longint; stdcall;
    var
    szClassName: array[0..255] of Char;
    const
    ie_name = 'Internet Explorer_Server';
    begin
    case nCode < 0 of
    True:
    Result := CallNextHookEx(HookID, nCode, wParam, lParam)
    else
    case wParam of
    WM_RBUTTONDOWN,
    WM_RBUTTONUP:
    begin
    GetClassName(PMOUSEHOOKSTRUCT(lParam)^.HWND, szClassName, SizeOf(szClassName));
    if lstrcmp(@szClassName[0], @ie_name[1]) = 0 then
    Result := HC_SKIP
    else
    Result := CallNextHookEx(HookID, nCode, wParam, lParam);
    end
    else
    Result := CallNextHookEx(HookID, nCode, wParam, lParam);
    end;
    end;
    end;
    procedure TForm1.FormCreate(Sender: TObject);
    begin
    HookID := SetWindowsHookEx(WH_MOUSE, MouseProc, 0, GetCurrentThreadId());
    end;
    procedure TForm1.FormDestroy(Sender: TObject);
    begin
    if HookID <> 0 then
    UnHookWindowsHookEx(HookID);
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    Webbrowser1.Navigate('http://www.google.com&#39;);
    end;
      

  4.   

    procedure OnAppMsg(var msg: tmsg;var handled: boolean);
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      WebBrowser1.Navigate('http://www.163.com');
      Application.OnMessage := OnAppMsg;
    end;procedure TForm1.OnAppMsg(var msg: tmsg; var handled: boolean);
    begin
      if (msg.message = wm_rbuttondown) then
      begin
        showmessage(inttostr(WebBrowser1.Handle));
        showmessage(inttostr(windowfrompoint(msg.pt)));
        showmessage(inttostr(msg.lParam));
        showmessage(inttostr(longint(@msg.wParam)));
        showmessage('trap browser mouse');
      end
      else
        inherited;
    end;
    _____________________________________
    procedure OnAppMsg(var msg: tmsg;var handled: boolean);
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      WebBrowser1.Navigate('http://www.163.com');
      Application.OnMessage := OnAppMsg;
    end;procedure TForm1.OnAppMsg(var msg: tmsg; var handled: boolean);
    begin
      if (msg.message = wm_rbuttondown) then
      begin
        showmessage(inttostr(WebBrowser1.Handle));
        showmessage(inttostr(windowfrompoint(msg.pt)));
        showmessage(inttostr(msg.lParam));
        showmessage(inttostr(longint(@msg.wParam)));
        showmessage('trap browser mouse');
      end
      else
        inherited;
    end;