去除WebBrowser的 3D边框、滚动条、右键菜单...

 

unit WebBrowserWithUI;

 

interface

 

uses

  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

  OleCtrls, SHDocVw, COmObj, ActiveX;

 

type

  TEnhancedWebBrowserUI = class(TPersistent)

  private

    FlatScrollBar: boolean;

    IE3DBorder: boolean;

    RightClickMenu: boolean;

    ScrollBar: boolean;

  public

    constructor Create;

  published

    property EnableScrollBars: boolean read ScrollBar write ScrollBar;

    property EnableFlatScrollBars: boolean read FlatScrollBar write

      FlatScrollBar;

    property EnableContextMenu: boolean read RightClickMenu write

      RightClickMenu;

    property Enable3DBorder: boolean read IE3DBorder write IE3DBorder;

  end;

  pDocHostUIInfo = ^TDocHostUIInfo;

  TDocHostUIInfo = packed record

    cbSize: ULONG;

    dwFlags: DWORD;

    dwDoubleClick: DWORD;

    pchHostCss: polestr;

    pchHostNS: polestr;

  end;

  IDocHostUIHandler = interface(IUnknown)

    ['{bd 3f 23c 0-d43e-11cf-893b-00aa00bdce 1a }']

    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;

 

  TWebBrowserWithUI = class(TWebBrowser, IDocHostUIHandler)

  private

    { Private declarations }

    UIProperties: TEnhancedWebBrowserUI;

  protected

    { Protected declarations }

  public

    { Public declarations }

    constructor Create(AOwner: TComponent); override;

    destructor Destroy; override;

    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;

  published

    { Published declarations }

    property UISettings: TEnhancedWebBrowserUI read UIProperties write

      UIProperties;

  end;

const

  DOCHOSTUIFLAG_DIALOG = $00000001;

  DOCHOSTUIFLAG_DISABLE_HELP_MENU = $00000002;

  DOCHOSTUIFLAG_NO3DBORDER = $00000004;

  DOCHOSTUIFLAG_SCROLL_NO = $00000008;

  DOCHOSTUIFLAG_DISABLE_SCRIPT_INACTIVE = $00000010;

  DOCHOSTUIFLAG_OPENNEWWIN = $00000020;

  DOCHOSTUIFLAG_DISABLE_OFFSCREEN = $00000040;

  DOCHOSTUIFLAG_FLAT_SCROLLBAR = $00000080;

  DOCHOSTUIFLAG_DIV_BLOCKDEFAULT = $00000100;

  DOCHOSTUIFLAG_ACTIVATE_CLIENTHIT_ONLY = $00000200;

  DOCHOSTUIFLAG_OVERRIDEBEHAVIOURFACTORY = $00000400;

  DOCHOSTUIFLAG_CODEPAGELINKEDFONTS = $00000800;

  DOCHOSTUIFLAG_URL_ENCODING_DISABLE_UTF8 = $00001000;

  DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 = $00002000;

  DOCHOSTUIFLAG_ENABLE_FORMS_AUTOCOMPLETE = $00004000;

  IID_IDocHostUIHandler: TGUID = '{bd 3f 23c 0-d43e-11CF-893b-00aa00bdce 1a }';

 

procedure Register;

 

implementation

 

procedure Register;

begin

  RegisterComponents('Samples', [TWebBrowserWithUI]);

end;

 

{ TEnhancedWebBrowserUI }

 

constructor TEnhancedWebBrowserUI.Create;

begin

  ScrollBar := True;

  FlatScrollBar := False;

  IE3DBorder := True;

  RightClickMenu := True;

end;

 

{ TWebBrowserWithUI }

 

constructor TWebBrowserWithUI.Create(AOwner: TComponent);

begin

  inherited;

  UIProperties := TEnhancedWebBrowserUI.Create;

end;

 

destructor TWebBrowserWithUI.Destroy;

begin

  UIProperties.Free;

  inherited;

end;

 

function TWebBrowserWithUI.EnableModeless(const fEnable: BOOL): HRESULT;

begin

  result := S_FALSE;

end;

 

function TWebBrowserWithUI.FilterDataObject(const pDO: IDataObject;

  out ppDORet: IDataObject): HRESULT;

begin

  result := S_FALSE;

end;

 

function TWebBrowserWithUI.GetDropTarget(const pDropTarget: IDropTarget;

  out ppDropTarget: IDropTarget): HRESULT;

begin

  result := S_FALSE;

end;

 

function TWebBrowserWithUI.GetExternal(out ppDispatch: IDispatch): HRESULT;

begin

  result := S_OK;

end;

 

function TWebBrowserWithUI.GetHostInfo(var pInfo: TDOCHOSTUIINFO): HRESULT;

begin

  pInfo.cbSize := SizeOf(pInfo);

  pInfo.dwFlags := 0;

  if not UIProperties.EnableScrollBars then

    pInfo.dwFlags := pInfo.dwFlags or DOCHOSTUIFLAG_SCROLL_NO;

  if UIProperties.EnableFlatScrollBars then

    pInfo.dwFlags := pInfo.dwFlags or DOCHOSTUIFLAG_FLAT_SCROLLBAR;

  if not UIProperties.Enable3DBorder then

    pInfo.dwFlags := pInfo.dwFlags or DOCHOSTUIFLAG_NO3DBORDER;

  result := S_OK;

end;

 

function TWebBrowserWithUI.GetOptionKeyPath(var pchKey: POLESTR;

  const dw: DWORD): HRESULT;

begin

  result := S_FALSE;

end;

 

function TWebBrowserWithUI.HideUI: HRESULT;

begin

  result := S_FALSE;

end;

 

function TWebBrowserWithUI.OnDocWindowActivate(

  const fActivate: BOOL): HRESULT;

begin

  result := S_FALSE;

end;

 

function TWebBrowserWithUI.OnFrameWindowActivate(

  const fActivate: BOOL): HRESULT;

begin

  result := S_FALSE;

end;

 

function TWebBrowserWithUI.ResizeBorder(const prcBorder: PRECT;

  const pUIWindow: IOleInPlaceUIWindow; const fRameWindow: BOOL): HRESULT;

begin

  result := S_FALSE;

end;

 

function TWebBrowserWithUI.ShowContextMenu(const dwID: DWORD;

  const ppt: PPOINT; const pcmdtReserved: IUnknown;

  const pdispReserved: IDispatch): HRESULT;

begin

  if UIProperties.EnableContextMenu then

    result := S_FALSE

  else

    result := S_OK;

end;

 

function TWebBrowserWithUI.ShowUI(const dwID: DWORD;

  const pActiveObject: IOleInPlaceActiveObject;

  const pCommandTarget: IOleCommandTarget; const pFrame: IOleInPlaceFrame;

  const pDoc: IOleInPlaceUIWindow): HRESULT;

begin

  result := S_FALSE;

end;

 

function TWebBrowserWithUI.TranslateAccelerator(const lpMsg: PMSG;

  const pguidCmdGroup: PGUID; const nCmdID: DWORD): HRESULT;

begin

  result := S_FALSE;

end;

 

function TWebBrowserWithUI.TranslateUrl(const dwTranslate: DWORD;

  const pchURLIn: POLESTR; var ppchURLOut: POLESTR): HRESULT;

begin

  result := S_FALSE;

end;

 

function TWebBrowserWithUI.UpdateUI: HRESULT;

begin

  result := S_FALSE;

end;

end.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值