我用twebbrower显示一个html文档,但是我不想让它出现弹出菜单,主要是禁止他刷新,请教怎样才可以做到?

解决方案 »

  1.   

    1.加入一个ApplicationEvents,在OnMessage事件中加入以下代码:
    procedure TfrmMain.ApplicationEvents1Message(var Msg: tagMSG;
      var Handled: Boolean);
    begin
     if IsChild(WebBrowser1.Handle, Msg.Hwnd) and
         ((Msg.Message = WM_RBUTTONDOWN) or (Msg.Message = WM_RBUTTONUP)) then
      begin
         // dxBarPopupMenu.PopupFromCursorPos ;//在这里做你想做的事,比如显示你的菜单
        Handled:=True;
      end;
    end; -------------------------------------------------------
    本回复由大傻的破玩意儿【CSDN's forum Explorer】完成!
    软件功能强大,速度超快!!支持中...
    软件下载地址:http://CoolSlob.ys168.com
      

  2.   

    procedure TForm1.FormCreate(Sender: TObject);
    begin
      WebBrowser1.Navigate('http://www.gogle.com');
      Application.OnMessage := MessageEvent;
    end;function GetClassName(hWnd: THandle): string;
    var
      P: PChar;
    begin
      GetMem(P, MAX_PATH);
      try
        Windows.GetClassName(hWnd, P, MAX_PATH);
        Result := P;
      finally
        FreeMem(P);
      end;
    end;procedure TForm1.MessageEvent(var Msg: TMsg; var Handled: Boolean);
    var
      S: string;
    begin
      Handled := False;
      if (Msg.message = WM_RBUTTONDOWN)
        or (Msg.message = WM_RBUTTONUP) then
      begin
        S := GetClassName(Msg.hwnd);
        if SameText(S, 'Internet Explorer_Server') then
        begin
          //MyPopupMenu.Popup
          Handled := true;
        end;
      end;
    end;
      

  3.   

    to 饭桶http://community.csdn.net/Expert/topic/4877/4877308.xml?temp=.6406671
    帮助看看
      

  4.   

    试了,单单截住WM_RBUTTONDOWN/WM_RBUTTONUP只能拦住鼠标,但是按菜单键后,菜单还是弹出来了,还有没有比较彻底一点的办法?谢谢
      

  5.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, OleCtrls, SHDocVw, ActiveX;type
        PDOCHOSTUIINFO = ^TDOCHOSTUIINFO;
        TDOCHOSTUIINFO = record
          cbSize: ULONG;
          dwFlags: DWORD;
          dwDoubleClick: DWORD;
          chHostCss: POLESTR;
          chHostNS: POLESTR;
        end;  IDocHostUIHandler = interface(IUnknown)
        ['{bd3f23c0-d43e-11cf-893b-00aa00bdce1a}']
        function ShowContextMenu(const dwID: DWORD; const ppt: PPOINT;
          const pcmdtReserved: IUnknown; const pdispReserved: IDispatch): HRESULT; stdcall;
        function GetHostInfo(var pInfo: TDOCHOSTUIINFO): HRESULT; stdcall;
        function ShowUI(const dwID: DWORD; const pActiveObject: IOleInPlaceActiveObject;
          const pCommandTarget: IOleCommandTarget; const pFrame: IOleInPlaceFrame;
          const pDoc: IOleInPlaceUIWindow): HRESULT; stdcall;
        function HideUI: HRESULT; stdcall;
        function UpdateUI: HRESULT; stdcall;
        function EnableModeless(const fEnable: BOOL): HRESULT; stdcall;
        function OnDocWindowActivate(const fActivate: BOOL): HRESULT; stdcall;
        function OnFrameWindowActivate(const fActivate: BOOL): HRESULT; stdcall;
        function ResizeBorder(const prcBorder: PRECT;
          const pUIWindow: IOleInPlaceUIWindow;
          const fRameWindow: BOOL): HRESULT; stdcall;
        function TranslateAccelerator(const lpMsg: PMSG; const pguidCmdGroup: PGUID;
          const nCmdID: DWORD): HRESULT; stdcall;
        function GetOptionKeyPath(var pchKey: POLESTR; const dw: DWORD): HRESULT; stdcall;
        function GetDropTarget(const pDropTarget: IDropTarget;
          out ppDropTarget: IDropTarget): HRESULT; stdcall;
        function GetExternal(out ppDispatch: IDispatch): HRESULT; stdcall;
        function TranslateUrl(const dwTranslate: DWORD; const pchURLIn: POLESTR;
          var ppchURLOut: POLESTR): HRESULT; stdcall;
        function FilterDataObject(const pDO: IDataObject;
          out ppDORet: IDataObject): HRESULT; stdcall;
      end; // IDocHostUIHandler  TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;  TMyWebBrowser = class(TWebBrowser, IDocHostUIHandler)
      protected
        function ShowContextMenu(const dwID: DWORD; const ppt: PPOINT;
          const pcmdtReserved: IUnknown; const pdispReserved: IDispatch): HRESULT; stdcall;
        function GetHostInfo(var pInfo: TDOCHOSTUIINFO): HRESULT; stdcall;
        function ShowUI(const dwID: DWORD; const pActiveObject: IOleInPlaceActiveObject;
          const pCommandTarget: IOleCommandTarget; const pFrame: IOleInPlaceFrame;
          const pDoc: IOleInPlaceUIWindow): HRESULT; stdcall;
        function HideUI: HRESULT; stdcall;
        function UpdateUI: HRESULT; stdcall;
        function EnableModeless(const fEnable: BOOL): HRESULT; stdcall;
        function OnDocWindowActivate(const fActivate: BOOL): HRESULT; stdcall;
        function OnFrameWindowActivate(const fActivate: BOOL): HRESULT; stdcall;
        function ResizeBorder(const prcBorder: PRECT;
          const pUIWindow: IOleInPlaceUIWindow;
          const fRameWindow: BOOL): HRESULT; stdcall;
        function TranslateAccelerator(const lpMsg: PMSG; const pguidCmdGroup: PGUID;
          const nCmdID: DWORD): HRESULT; stdcall;
        function GetOptionKeyPath(var pchKey: POLESTR; const dw: DWORD): HRESULT; stdcall;
        function GetDropTarget(const pDropTarget: IDropTarget;
          out ppDropTarget: IDropTarget): HRESULT; stdcall;
        function GetExternal(out ppDispatch: IDispatch): HRESULT; stdcall;
        function TranslateUrl(const dwTranslate: DWORD; const pchURLIn: POLESTR;
          var ppchURLOut: POLESTR): HRESULT; stdcall;
        function FilterDataObject(const pDO: IDataObject;
          out ppDORet: IDataObject): HRESULT; stdcall;
      end;var
      Form1: TForm1;
      WebBrowser: TMyWebBrowser;
      

  6.   

    implementation{$R *.dfm}{ TMyWebBrowser }function TMyWebBrowser.EnableModeless(const fEnable: BOOL): HRESULT;
    begin
      Result := S_FALSE;
    end;function TMyWebBrowser.FilterDataObject(const pDO: IDataObject;
      out ppDORet: IDataObject): HRESULT;
    begin
      Result := S_FALSE
    end;function TMyWebBrowser.GetDropTarget(const pDropTarget: IDropTarget;
      out ppDropTarget: IDropTarget): HRESULT;
    begin
      Result := S_OK
    end;function TMyWebBrowser.GetExternal(out ppDispatch: IDispatch): HRESULT;
    begin
      Result := S_FALSE
    end;function TMyWebBrowser.GetHostInfo(var pInfo: TDOCHOSTUIINFO): HRESULT;
    begin
      Result := S_OK
    end;function TMyWebBrowser.GetOptionKeyPath(var pchKey: POLESTR;
      const dw: DWORD): HRESULT;
    begin
      Result := S_FALSE
    end;function TMyWebBrowser.HideUI: HRESULT;
    begin
      Result := S_FALSE
    end;function TMyWebBrowser.OnDocWindowActivate(const fActivate: BOOL): HRESULT;
    begin
      Result := S_False;
    end;function TMyWebBrowser.OnFrameWindowActivate(
      const fActivate: BOOL): HRESULT;
    begin
      Result := S_FALSE
    end;function TMyWebBrowser.ResizeBorder(const prcBorder: PRECT;
      const pUIWindow: IOleInPlaceUIWindow; const fRameWindow: BOOL): HRESULT;
    begin
      Result := S_FALSE
    end;function TMyWebBrowser.ShowContextMenu(const dwID: DWORD;
      const ppt: PPOINT; const pcmdtReserved: IInterface;
      const pdispReserved: IDispatch): HRESULT;
    begin
      Result := S_OK //就这一句了
    end;function TMyWebBrowser.ShowUI(const dwID: DWORD;
      const pActiveObject: IOleInPlaceActiveObject;
      const pCommandTarget: IOleCommandTarget; const pFrame: IOleInPlaceFrame;
      const pDoc: IOleInPlaceUIWindow): HRESULT;
    begin
      Result := S_FALSE
    end;function TMyWebBrowser.TranslateAccelerator(const lpMsg: PMSG;
      const pguidCmdGroup: PGUID; const nCmdID: DWORD): HRESULT;
    begin
      Result := S_FALSE
    end;function TMyWebBrowser.TranslateUrl(const dwTranslate: DWORD;
      const pchURLIn: POLESTR; var ppchURLOut: POLESTR): HRESULT;
    begin
      Result := S_FALSE
    end;function TMyWebBrowser.UpdateUI: HRESULT;
    begin
      Result := S_FALSE
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      WebBrowser := TMyWebBrowser.Create(Self);
      WebBrowser.SetParent(Self);
      WebBrowser.Width := 500;
      WebBrowser.Height := 300;  WebBrowser.Navigate('http://www.google.com');
    end;procedure TForm1.FormDestroy(Sender: TObject);
    begin
      FreeAndNil(WebBrowser);
    end;end.
      

  7.   

    关于IDocHostUIHandler的详细说明,请参阅msdn