Delphi自带的WebBrowser是不含有滚动条设置的。下面的代码中加入了对滚动条的设置,如果是Delphi 7可以直接将下面的代码保存为pas文件进行安装,如果是2010则猛击此处下载我打包之后的控件包进行安装。 8) 安装之后可以通过上图的属性页面设置滚动条属性。 🙂
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | 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) ['{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; 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 = '{bd3f23c0-d43e-11CF-893b-00aa00bdce1a}'; 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. |
原创文章,转载请注明: 转载自 obaby@mars