embeddedwb.pas 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032
  1. unit EmbeddedWB;
  2. {$DEFINE USE_IOLECOMMANDTARGET}
  3. //***********************************************************
  4. // EmbeddedWb ver 1.17 (Jan. 1 , 2004) *
  5. // *
  6. // For Delphi 4, 5, 6 and 7 *
  7. // Freeware Component *
  8. // by *
  9. // Per Linds?Larsen *
  10. // per.lindsoe@larsen.mail.dk *
  11. // *
  12. // *
  13. // Contributors: *
  14. // *
  15. // Mathias Walter (walter@coint.de) *
  16. // - all messagehandling code *
  17. // *
  18. // Neil Moss (NeilM@BuchananInternational.com) *
  19. // - code for setting downloadoptions *
  20. // *
  21. // jezek1 *
  22. // - support for D7 (12/09/2002) *
  23. // *
  24. // Thomas Stutz *
  25. // *
  26. // - added THEME, NOTHEME, NOPICS, *
  27. // NO3DOUTERBORDER to TUserInterfaceOption *
  28. // (11/1/04) *
  29. // *
  30. // Documentation and updated versions: *
  31. // *
  32. // http://www.euromind.com/iedelphi *
  33. //***********************************************************
  34. interface
  35. uses
  36. Variants,
  37. IEConst, IEUtils, Registry, Windows, Messages, SysUtils, Classes, Graphics,
  38. Controls, Forms, Dialogs, EXTCtrls, OleCtrls, SHDocVw,
  39. ActiveX, shlObj, Wininet, Urlmon, shellapi, MSHTML;
  40. type
  41. {$IFDEF USE_IOLECOMMANDTARGET}
  42. TScriptErrorEvent = procedure(Sender: TObject; ErrorLine, ErrorCharacter, ErrorCode, ErrorMessage, ErrorUrl: string;
  43. var ContinueScript: Boolean; var Showdialog: Boolean) of object;
  44. TRefreshEvent = procedure(Sender: TObject; CmdID: Integer; var Cancel: Boolean) of object;
  45. TUnloadEvent = procedure(Sender: TObject) of object;
  46. {$ENDIF}
  47. TGetOverrideKeyPathEvent = function(pchKey: POLESTR; dw: DWORD): HRESULT of object;
  48. TShowContextMenuEvent = function(const dwID: DWORD; const ppt: PPOINT;
  49. const pcmdtReserved: IUnknown; const pdispReserved: IDispatch): HRESULT of object;
  50. TGetHostInfoEvent = function(var pInfo: TDOCHOSTUIINFO): HRESULT of object;
  51. TShowUIEvent = function(const dwID: DWORD; const pActiveObject: IOleInPlaceActiveObject;
  52. const pCommandTarget: IOleCommandTarget; const pFrame: IOleInPlaceFrame;
  53. const pDoc: IOleInPlaceUIWindow): HRESULT of object;
  54. THideUIEvent = function: HRESULT of object;
  55. TUpdateUIEvent = function: HRESULT of object;
  56. TEnableModelessEvent = function(const fEnable: BOOL): HRESULT of object;
  57. TOnDocWindowActivateEvent = function(const fActivate: BOOL): HRESULT of object;
  58. TOnFrameWindowActivateEvent = function(const fActivate: BOOL): HRESULT of object;
  59. TResizeBorderEvent = function(const prcBorder: PRECT;
  60. const pUIWindow: IOleInPlaceUIWindow;
  61. const fRameWindow: BOOL): HRESULT of object;
  62. TTranslateAcceleratorEvent = function(const lpMsg: PMSG; const pguidCmdGroup: PGUID;
  63. const nCmdID: DWORD): HRESULT of object;
  64. TGetOptionKeyPathEvent = function(var pchKey: POLESTR; const dw: DWORD): HRESULT of object;
  65. TGetDropTargetEvent = function(const pDropTarget: IDropTarget;
  66. out ppDropTarget: IDropTarget): HRESULT of object;
  67. TGetExternalEvent = function(out ppDispatch: IDispatch): HRESULT of object;
  68. TTranslateUrlEvent = function(const dwTranslate: DWORD; const pchURLIn: POLESTR;
  69. var ppchURLOut: POLESTR): HRESULT of object;
  70. TFilterDataObjectEvent = function(const pDO: IDataObject;
  71. out ppDORet: IDataObject): HRESULT of object;
  72. TShowMessageEvent = function(hwnd: THandle;
  73. lpstrText: POLESTR; lpstrCaption: POLESTR; dwType: longint; lpstrHelpFile: POLESTR;
  74. dwHelpContext: longint; var plResult: LRESULT): HRESULT of object;
  75. TShowHelpEvent = function(hwnd: THandle; pszHelpFile: POLESTR; uCommand: integer;
  76. dwData: longint; ptMouse: TPoint;
  77. var pDispatchObjectHit: IDispatch): HRESULT of object;
  78. TGetTypeInFoCountEvent = function(out Count: Integer): HResult of object;
  79. TGetTypeInfoEvent = function(Index, LocaleID: Integer; out TypeInfo: ITypeInfo): HResult of object;
  80. TGetIDsOfNamesEvent = function(const IID: TGUID; Names: Pointer;
  81. NameCount, LocaleID: Integer; DispIDs: Pointer): HResult of object;
  82. TInvokeEvent = function(DispID: Integer; const IID: TGUID; LocaleID: Integer;
  83. Flags: Word; var Params: TagDispParams; VarResult, ExcepInfo, ArgErr: Pointer): HResult of object;
  84. TQueryServiceEvent = function(const rsid, iid: TGuid; out Obj: IUnknown): HResult of object;
  85. TShowDialogEvent = procedure(Sender: TObject; h: THandle) of object;
  86. TDownloadControlOption = (DLCTL_DLIMAGES, DLCTL_VIDEOS, DLCTL_BGSOUNDS,
  87. DLCTL_NO_SCRIPTS, DLCTL_NO_JAVA, DLCTL_NO_RUNACTIVEXCTLS, DLCTL_NO_DLACTIVEXCTLS,
  88. DLCTL_DOWNLOADONLY, DLCTL_NO_FRAMEDOWNLOAD, DLCTL_RESYNCHRONIZE, DLCTL_PRAGMA_NO_CACHE,
  89. DLCTL_NO_BEHAVIORS, DLCTL_NO_METACHARSET, DLCTL_URL_ENCODING_DISABLE_UTF8,
  90. DLCTL_URL_ENCODING_ENABLE_UTF8, DLCTL_FORCEOFFLINE, DLCTL_NO_CLIENTPULL,
  91. DLCTL_SILENT, DLCTL_OFFLINE);
  92. TDownloadControlOptions = set of TDownloadControlOption;
  93. TUserInterfaceOption = (DIALOG, DISABLE_HELP_MENU, NO3DBORDER,
  94. SCROLL_NO, DISABLE_SCRIPT_INACTIVE, OPENNEWWIN,
  95. DISABLE_OFFSCREEN,
  96. FLAT_SCROLLBAR, DIV_BLOCKDEFAULT, ACTIVATE_CLIENTHIT_ONLY,
  97. OVERRIDEBEHAVIORFACTORY,
  98. CODEPAGELINKEDFONTS, URL_ENCODING_DISABLE_UTF8,
  99. URL_ENCODING_ENABLE_UTF8,
  100. ENABLE_FORMS_AUTOCOMPLETE, ENABLE_INPLACE_NAVIGATION,
  101. IME_ENABLE_RECONVERSION,
  102. THEME, NOTHEME, NOPICS, NO3DOUTERBORDER);
  103. TUserInterfaceOptions = set of TUserInterfaceOption;
  104. type
  105. TMeasure = (mMetric, mUS);
  106. TPrintOrientationOption = (poPortrait, poLandscape);
  107. TMargins = class(TPersistent)
  108. private
  109. FLeft: Real;
  110. FRight: Real;
  111. FTop: Real;
  112. FBottom: real;
  113. published
  114. property Left: Real read FLeft write FLeft;
  115. property Right: Real read FRight write FRight;
  116. property Top: Real read FTop write FTop;
  117. property Bottom: Real read FBottom write FBottom;
  118. end;
  119. TPrintOptions = class(TPersistent)
  120. private
  121. FHTMLHeader: TStrings;
  122. FHeader: string;
  123. FFooter: string;
  124. FMargins: TMargins;
  125. FOrientation: TPrintOrientationOption;
  126. FMeasure: TMeasure;
  127. procedure SetHTMLHeader(const Value: Tstrings);
  128. property Measure: TMeasure read FMeasure;
  129. published
  130. property Margins: TMargins read FMargins write FMargins;
  131. property Header: string read FHeader write FHeader;
  132. property HTMLHeader: TStrings read FHTMLHeader write SetHTMLHeader;
  133. property Footer: string read FFooter write FFooter;
  134. property Orientation: TPrintOrientationOption read FOrientation write FOrientation;
  135. end;
  136. TEmbeddedWB = class(TWebbrowser, IDocHostShowUI, IDocHostUIHandler,
  137. IDocHostUIHandler2, IDispatch, IServiceProvider
  138. {$IFDEF USE_IOLECOMMANDTARGET}, IOleCommandTarget{$ENDIF})
  139. private
  140. {$IFDEF VER120}
  141. SaveMessage: TMessageEvent;
  142. {$ENDIF}
  143. FUserAgent: string;
  144. FReplaceCaption: Boolean;
  145. FPrintOptions: TPrintOPtions;
  146. FDownloadControlOptions: TDownloadControlOptions;
  147. FUserInterfaceOptions: TUserInterfaceOptions;
  148. {$IFDEF USE_IOLECOMMANDTARGET}
  149. FOnUnload: TUnloadEvent;
  150. FOnRefresh: TRefreshEvent;
  151. FOnScriptError: TScriptErrorEvent;
  152. {$ENDIF}
  153. FOnGetOverrideKeyPath: TGetOverrideKeypathEvent;
  154. FOnShowContextMenu: TShowcontextmenuEvent;
  155. FOnGetHostInfo: TGetHostInfoEvent;
  156. FOnShowUI: TShowUIEvent;
  157. FOnHideUI: THideUIEvent;
  158. FOnUpdateUI: TUpdateUIEvent;
  159. FOnEnableModeless: TEnableModelessEvent;
  160. FOnOnDocWindowActivate: TOnDocWindowActivateEvent;
  161. FOnOnFrameWindowActivate: TOnFrameWindowActivateEvent;
  162. FOnResizeBorder: TResizeBorderEvent;
  163. FOnTranslateAccelerator: TTranslateAcceleratorEvent;
  164. FOnGetOptionKeyPath: TGetOptionKeyPathEvent;
  165. FOnGetDropTarget: TGetDropTargetEvent;
  166. FOnGetExternal: TGetExternalEvent;
  167. FOnTranslateUrL: TTranslateUrlEvent;
  168. FOnFilterDataObject: TFilterDataObjectEvent;
  169. FHelpFile: string;
  170. FOnShowMessage: TShowMessageEvent;
  171. FOnShowHelp: TShowHelpEvent;
  172. FOnGetTypeInfoCount: TGetTypeInfoCountEvent;
  173. FOnGetTypeInfo: TGetTypeInfoEvent;
  174. FOnGetIDsOfNames: TGetIDsOfNamesEvent;
  175. FOnInvoke: TInvokeEvent;
  176. FOnQueryService: TQueryServiceEvent;
  177. FOldWindowProc: TWndMethod;
  178. FParentForm: TForm;
  179. FDownloadOptionValue: Longint;
  180. FUserInterfaceValue: Cardinal;
  181. FOnCloseQuery: TCloseQueryEvent;
  182. FOnShowDialog: TShowDialogEvent;
  183. OldWBWndProc: TWndMethod;
  184. RuntimeMeasure: TMeasure;
  185. DDEHWnd: THandle;
  186. FEnableDDE: Boolean;
  187. FfpExceptions: Boolean;
  188. procedure SetUserAgent;
  189. procedure RemoveUserAgent;
  190. procedure GetPrintValues;
  191. procedure Hook;
  192. procedure UnHook;
  193. procedure FormWndProc(var AMsg: TMessage);
  194. procedure DDEWndProc(var AMsg: TMessage);
  195. procedure WBWndProc(var Message: TMessage);
  196. procedure SetDownloadOptions(const Value: TDownloadControlOptions);
  197. procedure SetUserInterfaceOptions(const Value: TUserInterfaceOptions);
  198. procedure SetfpExceptions(const Value: Boolean);
  199. procedure UpdateDownloadControlValue;
  200. procedure UpdateUserInterfaceValue;
  201. protected
  202. function DDETerminate(iwParam: WPARAM; ilParam: LPARAM): BOOL;
  203. function DDEInitiate(iwParam: WPARAM; ilParam: LPARAM): LRESULT;
  204. function DDEExecute(iwParam: WPARAM; ilParam: LPARAM): LRESULT;
  205. function GetOverrideKeyPath(pchKey: POLESTR; dw: DWORD): HRESULT; stdcall;
  206. {$IFDEF USE_IOLECOMMANDTARGET}
  207. function QueryStatus(CmdGroup: PGUID; cCmds: Cardinal;
  208. prgCmds: POleCmd; CmdText: POleCmdText): HResult; stdcall;
  209. function Exec(CmdGroup: PGUID; nCmdID, nCmdexecopt: DWORD;
  210. const vaIn: OleVariant; var vaOut: OleVariant): HResult; stdcall;
  211. {$ENDIF}
  212. function ShowContextMenu(const dwID: DWORD; const ppt: PPOINT;
  213. const pcmdtReserved: IUnknown; const pdispReserved: IDispatch): HRESULT; stdcall;
  214. function GetHostInfo(var pInfo: TDOCHOSTUIINFO): HRESULT; stdcall;
  215. function ShowUI(const dwID: DWORD; const pActiveObject: IOleInPlaceActiveObject;
  216. const pCommandTarget: IOleCommandTarget; const pFrame: IOleInPlaceFrame;
  217. const pDoc: IOleInPlaceUIWindow): HRESULT; stdcall;
  218. function HideUI: HRESULT; stdcall;
  219. function UpdateUI: HRESULT; stdcall;
  220. function EnableModeless(const fEnable: BOOL): HRESULT; stdcall;
  221. function OnDocWindowActivate(const fActivate: BOOL): HRESULT; stdcall;
  222. function OnFrameWindowActivate(const fActivate: BOOL): HRESULT; stdcall;
  223. function ResizeBorder(const prcBorder: PRECT;
  224. const pUIWindow: IOleInPlaceUIWindow;
  225. const FrameWindow: BOOL): HRESULT; stdcall;
  226. function TranslateAccelerator(const lpMsg: PMSG; const pguidCmdGroup: PGUID;
  227. const nCmdID: DWORD): HRESULT; stdcall;
  228. function GetOptionKeyPath(var pchKey: POLESTR; const dw: DWORD): HRESULT; stdcall;
  229. function GetDropTarget(const pDropTarget: IDropTarget;
  230. out ppDropTarget: IDropTarget): HRESULT; stdcall;
  231. function GetExternal(out ppDispatch: IDispatch): HRESULT; stdcall;
  232. function TranslateUrl(const dwTranslate: DWORD; const pchURLIn: POLESTR;
  233. var ppchURLOut: POLESTR): HRESULT; stdcall;
  234. function FilterDataObject(const pDO: IDataObject;
  235. out ppDORet: IDataObject): HRESULT; stdcall;
  236. function ShowMessage(hwnd: THandle;
  237. lpstrText: POLESTR; lpstrCaption: POLESTR; dwType: longint; lpstrHelpFile: POLESTR;
  238. dwHelpContext: longint; var plResult: LRESULT): HRESULT; stdcall;
  239. function ShowHelp(hwnd: THandle; pszHelpFile: POLESTR; uCommand: integer;
  240. dwData: longint; ptMouse: TPoint;
  241. var pDispatchObjectHit: IDispatch): HRESULT; stdcall;
  242. function GetTypeInfoCount(out Count: Integer): HResult; stdcall;
  243. function GetTypeInfo(Index, LocaleID: Integer; out TypeInfo): HResult; stdcall;
  244. function GetIDsOfNames(const IID: TGUID; Names: Pointer;
  245. NameCount, LocaleID: Integer; DispIDs: Pointer): HResult; stdcall;
  246. function Invoke(DispID: Integer; const IID: TGUID; LocaleID: Integer;
  247. Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer): HResult; stdcall;
  248. {$IFDEF VER120}
  249. procedure IEMessageHandler(var Msg: TMsg; var Handled: Boolean);
  250. {$ENDIF}
  251. function QueryService(const rsid, iid: TGuid; out Obj): HResult; stdcall;
  252. function OpenClient(Client: string): Boolean;
  253. function PrintMarginStr(M: Real): PChar;
  254. public
  255. SecurityManager: IInternetSecurityManager;
  256. ZoneManager: IInternetZoneManager;
  257. function ShowMailClient: Boolean;
  258. function ShowNewsClient: Boolean;
  259. function ShowAddressBook: Boolean;
  260. function ShowCalendar: Boolean;
  261. function ShowInternetCall: Boolean;
  262. procedure AssignDocument;
  263. procedure SetFocusToDoc;
  264. procedure InvokeCMD(InvokeIE: Boolean; Value1, Value2: Integer; var vaIn, vaOut: OleVariant);
  265. procedure Go(Url: string);
  266. procedure Print;
  267. procedure OpenDialog;
  268. procedure SaveDialog;
  269. procedure PrintSetup;
  270. procedure PageSetup(UsePrintOptions: Boolean);
  271. procedure ViewSource;
  272. procedure Properties;
  273. procedure Options;
  274. procedure Find;
  275. {$IFDEF VER120}
  276. procedure EnableMessagehandler;
  277. procedure DisableMessagehandler;
  278. {$ENDIF}
  279. procedure Copy;
  280. procedure SelectAll;
  281. procedure Zoom(ZoomValue: Integer);
  282. function ZoomRangeHigh: Integer;
  283. function ZoomRangeLow: Integer;
  284. function ZoomValue: Integer;
  285. procedure NavigatePidl(pidl: PItemIdlist);
  286. procedure NavigateFolder(CSIDL: Integer);
  287. procedure SetGlobalOffline(Value: Boolean);
  288. function IsGlobalOffline: boolean;
  289. // function LoadFrameFromStrings(Frameno: Integer; const AStrings: TStrings): HResult;
  290. // function LoadFrameFromStream(FrameNo: Integer; AStream: TStream): HRESULT;
  291. // function SaveFrameToFile(FrameNo: Integer; const Fname: string): HRESULT;
  292. // function SaveFrameToStream(FrameNo: Integer; AStream: TStream): HRESULT;
  293. // function SaveFrameToStrings(FrameNo: Integer; AStrings: TStrings): HRESULT;
  294. function LoadFromStream(const AStream: TStream): HRESULT;
  295. function LoadFromStrings(const AStrings: TStrings): HRESULT;
  296. function SaveToStrings(AStrings: TStrings): HRESULT;
  297. function SaveToStream(AStream: TStream): HRESULT;
  298. function SaveToFile(const Fname: string): HRESULT;
  299. constructor Create(Owner: TComponent); override;
  300. procedure Loaded; override;
  301. destructor Destroy; override;
  302. procedure PrintPreView;
  303. procedure PrintWithOptions;
  304. // function GetFrame(FrameNo: Integer): IWebbrowser2;
  305. // function FrameCount: LongInt;
  306. procedure GetThumbnail(var Image: TImage);
  307. procedure ClearHistory;
  308. procedure ClearCache;
  309. published
  310. property DownloadOptions: TDownloadControlOptions read FDownloadControlOptions write SetDownloadOptions;
  311. property UserInterfaceOptions: TUserInterfaceOptions read FUserInterfaceOptions write SetUserInterfaceOptions;
  312. {$IFDEF USE_IOLECOMMANDTARGET}
  313. property OnRefresh: TRefreshEvent read FOnRefresh write FOnRefresh;
  314. property OnScriptError: TScriptErrorEvent read FOnScriptError write FOnScriptError;
  315. property OnUnload: TUnloadEvent read FOnUnload write FOnUnload;
  316. {$ENDIF}
  317. property OnGetOverrideKeyPath: TGetOVerrideKeypathEvent read FOnGetOverrideKeyPath write FOnGetOverrideKeyPath;
  318. property OnShowContextMenu: TShowContextMenuEvent read FOnShowContextmenu write FOnShowContextmenu;
  319. property OnGetHostInfo: TGetHostInfoEvent read FOnGethostinfo write fongethostinfo;
  320. property OnShowUI: TShowUIEvent read FOnShowUI write FOnShowUI;
  321. property OnHideUI: THideUIEvent read FOnHideUI write FOnHideUI;
  322. property OnUpdateUI: TUpdateUIEvent read FOnUpdateUI write FOnUpdateUI;
  323. property OnEnableModeless: TEnableModelessEvent read FOnEnableModeless write FOnEnableModeless;
  324. property OnOnDocWindowActivate: TOnDocWindowActivateEvent read FOnOnDocWindowActivate write FOnOnDocWindowActivate;
  325. property OnOnFrameWindowActivate: TOnFrameWindowActivateEvent read FOnOnFrameWindowActivate write FOnOnFrameWindowActivate;
  326. property OnResizeBorder: TResizeBorderEvent read FOnResizeBorder write FOnResizeBorder;
  327. property OnTranslateAccelerator: TTranslateAcceleratorEvent read FOnTranslateAccelerator write FOnTranslateAccelerator;
  328. property OnGetOptionKeyPath: TGetOptionKeyPathEvent read FOnGetOptionKeyPath write FOnGetOptionKeyPath;
  329. property OnGetDropTarget: TGetDropTargetEvent read FOnGetDropTarget write FOnGetDropTarget;
  330. property OnGetExternal: TGetExternalEvent read FOnGetExternal write FOnGetExternal;
  331. property OnTranslateUrl: TTranslateUrlEvent read FOnTranslateUrL write FOnTranslateUrL;
  332. property OnFilterDataObject: TFilterDataObjectEvent read FOnFilterDataObject write FOnFilterDataObject;
  333. property HelpFile: string read FHelpFile write FHelpFile;
  334. property OnShowMessage: TShowMessageEvent read FOnShowMessage write FOnShowMessage;
  335. property OnShowHelp: TShowHelpEvent read FOnShowHelp write FOnShowHelp;
  336. property OnGetTypeInfoCount: TGetTypeInfoCountEvent read FonGetTypeInfoCount write FOnGetTypeInfoCount;
  337. property OnGetTypeInfo: TGetTypeInfoEvent read FonGetTypeInfo write FOnGetTypeInfo;
  338. property OnGetIDsOfNames: TGetIDsOfNamesEvent read FOnGetIDsOfNames write FOnGetIdsOfNames;
  339. property OnInvoke: TInvokeEvent read FOnInvoke write FOnInvoke;
  340. property OnQueryService: TQueryServiceEvent read FOnQueryService write FOnQueryService;
  341. property OnCloseQuery: TCloseQueryEvent read FOnCloseQuery write FOnCloseQuery;
  342. property OnShowDialog: TShowDialogEvent read FOnShowDialog write FOnShowDialog;
  343. property PrintOptions: TPrintOptions read FPrintOptions write FPrintOptions;
  344. property UserAgent: string read FUserAgent write FUserAgent;
  345. property ReplaceCaption: Boolean read FReplaceCaption write FReplaceCaption;
  346. property EnableDDE: Boolean read FEnableDDE write FEnableDDE;
  347. property fpExceptions: Boolean read FfpExceptions write SetfpExceptions;
  348. end;
  349. function RegisterMIMEFilter(clsid: TGUID; MIME: PWideChar): HRESULT;
  350. function UnregisterMIMEFilter(MIME: PWideChar): HRESULT;
  351. function RegisterNameSpace(clsid: TGUID): HRESULT;
  352. function UnregisterNameSpace: HRESULT;
  353. procedure Register;
  354. implementation
  355. uses
  356. comobj;
  357. var
  358. Saved8087CW: Word;
  359. PrintingWithOptions: Boolean;
  360. InvokingPagesetup: Boolean;
  361. MimeFactory, NSFactory: IClassFactory;
  362. MimeInternetSession, NSInternetSession: IInternetSession;
  363. DontRespond: Boolean;
  364. OpenFolder, ExploreFolder: string;
  365. FoldersApp, FoldersTopic: string;
  366. FindFolder: string;
  367. HtmlFileApp, HtmlFileTopic: string;
  368. fHtmlCommand: Boolean;
  369. {$IFDEF VER120}
  370. bMsgHandler: Boolean;
  371. {$ENDIF}
  372. procedure TEmbeddedWB.GetThumbnail(var Image: TImage);
  373. var
  374. DrawRect: TRect;
  375. begin
  376. if Image = nil then exit;
  377. DrawRect := Rect(0, 0, Image.Height, Image.width);
  378. Image.Picture.Bitmap.Height := image.height;
  379. Image.Picture.Bitmap.Width := image.Width;
  380. ({$IFDEF VER120}Application_{$ELSE}Application{$ENDIF} as IviewObject).Draw(DVASPECT_DOCPRINT, 0, nil, nil, 0,
  381. image.Canvas.Handle, @DrawRect, nil, nil, 0);
  382. Image.Refresh;
  383. end;
  384. procedure TEmbeddedWB.SetfpExceptions(const Value: Boolean);
  385. begin
  386. if not Value then begin
  387. Set8087CW($133F);
  388. FfpExceptions := False;
  389. end
  390. else
  391. begin
  392. Set8087CW(Saved8087CW);
  393. FfpExceptions := True;
  394. end;
  395. end; {
  396. function TEmbeddedwb.GetFrame(FrameNo: Integer): IWebbrowser2;
  397. var
  398. OleContainer: IOleContainer;
  399. enum: IEnumUnknown;
  400. unk: IUnknown;
  401. Fetched: PLongint;
  402. begin
  403. while ReadyState <> READYSTATE_COMPLETE do
  404. Forms.Application.ProcessMessages;
  405. if Assigned(document) then
  406. begin
  407. Fetched := nil;
  408. OleContainer := Document as IOleContainer;
  409. OleContainer.EnumObjects(OLECONTF_EMBEDDINGS, Enum);
  410. Enum.Skip(FrameNo);
  411. Enum.Next(1, Unk, Fetched);
  412. Result := Unk as IWebbrowser2;
  413. end else Result := nil;
  414. end;
  415. }
  416. {
  417. Ver. 1.16:
  418. Thanks to Brian Lowe for Fixing OLE-problem in function FrameCount:
  419. http://groups.yahoo.com/group/delphi-webbrowser/message/4194
  420. } {
  421. function TEmbeddedWB.FrameCount: LongInt;
  422. var
  423. OleContainer: IOleContainer;
  424. enum: IEnumUnknown;
  425. unk: array[0..99] of IUnknown; // CHANGED from "unk: IUnknown;"
  426. EnumResult: HRESULT;
  427. begin
  428. while ReadyState <> READYSTATE_COMPLETE do
  429. Forms.Application.ProcessMessages;
  430. if Assigned(document) then
  431. begin
  432. OleContainer := Document as IOleContainer;
  433. EnumResult := OleContainer.EnumObjects(OLECONTF_EMBEDDINGS, Enum);
  434. if EnumResult = S_OK then // Added per OLE help
  435. Enum.Next(100, Unk, @Result)
  436. else // Added per OLE help
  437. Enum := nil;
  438. end else
  439. Result := 0;
  440. end; }
  441. procedure TEmbeddedWB.SetUserAgent;
  442. var
  443. reg: TRegistry;
  444. begin
  445. Reg := TRegistry.Create;
  446. try
  447. Reg.RootKey := HKEY_CURRENT_USER;
  448. if Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Internet Settings\User Agent\Post Platform', True)
  449. then Reg.WriteString(FUserAgent, '');
  450. finally
  451. Reg.CloseKey;
  452. Reg.Free;
  453. end;
  454. end;
  455. procedure TEmbeddedWB.RemoveUserAgent;
  456. var
  457. reg: TRegistry;
  458. begin
  459. Reg := TRegistry.Create;
  460. try
  461. Reg.RootKey := HKEY_CURRENT_USER;
  462. if Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Internet Settings\User Agent\Post Platform', FALSE)
  463. then reg.DeleteValue(FUseragent);
  464. finally
  465. Reg.CloseKey;
  466. Reg.Free;
  467. end;
  468. end;
  469. function GetDDEVariables: Boolean;
  470. var
  471. s: string;
  472. Reg: TRegistry;
  473. begin
  474. Reg := Tregistry.Create;
  475. with Reg do try
  476. RootKey := HKEY_CLASSES_ROOT;
  477. OpenKey('htmlfile\shell\open\ddeexec\application', False);
  478. HtmlFileApp := Readstring('');
  479. CloseKey;
  480. OpenKey('htmlfile\shell\open\ddeexec\topic', FALSE);
  481. HtmlFileTopic := ReadString('');
  482. CloseKey;
  483. OpenKey('Folder\shell\open\ddeexec\application', False);
  484. FoldersApp := Readstring('');
  485. CloseKey;
  486. OpenKey('Folder\shell\open\ddeexec\topic', FALSE);
  487. FoldersTopic := ReadString('');
  488. CloseKey;
  489. OpenKey('Folder\shell\open\ddeexec', False);
  490. s := readString('');
  491. CloseKey;
  492. S := Copy(S, Pos('[', S) + 1, length(S));
  493. OpenFolder := Copy(s, 1, Pos('(', S) - 1);
  494. OpenKey('Folder\shell\explore\ddeexec', False);
  495. s := readString('');
  496. CloseKey;
  497. S := Copy(S, Pos('[', S) + 1, length(S));
  498. ExploreFolder := Copy(s, 1, Pos('(', S) - 1);
  499. OpenKey('Directory\shell\find\ddeexec', False);
  500. s := readString('');
  501. CloseKey;
  502. S := Copy(S, Pos('[', S) + 1, length(S));
  503. FindFolder := Copy(s, 1, Pos('(', S) - 1);
  504. Result := True;
  505. except
  506. Result := False;
  507. end;
  508. Reg.Free;
  509. end;
  510. function GetCommandTypeFromDDEString(szCommand: string): UINT;
  511. begin
  512. szCommand := Copy(szCommand, Pos('[', szCommand) + 1, length(szCommand));
  513. szCommand := Copy(szCommand, 1, Pos('(', szCommand) - 1);
  514. if szCommand = Openfolder then Result := VIEW_COMMAND else
  515. if szCommand = Explorefolder then Result := EXPLORE_COMMAND else
  516. if szCommand = Findfolder then Result := FIND_COMMAND else
  517. Result := NO_COMMAND;
  518. end;
  519. function GetPathFromDDEString(szCommand: string; var szFolder: string): Boolean;
  520. begin
  521. szCommand := Copy(szCommand, Pos('"', szCommand) + 1, length(szCommand));
  522. szFolder := Copy(szCommand, 1, Pos('"', szCommand) - 1);
  523. Result := (szFolder <> '');
  524. end;
  525. function GetPidlFromDDEString(szCommand: string): PItemIDList;
  526. var
  527. pidlShared, pidlGlobal: PItemIDList;
  528. dwProcessID: Integer;
  529. hShared: THandle;
  530. s: string;
  531. ProcessID: string;
  532. i: Integer;
  533. begin
  534. s := Copy(szCommand, Pos(',', szCommand) + 1, length(szCommand));
  535. i := 1;
  536. while not (s[i] in IsDigit) and (i <= Length(s)) do Inc(i);
  537. processID := Copy(s, i, Length(S));
  538. s := copy(S, i, length(s) - 1);
  539. i := 1;
  540. while (s[i] in IsDigit) and (i <= Length(s)) do Inc(i);
  541. s := copy(S, 1, i - 1);
  542. while not ((ProcessID[i] = ':') or (ProcessID[i] = ',')) and (i <= Length(processID)) do Inc(i);
  543. if ProcessID[i] = ':' then
  544. begin
  545. ProcessID := Copy(ProcessID, i, Length(ProcessID));
  546. i := 1;
  547. while not (ProcessID[i] in IsDigit) and (i <= Length(ProcessID)) do Inc(i);
  548. ProcessID := Copy(ProcessID, i, Length(ProcessID));
  549. i := 1;
  550. while (ProcessID[i] in IsDigit) and (i <= Length(ProcessID)) do Inc(i);
  551. if not (ProcessID[i] in IsDigit) then ProcessID := Copy(ProcessID, 1, i - 1);
  552. end else ProcessID := '0';
  553. dwProcessID := StrToInt(ProcessID);
  554. if dwProcessID <> 0 then begin
  555. hShared := StrToInt(s);
  556. pidlShared := ShLockShared(hShared, dwProcessId);
  557. if PidlShared <> nil then
  558. begin
  559. Result := CopyPidl(PidlShared);
  560. ShUnlockShared(pidlShared);
  561. end else Result := nil;
  562. ShFreeShared(hShared, dwProcessID);
  563. end else
  564. begin
  565. pidlGlobal := PItemIDList(StrToInt(s));
  566. Result := CopyPidl(pidlGlobal);
  567. _Free(pidlGlobal);
  568. end;
  569. end;
  570. function GetShowCmdFromDDEString(szCommand: string): Integer;
  571. var
  572. i: Integer;
  573. begin
  574. i := 1;
  575. while szCommand[i] <> ',' do Inc(i);
  576. Inc(i);
  577. while szCommand[i] <> ',' do Inc(i);
  578. szCommand := Copy(szCommand, i, Length(szCommand));
  579. i := 0;
  580. repeat
  581. inc(i)
  582. until (i > Length(szCommand)) or (szCommand[i] in IsDigit);
  583. if i <= length(szCommand) then result := StrtoInt(szCommand[i]) else
  584. result := 1;
  585. end;
  586. function ParseDDECommand(szCommand: string; var szFolder: string; var pidl: PItemIDList; var show: Integer): UINT;
  587. begin
  588. Result := GetCommandTypeFromDDEString(szCommand);
  589. if Result <> NO_COMMAND then begin
  590. GetPathFromDDEString(szCommand, szFolder);
  591. pidl := GetPidlFromDDEString(szCommand);
  592. Show := GetShowCmdFromDDEString(szCommand);
  593. end;
  594. end;
  595. function TEmbeddedwb.DDETerminate(iwParam: WPARAM; ilParam: LPARAM): BOOL;
  596. begin
  597. Result := PostMessage(THandle(iwParam), WM_DDE_TERMINATE, handle, 0);
  598. end;
  599. function TEmbeddedWB.DDEInitiate(iwParam: WPARAM; ilParam: LPARAM): LRESULT;
  600. var
  601. dwThreadID: DWORD;
  602. dwProcessID: DWORD;
  603. hwndClient: Integer;
  604. aInApp,
  605. aInTopic,
  606. aOutApp,
  607. aOutTopic: ATOM;
  608. szInAppName,
  609. szInAppTopic: array[0..255] of Char;
  610. begin
  611. FillChar(szInAppName, SizeOf(szInAppName), 0);
  612. FillChar(szInAppTopic, SizeOf(szInAppTopic), 0);
  613. if DontRespond then
  614. begin
  615. result := 0;
  616. exit;
  617. end;
  618. hwndClient := THandle(iwParam);
  619. dwThreadID := GetWindowThreadProcessId(hwndClient, @dwProcessID);
  620. if (GetCurrentProcessId() <> dwProcessID) or (GetCurrentThreadID() <> dwThreadID) then
  621. begin
  622. result := 0;
  623. exit;
  624. end;
  625. aInApp := LOWORD(ilParam);
  626. aInTopic := HIWORD(ilParam);
  627. GlobalGetAtomName(aInApp, szInAppName, SizeOf(szInAppName));
  628. GlobalGetAtomName(aInTopic, szInAppTopic, SizeOf(szInAppTopic));
  629. if szInAppName = HtmlFileApp then
  630. begin
  631. fHtmlCommand := True;
  632. aOutApp := GlobalAddAtom(PChar(HtmlFileApp));
  633. aOutTopic := GlobalAddAtom(PChar(HtmlFileTopic));
  634. if ((aOutApp <> 0) and (aOutTopic <> 0) and (aOutApp = aInApp) and (aOutTopic = aInTopic)) then
  635. SendMessage(hwndClient, WM_DDE_ACK, WPARAM(handle), MAKELPARAM(aOutApp, aOutTopic));
  636. if (aOutApp <> 0) then GlobalDeleteAtom(aOutApp);
  637. if (aOutTopic <> 0) then GlobalDeleteAtom(aOutTopic);
  638. end
  639. else
  640. begin
  641. fHtmlCommand := False;
  642. aOutApp := GlobalAddAtom(PChar(FoldersApp));
  643. aOutTopic := GlobalAddAtom(PChar(FoldersTopic));
  644. if ((aOutApp <> 0) and (aOutTopic <> 0) and (aOutApp = aInApp) and (aOutTopic = aInTopic)) then
  645. SendMessage(HWNDClient, WM_DDE_ACK, WPARAM(Handle), MAKELPARAM(aOutApp, aOutTopic));
  646. if (aOutApp <> 0) then GlobalDeleteAtom(aOutApp);
  647. if (aOutTopic <> 0) then GlobalDeleteAtom(aOutTopic);
  648. end;
  649. result := 0;
  650. end;
  651. function TEmbeddedwb.DDEExecute(iwParam: WPARAM; ilParam: LPARAM): LRESULT;
  652. var
  653. szFolder: string;
  654. szCommand: LPTSTR;
  655. uLo: PUINT;
  656. hgMem: HGLOBAL;
  657. ack: DDEACK;
  658. lpTemp: PUINT;
  659. uCommand: Cardinal;
  660. show: Integer;
  661. pidl: PITEMIDLIST;
  662. sei: TShellExecuteInfo;
  663. szTmp: string;
  664. begin
  665. ulo := nil;
  666. if UnpackDDElParam(WM_DDE_EXECUTE, ilParam, uLo, @hgMem)
  667. then begin
  668. szCommand := GlobalLock(hgmem);
  669. ZeroMemory(@Ack, sizeof(ddeAck));
  670. if (szCommand <> nil) then
  671. begin
  672. if fHtmlCommand then
  673. begin
  674. szTmp := szCommand;
  675. if Pos('"', szTmp) = 1 then
  676. begin
  677. Delete(szTmp, 1, 1);
  678. szTmp := System.Copy(szTmp, 1, Pos('"', szTmp) - 1);
  679. end;
  680. Go(szTmp);
  681. Ack.flags := 1;
  682. end
  683. else
  684. begin
  685. uCommand := ParseDDECommand(szCommand, szFolder, pidl, Show);
  686. case uCommand of
  687. VIEW_COMMAND:
  688. begin
  689. if (szFolder <> '') then Go(szFolder)
  690. else
  691. if (pidl <> nil) then NavigatePidl(pidl);
  692. DisposePidl(pidl);
  693. Ack.flags := 1;
  694. end;
  695. EXPLORE_COMMAND:
  696. begin
  697. DontRespond := TRUE;
  698. ZeroMemory(@sei, sizeof(SHELLEXECUTEINFO));
  699. sei.cbSize := sizeof(SHELLEXECUTEINFO);
  700. if szFolder <> '' then begin
  701. sei.fMask := SEE_MASK_CLASSNAME;
  702. sei.lpFile := Pchar(szFolder);
  703. end else
  704. begin
  705. sei.fMask := SEE_MASK_IDLIST or SEE_MASK_CLASSNAME;
  706. sei.lpIDList := pidl;
  707. end;
  708. sei.lpClass := 'folder';
  709. sei.Wnd := 0;
  710. sei.nShow := Show;
  711. sei.lpVerb := 'explore';
  712. ShellExecuteEx(@sei);
  713. DontRespond := FALSE;
  714. DisposePidl(pidl);
  715. Ack.flags := 1;
  716. end;
  717. FIND_COMMAND:
  718. begin
  719. DontRespond := TRUE;
  720. ZeroMemory(@sei, sizeof(SHELLEXECUTEINFO));
  721. sei.cbSize := sizeof(SHELLEXECUTEINFO);
  722. if (szFolder <> '')
  723. then begin
  724. sei.fMask := 0;
  725. sei.lpFile := PChar(szFolder);
  726. end
  727. else
  728. begin
  729. sei.fMask := SEE_MASK_IDLIST;
  730. sei.lpIDList := pidl;
  731. end;
  732. sei.wnd := 0;
  733. sei.nShow := Show;
  734. sei.lpVerb := 'find';
  735. ShellExecuteEx(@sei);
  736. DontRespond := FALSE;
  737. DisposePidl(pidl);
  738. Ack.flags := 1;
  739. end;
  740. end;
  741. end;
  742. GlobalUnlock(hgMem);
  743. lpTemp := @Ack;
  744. PostMessage(Thandle(iwParam),
  745. WM_DDE_ACK,
  746. WPARAM(handle),
  747. ReuseDDElParam(ilParam, WM_DDE_EXECUTE, WM_DDE_ACK, lpTemp^, hgMem));
  748. end;
  749. end;
  750. Result := 0;
  751. end;
  752. procedure TEmbeddedwb.PrintWithOptions;
  753. begin
  754. PrintingWithOptions := True;
  755. Pagesetup(TRUE);
  756. Print;
  757. end;
  758. procedure TembeddedWB.GetPrintValues;
  759. var
  760. S: string;
  761. regWinRegistry: TRegistry;
  762. function ReadMargin(key: string): Real;
  763. begin
  764. S := RegwinRegistry.ReadString(key);
  765. S := Stringreplace(S, ' ', '', [rfReplaceAll]);
  766. if DecimalSeparator <> '.' then
  767. S := Stringreplace(S, '.', DecimalSeparator, []);
  768. if Printoptions.Measure = mMetric then
  769. result := StrtoFloatDef(S, 0.75) * InchToMetric else
  770. result := StrtoFloatDef(S, 0.75);
  771. end;
  772. begin
  773. regWinRegistry := TRegistry.Create;
  774. try
  775. with regWinRegistry do begin
  776. RootKey := HKEY_CURRENT_USER;
  777. if OpenKey('Software\Microsoft\Internet Explorer\PageSetup', False) then
  778. begin
  779. PrintOptions.Header := Readstring('header');
  780. PrintOptions.Footer := ReadString('footer');
  781. PrintOptions.Margins.left := ReadMargin('margin_left');
  782. PrintOptions.Margins.right := ReadMargin('margin_right');
  783. PrintOptions.Margins.top := ReadMargin('margin_top');
  784. PrintOptions.Margins.bottom := ReadMargin('margin_bottom');
  785. end;
  786. end;
  787. finally
  788. regWinRegistry.Free;
  789. end;
  790. end;
  791. procedure TEmbeddedWB.Loaded;
  792. begin
  793. inherited Loaded;
  794. CoInternetCreateSecuritymanager(self, SecurityManager, 0);
  795. CoInternetCreateZoneManager(self, ZoneManager, 0);
  796. UpdateDownloadControlValue;
  797. UpdateUserInterfaceValue;
  798. hook;
  799. if not (csDesigning in ComponentState) then
  800. begin
  801. OldWBWndProc := WindowProc;
  802. WindowProc := WBWndProc;
  803. SetUserAgent;
  804. end else
  805. begin
  806. PrintOptions.FMeasure := RunTimeMeasure;
  807. GetPrintValues;
  808. end;
  809. end;
  810. function TEmbeddedWB.PrintMarginStr(M: Real): PChar;
  811. var
  812. S: string;
  813. begin
  814. if printOptions.Measure <> RuntimeMeasure
  815. then begin
  816. if RuntimeMeasure = mMetric then
  817. s := FloatToStr(M * InchToMetric) else
  818. s := FloatToStr(M / InchToMetric);
  819. if s = '' then
  820. s := '1.00';
  821. Result := PChar(S);
  822. end else Result := PChar(FloatToStr(M));
  823. end;
  824. constructor TEmbeddedWb.Create(Owner: TComponent);
  825. var
  826. Buf: array[1..10] of Char;
  827. begin
  828. FfpExceptions := True;
  829. inherited;
  830. {$IFDEF VER120}
  831. enablemessagehandler;
  832. {$ENDIF}
  833. GetDDEVariables;
  834. DDEHWnd := AllocateHWnd(DDEWndProc);
  835. FPrintOptions := TPrintOptions.Create;
  836. FPrintOptions.Margins := TMargins.Create;
  837. FPrintOptions.FHTMLHeader := TStringlist.Create;
  838. FPrintOptions.FHTMLHeader.Add('<HTML></HTML>');
  839. FillChar(Buf, SizeOf(Buf), 0);
  840. GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IMEASURE, @Buf[1], SizeOf(Buf));
  841. if Buf[1] = '1' then RunTimeMeasure := mUS else
  842. RunTimeMeasure := mMetric;
  843. DownloadOptions := [DLCTL_DLIMAGES, DLCTL_BGSOUNDS, DLCTL_VIDEOS];
  844. UserInterfaceOptions := [];
  845. FEnableDDE := False;
  846. end;
  847. destructor TEmbeddedWb.Destroy;
  848. begin
  849. DeAllocateHWnd(DDEHwnd);
  850. FPrintOptions.HTMLHeader.Free;
  851. FPrintoptions.Margins.Free;
  852. FPrintoptions.Free;
  853. unhook;
  854. RemoveUserAgent;
  855. {$IFDEF VER120}
  856. disablemessagehandler;
  857. {$ENDIF}
  858. inherited;
  859. end;
  860. function RegisterMIMEFilter(clsid: TGUID; MIME: PWideChar): HRESULT;
  861. begin
  862. CoGetClassObject(Clsid, CLSCTX_SERVER, nil, IClassFactory, MimeFactory);
  863. CoInternetGetSession(0, MimeInternetSession, 0);
  864. Result := MIMEInternetSession.RegisterMimeFilter(MimeFactory, Clsid, MIME);
  865. end;
  866. function UnregisterMIMEFilter(MIME: PWideChar): HRESULT;
  867. begin
  868. Result := MIMEInternetSession.UnregisterMimeFilter(MIMEFactory, MIME);
  869. end;
  870. function RegisterNameSpace(clsid: TGUID): HRESULT;
  871. begin
  872. CoGetClassObject(Clsid, CLSCTX_SERVER, nil, IClassFactory, NSFactory);
  873. CoInternetGetSession(0, NSInternetSession, 0);
  874. Result := NSInternetSession.RegisterNameSpace(NSFactory, Clsid, 'http', 0, nil, 0);
  875. end;
  876. function UnregisterNameSpace: HRESULT;
  877. begin
  878. Result := NSInternetSession.UnregisterNameSpace(NSFactory, 'http');
  879. end;
  880. procedure TEmbeddedWB.Hook;
  881. begin
  882. if (csDesigning in ComponentState) then exit;
  883. FParentform := TForm(Owner);
  884. if (FParentForm <> nil) and (FParentForm.HandleAllocated) then
  885. begin
  886. FOldWindowProc := FParentForm.WindowProc;
  887. FParentForm.WindowProc := FormWndProc;
  888. end;
  889. end;
  890. procedure TEmbeddedWB.UnHook;
  891. begin
  892. if (csDesigning in ComponentState) then exit;
  893. if (FParentForm <> nil) and (FParentForm.HandleAllocated) then
  894. FParentForm.WindowProc := FOldWindowProc;
  895. // FOldWindowProc := nil;
  896. FParentform := nil;
  897. end;
  898. procedure TEmbeddedWB.DDEWndProc(var AMsg: TMessage);
  899. begin
  900. with AMsg do
  901. if (Msg = WM_DDE_INITIATE) and FEnableDDE
  902. then DDEInitiate(wparam, lparam)
  903. else
  904. Result := DefWindowProc(DDEHWND, msg, wParam, lParam);
  905. end;
  906. procedure TEmbeddedWB.FormWndProc(var AMsg: TMessage);
  907. var
  908. i: Integer;
  909. wnd: Integer;
  910. S: string;
  911. Msg: TWmActivate;
  912. begin
  913. if AMsg.Msg = WM_ACTIVATE then begin
  914. Msg := TWmActivate(AMsg);
  915. if Msg.Active = 0 then
  916. begin
  917. wnd := Msg.ActiveWindow;
  918. SetLength(S, 80);
  919. SetLength(S, GetClassName(Wnd, PChar(S), Length(S)));
  920. if (S = '#32770') then
  921. begin
  922. if ReplaceCaption then
  923. begin
  924. SendMessage(wnd, WM_SETICON, ICON_SMALL, Forms.Application.Icon.Handle);
  925. I := GetWindowTextLength(wnd);
  926. SetLength(S, I + 1);
  927. GetWindowText(Wnd, PChar(S), I + 1);
  928. S := StringReplace(S, 'Microsoft ', '', []);
  929. S := StringReplace(S, 'Internet Explorer', Forms.Application.Title, []);
  930. SetWindowText(Wnd, Pchar(S));
  931. end;
  932. if InvokingPageSetup then
  933. begin
  934. InvokingPagesetup := False;
  935. if PrintingWithOptions then
  936. begin
  937. SetWindowPos(Wnd, 0, -600, 0, 0, 0, 0);
  938. PrintingWithOptions := False;
  939. end;
  940. if PrintOptions.Orientation = poPortrait then
  941. SendDlgItemMessage(Wnd, $0420, BM_CLICK, 0, 0) else
  942. SendDlgItemMessage(Wnd, $0421, BM_CLICK, 0, 0);
  943. SetDlgItemText(wnd, $1FD3, PChar(PrintOptions.Header));
  944. SetDlgItemText(wnd, $1FD5, PChar(PrintOptions.Footer));
  945. SetDlgItemText(wnd, $0483, PrintMarginStr(PrintOptions.Margins.Left));
  946. SetDlgItemText(wnd, $0484, PrintMarginStr(PrintOptions.Margins.top));
  947. SetDlgItemText(wnd, $0485, PrintMarginStr(PrintOptions.Margins.Right));
  948. SetDlgItemText(wnd, $0486, PrintMarginStr(PrintOptions.Margins.Bottom));
  949. if (Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion > 4) then
  950. PostMessage(FindWindowEx(wnd, 0, Pchar('Button'), nil), BM_CLICK, 0, 0) //Win2000
  951. else SendDlgItemMessage(Wnd, 1, BM_CLICK, 0, 0);
  952. end;
  953. end;
  954. if not PrintingWithOptions and (wnd <> 0) and Assigned(FOnShowDialog) then FOnShowDialog(self, Wnd);
  955. end;
  956. end;
  957. FOldWindowProc(AMsg);
  958. end;
  959. function TEmbeddedWB.QueryService(const rsid, iid: TGuid; out Obj): HResult;
  960. begin
  961. if Assigned(FOnQueryService) then
  962. Result := FOnQueryService(rsid, iid, IUnknown(obj)) else
  963. Result := E_NOINTERFACE;
  964. end;
  965. function TEmbeddedWB.ShowMailClient: Boolean;
  966. begin
  967. result := OpenClient('Mail');
  968. end;
  969. function TEmbeddedWB.ShowNewsClient: Boolean;
  970. begin
  971. result := OpenClient('News');
  972. end;
  973. function TEmbeddedWB.ShowAddressBook: Boolean;
  974. begin
  975. result := OpenClient('Contacts');
  976. end;
  977. function TEmbeddedWB.ShowCalendar: Boolean;
  978. begin
  979. result := OpenClient('Calendar');
  980. end;
  981. function TEmbeddedWB.ShowInternetCall: Boolean;
  982. begin
  983. result := OpenClient('Internet Call');
  984. end;
  985. function TEmbeddedWB.OpenClient(Client: string): Boolean;
  986. var
  987. s, params, Exec: string;
  988. begin
  989. Result := FALSE;
  990. with TRegistry.Create do
  991. try
  992. RootKey := HKEY_LOCAL_MACHINE;
  993. OpenKey('Software\Clients\' + Client, FALSE);
  994. S := ReadString('');
  995. CloseKey;
  996. OpenKey('Software\Clients\' + Client + '\' + S + '\shell\open\command', FALSE);
  997. S := ReadString('');
  998. CloseKey;
  999. if S <> '' then begin
  1000. if Pos('/', S) > 0 then begin
  1001. Exec := system.Copy(S, 1, Pos('/', S) - 2);
  1002. Params := system.Copy(s, Length(exec) + 1, length(S));
  1003. end else begin
  1004. Exec := S;
  1005. Params := '';
  1006. end;
  1007. Result := TRUE;
  1008. shellExecute(handle, 'open', Pchar(Exec), pChar(Params), '', SW_SHOW);
  1009. end;
  1010. finally
  1011. Free;
  1012. end;
  1013. end;
  1014. procedure TEmbeddedWB.PrintPreView;
  1015. // IE 5.5 only
  1016. var
  1017. vaIn, vaOut: Olevariant;
  1018. begin
  1019. InvokeCmd(FALSE, OLECMDID_PRINTPREVIEW, OLECMDEXECOPT_DODEFAULT, vaIn, vaOut);
  1020. end;
  1021. procedure TEmbeddedWB.SetDownloadOptions(const Value:
  1022. TDownloadControlOptions);
  1023. begin
  1024. FDownloadControlOptions := Value;
  1025. UpdateDownloadControlValue;
  1026. {$IFDEF VER120}
  1027. (Application_ as IOleControl).OnAmbientPropertyChange(DISPID_AMBIENT_DLCONTROL);
  1028. {$ELSE}
  1029. (Application as IOleControl).OnAmbientPropertyChange(DISPID_AMBIENT_DLCONTROL);
  1030. {$ENDIF}
  1031. end;
  1032. procedure TEmbeddedWB.SetUserInterfaceOptions(const Value:
  1033. TUserInterfaceOptions);
  1034. begin
  1035. FUserInterfaceOptions := Value;
  1036. UpdateUserInterfaceValue;
  1037. {$IFDEF VER120}
  1038. (Application_ as IOleControl).OnAmbientPropertyChange(DISPID_AMBIENT_DLCONTROL);
  1039. {$ELSE}
  1040. (Application as IOleControl).OnAmbientPropertyChange(DISPID_AMBIENT_DLCONTROL);
  1041. {$ENDIF}
  1042. end;
  1043. procedure TEmbeddedWB.UpdateDownloadControlValue;
  1044. const
  1045. acardDownloadControlValues: array[TDownloadControlOption] of Cardinal =
  1046. ($00000010, $00000020, $00000040, $00000080,
  1047. $00000100, $00000200, $00000400, $00000800,
  1048. $00001000, $00002000, $00004000, $00008000,
  1049. $00010000, $00020000, $00040000, $10000000,
  1050. $20000000, $40000000, $80000000);
  1051. var
  1052. i: TDownloadControlOption;
  1053. begin
  1054. FDownloadOptionValue := 0;
  1055. if (FDownloadControlOptions <> []) then
  1056. for i := Low(TDownloadControlOption) to High(TDownloadControlOption)
  1057. do
  1058. if (i in FDownloadControlOptions) then
  1059. Inc(FDownloadOptionValue, acardDownloadControlValues[i]);
  1060. end;
  1061. procedure TEmbeddedWB.UpdateUserInterfaceValue;
  1062. const
  1063. acardUserInterfaceValues: array[TUserInterfaceOption] of Cardinal =
  1064. ($00000001, $00000002, $00000004, $00000008,
  1065. $00000010, $00000020, $00000040, $00000080,
  1066. $00000100, $00000200, $00000400, $00000800,
  1067. $00001000, $00002000, $00004000, $00010000, $00020000,
  1068. $00040000, $00080000, $00100000, $00200000);
  1069. var
  1070. i: TUserInterfaceOption;
  1071. begin
  1072. FUserInterfaceValue := 0;
  1073. if (FUserInterfaceOptions <> []) then
  1074. for i := Low(TUserInterfaceOption) to High(TUserInterfaceOption) do
  1075. if (i in FUserInterfaceOptions) then
  1076. Inc(FUserInterfaceValue, acardUserInterfaceValues[i]);
  1077. end;
  1078. function TEmbeddedWB.IsGlobalOffline: boolean;
  1079. var
  1080. dwState: DWORD;
  1081. dwSize: DWORD;
  1082. begin
  1083. dwState := 0;
  1084. dwSize := SizeOf(dwState);
  1085. result := false;
  1086. if (InternetQueryOption(nil, INTERNET_OPTION_CONNECTED_STATE, @dwState,
  1087. dwSize)) then
  1088. if ((dwState and INTERNET_STATE_DISCONNECTED_BY_USER) <> 0) then
  1089. result := true;
  1090. end;
  1091. procedure TEmbeddedWB.SetGlobalOffline(Value: Boolean);
  1092. const
  1093. INTERNET_STATE_DISCONNECTED_BY_USER = $10;
  1094. ISO_FORCE_DISCONNECTED = $1;
  1095. INTERNET_STATE_CONNECTED = $1;
  1096. var
  1097. ci: TInternetConnectedInfo;
  1098. dwSize: DWORD;
  1099. begin
  1100. dwSize := SizeOf(ci);
  1101. if (Value) then begin
  1102. ci.dwConnectedState := INTERNET_STATE_DISCONNECTED_BY_USER;
  1103. ci.dwFlags := ISO_FORCE_DISCONNECTED;
  1104. end else begin
  1105. ci.dwFlags := 0;
  1106. ci.dwConnectedState := INTERNET_STATE_CONNECTED;
  1107. end;
  1108. InternetSetOption(nil, INTERNET_OPTION_CONNECTED_STATE, @ci, dwSize);
  1109. end;
  1110. function SaveDocToStream(Doc: IDispatch; var AStream: TStream): HResult;
  1111. var
  1112. IpStream: IPersistStreamInit;
  1113. begin
  1114. if Doc <> nil then begin
  1115. IpStream := Doc as IPersistStreamInit;
  1116. Result := IpStream.save(TStreamAdapter.Create(AStream), TRUE);
  1117. end else Result := S_FALSE;
  1118. end;
  1119. function TEmbeddedWB.SaveToStream(AStream: TStream): HRESULT;
  1120. begin
  1121. while ReadyState <> READYSTATE_COMPLETE do
  1122. Forms.Application.ProcessMessages;
  1123. if Assigned(Document) then
  1124. Result := SaveDocToStream(Document, AStream)
  1125. else Result := S_FALSE;
  1126. end;
  1127. function SaveDocToStrings(Doc: IDispatch; var AStrings: TStrings): HResult;
  1128. var
  1129. IpStream: IPersistStreamInit;
  1130. AStream: TMemoryStream;
  1131. begin
  1132. AStream := TMemoryStream.Create;
  1133. try
  1134. IpStream := doc as IPersistStreamInit;
  1135. if not Assigned(IpStream) then Result := S_FALSE else
  1136. if Succeeded(IpStream.save(TStreamadapter.Create(AStream), TRUE))
  1137. then begin
  1138. AStream.Seek(0, 0);
  1139. AStrings.LoadFromStream(AStream);
  1140. Result := S_OK;
  1141. end else Result := S_FALSE;
  1142. except
  1143. Result := S_FALSE;
  1144. end;
  1145. AStream.Free;
  1146. end;
  1147. {
  1148. function TEmbeddedwb.SaveFrameToStream(FrameNo: Integer; AStream: TStream): HRESULT;
  1149. var
  1150. iw: IWebbrowser2;
  1151. begin
  1152. Result := S_FALSE;
  1153. iw := Getframe(frameNo);
  1154. if (iw <> nil) and assigned(iw.Document) then
  1155. Result := SaveDocToStream(iw.Document, AStream)
  1156. end;
  1157. function TEmbeddedwb.SaveFrameToStrings(FrameNo: Integer; AStrings: TStrings): HRESULT;
  1158. var
  1159. iw: Iwebbrowser2;
  1160. begin
  1161. Result := S_FALSE;
  1162. iw := Getframe(frameNo);
  1163. if (iw <> nil) and assigned(iw.Document) then
  1164. Result := SaveDocToStrings(iw.Document, AStrings);
  1165. end;
  1166. function TEmbeddedwb.SaveFrameToFile(FrameNo: Integer; const Fname: string): HRESULT;
  1167. var
  1168. Iw: IWebbrowser2;
  1169. PFile: IPersistFile;
  1170. begin
  1171. iw := Getframe(frameNo);
  1172. if (iw <> nil) and assigned(iw.Document) then begin
  1173. PFile := iw.Document as IPersistFile;
  1174. Result := PFile.Save(StringToOleStr(FName), False);
  1175. end else Result := S_FALSE;
  1176. end;
  1177. }
  1178. function SaveDocToFile(Doc: IDispatch; const Fname: string): HResult;
  1179. var
  1180. PFile: IPersistFile;
  1181. begin
  1182. PFile := Doc as IPersistFile;
  1183. Result := PFile.Save(StringToOleStr(FName), False);
  1184. end;
  1185. function TEmbeddedWB.SaveToFile(const Fname: string): HRESULT;
  1186. begin
  1187. while ReadyState <> READYSTATE_COMPLETE do
  1188. Forms.Application.ProcessMessages;
  1189. if Assigned(Document) then
  1190. begin
  1191. Result := SaveDocToFile(Document, FName);
  1192. end else Result := S_FALSE;
  1193. end;
  1194. function TEmbeddedWB.SaveToStrings(AStrings: TStrings): HRESULT;
  1195. begin
  1196. while ReadyState <> READYSTATE_COMPLETE do
  1197. Forms.Application.ProcessMessages;
  1198. if Assigned(document) then
  1199. Result := SaveDocToStrings(Document, AStrings)
  1200. else Result := S_FALSE;
  1201. end;
  1202. {
  1203. function TEmbeddedWb.LoadFrameFromStrings(Frameno: Integer; const AStrings: TStrings): HResult;
  1204. var
  1205. iw: IWebbrowser2;
  1206. M: TMemoryStream;
  1207. begin
  1208. Result := S_FALSE;
  1209. iw := GetFrame(Frameno);
  1210. if (iw <> nil) and assigned(iw.document) then begin
  1211. M := TMemoryStream.Create;
  1212. try
  1213. AStrings.SaveToStream(M);
  1214. M.seek(0, 0);
  1215. Result := (iw.Document as IPersistStreamInit).Load(TStreamadapter.Create(M));
  1216. except
  1217. Result := S_FALSE;
  1218. end;
  1219. M.free;
  1220. end;
  1221. end; }
  1222. function TEmbeddedWb.LoadFromStrings(const AStrings: TStrings): HResult;
  1223. var
  1224. M: TMemoryStream;
  1225. begin
  1226. if not Assigned(document) then AssignDocument;
  1227. M := TMemoryStream.Create;
  1228. try
  1229. AStrings.SaveToStream(M);
  1230. Result := LoadFromStream(M);
  1231. except
  1232. Result := S_FALSE;
  1233. end;
  1234. M.free;
  1235. end;
  1236. {
  1237. function TEmbeddedWb.LoadFrameFromStream(FrameNo: Integer; AStream: TStream): HRESULT;
  1238. var
  1239. iw: IWebbrowser2;
  1240. begin
  1241. Result := S_FALSE;
  1242. iw := Getframe(frameNo);
  1243. if (iw <> nil) then if Assigned(iw.Document) then
  1244. begin
  1245. AStream.seek(0, 0);
  1246. Result := (iw.Document as IPersistStreamInit).Load(TStreamadapter.Create(AStream));
  1247. end;
  1248. end;
  1249. }
  1250. function TEmbeddedWb.LoadFromStream(const AStream: TStream): HRESULT;
  1251. begin
  1252. if not Assigned(Document) then AssignDocument;
  1253. AStream.seek(0, 0);
  1254. Result := (Document as IPersistStreamInit).Load(TStreamadapter.Create(AStream));
  1255. end;
  1256. procedure TEmbeddedWb.AssignDocument;
  1257. begin
  1258. Go('about:blank');
  1259. while readystate <> READYSTATE_COMPLETE do Forms.Application.ProcessMessages;
  1260. end;
  1261. procedure TEmbeddedWb.SetFocusToDoc;
  1262. begin
  1263. if Document <> nil then
  1264. with {$IFDEF VER120}Application_{$ELSE}Application{$ENDIF} as IOleobject do
  1265. DoVerb(OLEIVERB_UIACTIVATE, nil, Self, 0, Handle, GetClientRect);
  1266. end;
  1267. {$IFDEF VER120}
  1268. procedure TEmbeddedWb.EnableMessagehandler;
  1269. begin
  1270. if not bMsgHandler then
  1271. begin
  1272. SaveMessage := Forms.Application.OnMessage;
  1273. Forms.Application.OnMessage := IeMessagehandler;
  1274. bMsgHandler := True;
  1275. end;
  1276. end;
  1277. procedure TEmbeddedWB.DisableMessageHandler;
  1278. begin
  1279. if bMsgHandler then
  1280. begin
  1281. Forms.Application.onMessage := Savemessage;
  1282. bMsgHandler := False;
  1283. end;
  1284. end;
  1285. {$ENDIF}
  1286. ///BEGIN >>>>> Messagehandler by Mathias Walter - walter@coint.de >>>>>///
  1287. procedure TEmbeddedWB.WBWndProc(var Message: TMessage);
  1288. const
  1289. StdKeys = [VK_RETURN, VK_BACK]; { standard keys }
  1290. ExtKeys = [VK_LEFT, VK_RIGHT]; { extended keys }
  1291. fExtended = $01000000; { extended key flag }
  1292. var
  1293. bClose: Boolean;
  1294. {$IFNDEF VER120}
  1295. WinMsg: TMsg;
  1296. {$ENDIF}
  1297. begin
  1298. with Message do
  1299. begin
  1300. {$IFNDEF VER120}
  1301. if (Msg >= (CN_BASE + WM_KEYFIRST)) and (Msg <= (CN_BASE + WM_DEADCHAR)) then
  1302. begin
  1303. WinMsg.hwnd := Handle;
  1304. WinMsg.message := Msg - CN_BASE;
  1305. WinMsg.wParam := wParam;
  1306. WinMsg.lParam := lParam;
  1307. WinMsg.time := GetMessageTime;
  1308. WinMsg.pt.x := $115DE1F1;
  1309. WinMsg.pt.y := $115DE1F1;
  1310. if not ((wParam in StdKeys) or
  1311. (wParam in ExtKeys) and ((lParam and fExtended) = fExtended)) then
  1312. with Application as IOleInPlaceActiveObject do
  1313. Result := Integer(TranslateAccelerator(WinMsg) = S_OK);
  1314. end
  1315. else
  1316. {$ENDIF}
  1317. case Msg of
  1318. WM_CLOSE: begin
  1319. bClose := True;
  1320. if Assigned(FOnCloseQuery) then
  1321. FOnCloseQuery(Self, bClose);
  1322. if bClose then
  1323. OldWBWndProc(Message);
  1324. end;
  1325. WM_DDE_EXECUTE: DDEExecute(wparam, lparam);
  1326. WM_DDE_TERMINATE: DDETerminate(wparam, lparam);
  1327. else
  1328. OldWBWndProc(Message);
  1329. end;
  1330. end;
  1331. end;
  1332. {$IFDEF VER120}
  1333. procedure TEmbeddedWB.IEMessageHandler(var Msg: TMsg; var Handled: Boolean);
  1334. { fixes the malfunction of some keys within webbrowser control }
  1335. const
  1336. StdKeys = [VK_TAB, VK_RETURN]; { standard keys }
  1337. ExtKeys = [VK_DELETE, VK_BACK, VK_LEFT, VK_RIGHT]; { extended keys }
  1338. fExtended = $01000000; { extended key flag }
  1339. begin
  1340. Handled := False;
  1341. with Msg do
  1342. if ((Message >= WM_KEYFIRST) and (Message <= WM_KEYLAST)) and
  1343. ((wParam in StdKeys) or (GetKeyState(VK_CONTROL) < 0) or
  1344. (wParam in ExtKeys) and ((lParam and fExtended) = fExtended)) then
  1345. try
  1346. if IsChild(Handle, hWnd) then
  1347. { handles all browser related messages }
  1348. begin
  1349. with Application_ as IOleInPlaceActiveObject do
  1350. Handled := TranslateAccelerator(Msg) = S_OK;
  1351. if not Handled then
  1352. begin
  1353. Handled := True;
  1354. TranslateMessage(Msg);
  1355. DispatchMessage(Msg);
  1356. end;
  1357. end;
  1358. except end;
  1359. end; // IEMessageHandler
  1360. {$ENDIF}
  1361. ///END <<<<<< Messagehandler by Mathias Walter - walter@coint.de <<<<<///
  1362. procedure TEmbeddedWb.NavigateFolder(CSIDL: Integer);
  1363. var
  1364. sFolder: PITemIdList;
  1365. begin
  1366. SHGetSpecialFolderLocation(0, CSIDL, SFolder);
  1367. NavigatePidl(SFolder);
  1368. CoTaskMemFree(SFolder);
  1369. end;
  1370. procedure TEmbeddedWB.NavigatePidl(pidl: PItemIdList);
  1371. var
  1372. VaEmpty, vaPidl: Olevariant;
  1373. psa: PSafeArray;
  1374. cbData: UINT;
  1375. begin
  1376. cbdata := GetPidlSize(pidl);
  1377. psa := SafeArrayCreateVector(VT_UI1, 0, cbData);
  1378. if (psa <> nil) then begin
  1379. CopyMemory(psa.pvData, pidl, cbData);
  1380. VariantInit(vaPidl);
  1381. TVariantArg(vaPidl).vt := VT_ARRAY or VT_UI1;
  1382. TVariantArg(vaPidl).parray := psa;
  1383. Navigate2(vaPidl, vaEmpty, vaEmpty, vaEmpty, vaEmpty);
  1384. VariantClear(vaPidl);
  1385. end;
  1386. end;
  1387. procedure TEmbeddedWB.Go(Url: string);
  1388. var
  1389. _URL, Flags, TargetFrameName, PostData, Headers: Olevariant;
  1390. begin
  1391. _URL := Url;
  1392. Flags := 0; TargetFrameName := 0; Postdata := 0; Headers := 0;
  1393. Navigate2(_URL, Flags, TargetFrameName, PostData, Headers);
  1394. end;
  1395. procedure TEmbeddedWB.InvokeCMD(InvokeIE: Boolean; Value1, Value2: Integer; var vaIn, vaOut: OleVariant);
  1396. var
  1397. CmdTarget: IOleCommandTarget;
  1398. PtrGUID: PGUID;
  1399. begin
  1400. New(PtrGUID);
  1401. if InvokeIE then PtrGUID^ := CLSID_WebBrowser else
  1402. PtrGuid := PGUID(nil);
  1403. if Document <> nil then
  1404. try
  1405. Document.QueryInterface(IOleCommandTarget, CmdTarget);
  1406. if CmdTarget <> nil then
  1407. try
  1408. CmdTarget.Exec(PtrGuid, Value1, Value2, vaIn, vaOut);
  1409. finally
  1410. CmdTarget._Release;
  1411. end;
  1412. except end;
  1413. Dispose(PtrGUID);
  1414. end;
  1415. procedure TEmbeddedWB.Print;
  1416. var
  1417. vaIn, vaOut: Olevariant;
  1418. HtmlText: string;
  1419. Stream: IStream;
  1420. Dummy: Int64;
  1421. Psa: PSafeArray;
  1422. begin
  1423. HtmlText := PrintOptions.HtmlHeader.Text;
  1424. CreateStreamOnHGlobal(0, TRUE, Stream);
  1425. Stream.Write(Pchar(HTMLText), length(HTMLText), @Dummy);
  1426. Stream.Seek(0, STREAM_SEEK_SET, Dummy);
  1427. SafeArrayCopy(PSafeArray(TVarData(VarArrayOf([FPrintOptions.Header, FPrintOptions.Footer, Stream as IUnknown])).VArray), psa);
  1428. TVarData(VaIn).VType := varArray or varByRef;
  1429. SafeArrayCopy(psa, PSafeArray(TVarData(VaIn).VArray));
  1430. InvokeCmd(FALSE, OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, vaIn, vaOut);
  1431. end;
  1432. procedure TEmbeddedWB.PrintSetup;
  1433. var
  1434. vaIn, vaOut: Olevariant;
  1435. HtmlText: string;
  1436. Stream: IStream;
  1437. Dummy: Int64;
  1438. Psa: PSafeArray;
  1439. begin
  1440. HtmlText := PrintOptions.HtmlHeader.Text;
  1441. CreateStreamOnHGlobal(0, TRUE, Stream);
  1442. Stream.Write(Pchar(HTMLText), length(HTMLText), @Dummy);
  1443. Stream.Seek(0, STREAM_SEEK_SET, Dummy);
  1444. SafeArrayCopy(PSafeArray(TVarData(VarArrayOf([FPrintOptions.Header, FPrintOptions.Footer, Stream as IUnknown])).VArray), psa);
  1445. TVarData(VaIn).VType := varArray or varByRef;
  1446. SafeArrayCopy(psa, PSafeArray(TVarData(VaIn).VArray));
  1447. InvokeCmd(FALSE, OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER, vaIn, vaOut);
  1448. end;
  1449. procedure TEmbeddedWB.PageSetup(UsePrintOptions: Boolean);
  1450. var
  1451. vaIn, vaOut: Olevariant;
  1452. begin
  1453. if UsePrintOptions then InvokingPageSetup := True;
  1454. InvokeCmd(FALSE, OLECMDID_PAGESETUP, OLECMDEXECOPT_DODEFAULT, vaIn, vaOut);
  1455. end;
  1456. procedure TEmbeddedWB.OpenDialog;
  1457. var
  1458. vaIn, vaOut: Olevariant;
  1459. begin
  1460. InvokeCmd(FALSE, OLECMDID_OPEN, OLECMDEXECOPT_DODEFAULT, vaIn, vaOut);
  1461. end;
  1462. procedure TEmbeddedWB.SaveDialog;
  1463. var
  1464. vaIn, vaOut: Olevariant;
  1465. begin
  1466. InvokeCmd(FALSE, OLECMDID_SAVEAS, OLECMDEXECOPT_DODEFAULT, vaIn, vaOut);
  1467. end;
  1468. procedure TEmbeddedWB.ViewSource;
  1469. var
  1470. vaIn, vaOut: Olevariant;
  1471. begin
  1472. InvokeCmd(TRUE, HTMLID_VIEWSOURCE, 0, vaIn, vaOut);
  1473. end;
  1474. procedure TEmbeddedWB.Options;
  1475. var
  1476. vaIn, vaOut: Olevariant;
  1477. begin
  1478. InvokeCmd(TRUE, HTMLID_OPTIONS, 0, vaIn, vaOut);
  1479. end;
  1480. procedure TEmbeddedWB.Properties;
  1481. var
  1482. vaIn, vaOut: Olevariant;
  1483. begin
  1484. InvokeCmd(FALSE, OLECMDID_PROPERTIES, OLECMDEXECOPT_DODEFAULT, vaIn, vaOut);
  1485. end;
  1486. procedure TEmbeddedWB.Find;
  1487. var
  1488. vaIn, vaOut: Olevariant;
  1489. begin
  1490. InvokeCmd(TRUE, HTMLID_FIND, 0, vaIn, vaOut);
  1491. end;
  1492. procedure TEmbeddedWB.Copy;
  1493. var
  1494. vaIn, vaOut: Olevariant;
  1495. begin
  1496. InvokeCmd(FALSE, OLECMDID_COPY, OLECMDEXECOPT_DODEFAULT, vaIn, vaOut);
  1497. end;
  1498. procedure TEmbeddedWB.SelectAll;
  1499. var
  1500. vaIn, vaOut: Olevariant;
  1501. begin
  1502. InvokeCmd(FALSE, OLECMDID_SELECTALL, OLECMDEXECOPT_DODEFAULT, vaIn, vaOut);
  1503. end;
  1504. procedure TEmbeddedWB.Zoom(ZoomValue: Integer);
  1505. var
  1506. vaIn, vaOut: Olevariant;
  1507. begin
  1508. if ZoomValue < ZoomRangeLow then vaIn := ZoomRangeLow else
  1509. if ZoomValue > ZoomRangeHigh then vaIn := ZoomRangeHigh else
  1510. vaIn := ZoomValue;
  1511. InvokeCmd(FALSE, OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, vaIn, vaOut);
  1512. end;
  1513. function TEmbeddedWB.ZoomRangeLow: Integer;
  1514. var
  1515. vaIn, vaOut: Olevariant;
  1516. begin
  1517. InvokeCmd(FALSE, OLECMDID_GETZOOMRANGE, OLECMDEXECOPT_DONTPROMPTUSER, vaIn, vaOut);
  1518. result := LoWord(Dword(vaOut));
  1519. end;
  1520. function TEmbeddedWB.ZoomRangeHigh: Integer;
  1521. var
  1522. vaIn, vaOut: Olevariant;
  1523. begin
  1524. InvokeCmd(FALSE, OLECMDID_GETZOOMRANGE, OLECMDEXECOPT_DONTPROMPTUSER, vaIn, vaOut);
  1525. result := HiWord(Dword(vaOut));
  1526. end;
  1527. function TEmbeddedWB.ZoomValue: Integer;
  1528. var
  1529. vaIn, vaOut: Olevariant;
  1530. begin
  1531. vaIn := null;
  1532. InvokeCmd(FALSE, OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, vaIn, vaOut);
  1533. result := vaOut;
  1534. end;
  1535. // IDOCHOSTUIHANDLER
  1536. function TEmbeddedWB.ShowContextMenu(const dwID: DWORD; const ppt: PPOINT;
  1537. const pcmdtReserved: IUnknown; const pdispReserved: IDispatch): HRESULT;
  1538. begin
  1539. if Assigned(FOnShowContextmenu) then RESULT := FOnSHowContextmenu(dwID, ppt,
  1540. pcmdtreserved, pdispreserved) else
  1541. RESULT := S_FALSE;
  1542. end;
  1543. function TEmbeddedWB.GetHostInfo(var pInfo: TDOCHOSTUIINFO): HRESULT;
  1544. begin
  1545. pInfo.cbSize := SizeOf(pInfo);
  1546. pInfo.dwFlags := FUserInterfaceValue;
  1547. pInfo.dwDoubleClick := DOCHOSTUIDBLCLK_DEFAULT;
  1548. if Assigned(FOnGetHostInfo) then
  1549. Result := FOnGetHostInfo(pInfo) else
  1550. Result := S_OK;
  1551. end;
  1552. function TEmbeddedWB.ShowUI(const dwID: DWORD;
  1553. const pActiveObject: IOleInPlaceActiveObject;
  1554. const pCommandTarget: IOleCommandTarget; const pFrame: IOleInPlaceFrame;
  1555. const pDoc: IOleInPlaceUIWindow): HRESULT;
  1556. begin
  1557. if Assigned(FOnShowUI) then
  1558. Result := FOnShowUI(dwID, pActiveObject, pCommandTarget, pFrame, pDoc)
  1559. else
  1560. Result := S_FALSE;
  1561. end;
  1562. function TEmbeddedWB.HideUI: HRESULT;
  1563. begin
  1564. if Assigned(FOnHideUI) then
  1565. Result := FOnHideUI else
  1566. Result := S_FALSE;
  1567. end;
  1568. function TEmbeddedWB.UpdateUI: HRESULT;
  1569. begin
  1570. if Assigned(FOnUpdateUI) then
  1571. Result := FOnUpdateUI else
  1572. Result := S_FALSE;
  1573. end;
  1574. function TEmbeddedWB.EnableModeless(const fEnable: BOOL): HRESULT;
  1575. begin
  1576. if Assigned(FOnEnableModeless) then
  1577. Result := FOnEnableModeless(fEnable) else
  1578. Result := S_FALSE;
  1579. end;
  1580. function TEmbeddedWB.OnDocWindowActivate(const fActivate: BOOL): HRESULT;
  1581. begin
  1582. if Assigned(FOnOnDocWindowActivate) then
  1583. Result := FOnOnDocWindowActivate(fActivate) else
  1584. Result := S_FALSE;
  1585. end;
  1586. function TEmbeddedWB.OnFrameWindowActivate(const fActivate: BOOL): HRESULT;
  1587. begin
  1588. if Assigned(FOnOnFrameWindowActivate) then
  1589. Result := FOnOnFrameWindowActivate(fActivate) else
  1590. Result := S_FALSE;
  1591. end;
  1592. function TEmbeddedWB.ResizeBorder(const prcBorder: PRECT;
  1593. const pUIWindow: IOleInPlaceUIWindow; const fRameWindow: BOOL): HRESULT;
  1594. begin
  1595. if Assigned(FOnResizeBorder) then
  1596. Result := FOnResizeBorder(prcBorder, pUIWindow, fRameWindow) else
  1597. Result := S_FALSE;
  1598. end;
  1599. function TEmbeddedWB.TranslateAccelerator(const lpMsg: PMSG;
  1600. const pguidCmdGroup: PGUID; const nCmdID: DWORD): HRESULT;
  1601. begin
  1602. if Assigned(FOnTranslateAccelerator) then
  1603. Result := FOnTranslateAccelerator(lpMsg, pguidCmdGroup, nCmdID) else
  1604. Result := S_FALSE;
  1605. end;
  1606. function TEmbeddedWB.GetOptionKeyPath(var pchKey: POLESTR; const dw: DWORD): HRESULT;
  1607. begin
  1608. if Assigned(FOnGetOptionKeyPath) then
  1609. Result := FOnGetOptionKeyPath(pchKey, dw) else
  1610. Result := S_FALSE;
  1611. end;
  1612. function TEmbeddedWB.GetDropTarget(const pDropTarget: IDropTarget;
  1613. out ppDropTarget: IDropTarget): HRESULT;
  1614. begin
  1615. if Assigned(FOnGetDropTarget) then
  1616. Result := FOnGetDropTarget(pDropTarget, ppDropTarget) else
  1617. Result := S_OK;
  1618. end;
  1619. function TEmbeddedWB.GetExternal(out ppDispatch: IDispatch): HRESULT;
  1620. begin
  1621. if Assigned(FOnGetExternal) then
  1622. Result := FOnGetExternal(ppDispatch) else
  1623. Result := S_FALSE;
  1624. end;
  1625. function TEmbeddedWB.TranslateUrl(const dwTranslate: DWORD;
  1626. const pchURLIn: POLESTR; var ppchURLOut: POLESTR): HRESULT;
  1627. begin
  1628. if Assigned(FOnTranslateUrl) then
  1629. Result := FOnTranslateUrl(dwTranslate, pchUrlIn, ppchUrlOut) else
  1630. Result := S_FALSE;
  1631. end;
  1632. function TEmbeddedWB.FilterDataObject(const pDO: IDataObject;
  1633. out ppDORet: IDataObject): HRESULT;
  1634. begin
  1635. if Assigned(FOnFilterDataObject) then
  1636. Result := FOnFilterDataObject(pDO, ppDORet) else
  1637. Result := S_FALSE;
  1638. end;
  1639. // IDOCHOSTSHOWUI
  1640. function TEmbeddedWB.ShowMessage(hwnd: THandle; lpstrText: POLESTR;
  1641. lpstrCaption: POLESTR; dwType: longint; lpstrHelpFile: POLESTR;
  1642. dwHelpContext: longint; var plResult: LRESULT): HRESULT;
  1643. begin
  1644. if Assigned(FOnShowMessage) then
  1645. Result := FOnShowMessage(hwnd, lpstrText, lpStrCaption, dwType, lpStrHelpFile, dwHelpContext, plResult) else
  1646. Result := S_FALSE;
  1647. end;
  1648. function TEmbeddedWB.ShowHelp(hwnd: THandle; pszHelpFile: POLESTR;
  1649. uCommand: integer; dwData: longint; ptMouse: TPoint;
  1650. var pDispatchObjectHit: IDispatch): HRESULT;
  1651. begin
  1652. Result := S_OK;
  1653. if Assigned(FOnShowHelp) then
  1654. Result := FOnShowHelp(hwnd, pszHelpFile, uCommand, dwData, ptMouse, pDispatchObjectHit) else
  1655. if FHelpFile <> '' then HtmlHelp(hwnd, Pchar(FHelpFile), ucommand, dwData) else
  1656. Result := S_FALSE;
  1657. end;
  1658. // IDISPATCH methods
  1659. function TEmbeddedWB.GetIDsOfNames(const IID: TGUID; Names: Pointer;
  1660. NameCount, LocaleID: Integer; DispIDs: Pointer): HResult;
  1661. begin
  1662. if Assigned(FOnGetIdsofNames) then
  1663. Result := FOnGetIdsofNames(IID, Names, NameCount, LocaleID, DispIds) else
  1664. result := E_NotImpl;
  1665. end;
  1666. function TEmbeddedWB.GetTypeInfo(Index, LocaleID: Integer;
  1667. out TypeInfo): HResult;
  1668. begin
  1669. if Assigned(FOnGetTypeInfo) then
  1670. Result := FOnGetTypeInfo(Index, LocaleID, ITypeInfo(TypeInfo)) else
  1671. begin
  1672. Result := E_NOTIMPL;
  1673. pointer(TypeInfo) := nil;
  1674. end;
  1675. end;
  1676. function TEmbeddedWB.GetTypeInfoCount(out Count: Integer): HResult;
  1677. begin
  1678. if Assigned(FOnGetTypeInfoCount) then
  1679. Result := FOnGetTypeInfoCount(Count) else
  1680. begin
  1681. Result := E_NOTIMPL;
  1682. Count := 0;
  1683. end;
  1684. end;
  1685. function TEmbeddedWB.Invoke(DispID: Integer;
  1686. const IID: TGUID;
  1687. LocaleID: Integer;
  1688. Flags: Word;
  1689. var Params;
  1690. VarResult, ExcepInfo,
  1691. ArgErr: Pointer): HResult;
  1692. begin
  1693. Result := S_OK;
  1694. if (Flags and DISPATCH_PROPERTYGET <> 0) and (VarResult <> nil) and
  1695. (DispId = DISPID_AMBIENT_DLCONTROL) then
  1696. PVariant(VarResult)^ := FDownloadOptionValue
  1697. else
  1698. if Assigned(FOnInvoke) then
  1699. Result := FOnInvoke(DispId, IID, LocaleID, Flags, TagDispParams(Params),
  1700. VarResult, ExcepInfo, ArgErr)
  1701. else
  1702. Result := inherited Invoke(DispID, IID, LocaleID, Flags, Params,
  1703. VarResult, ExcepInfo, ArgErr);
  1704. end;
  1705. procedure Register;
  1706. begin
  1707. RegisterComponents({$IFDEF VER120} 'ActiveX'{$ELSE} 'Internet'{$ENDIF}, [TEmbeddedWB]);
  1708. end;
  1709. { TPrintOptions }
  1710. procedure TPrintOptions.SetHTMLHeader(const Value: Tstrings);
  1711. begin
  1712. FHTMLHeader.Assign(Value);
  1713. end;
  1714. function DeleteFirstCacheEntry(var H: THandle): DWORD;
  1715. var
  1716. T: PInternetCacheEntryInfo;
  1717. D: DWord;
  1718. begin
  1719. Result := S_OK;
  1720. H := 0;
  1721. D := 0;
  1722. FindFirstUrlCacheEntryEx(nil, 0, URLCACHE_FIND_DEFAULT_FILTER, 0, nil, @D, nil, nil, nil);
  1723. GetMem(T, D);
  1724. try
  1725. H := FindFirstUrlCacheEntryEx(nil, 0, URLCACHE_FIND_DEFAULT_FILTER, 0, T, @D, nil, nil, nil);
  1726. if (H = 0) then Result := GetLastError else DeleteUrlCacheEntry(T^.lpszSourceUrlname);
  1727. finally
  1728. FreeMem(T, D)
  1729. end;
  1730. end;
  1731. function DeleteNextCacheEntry(H: THandle): DWORD;
  1732. var
  1733. T: PInternetCacheEntryInfo;
  1734. D: DWORD;
  1735. begin
  1736. Result := S_OK;
  1737. D := 0;
  1738. FindnextUrlCacheEntryEx(H, nil, @D, nil, nil, nil);
  1739. GetMem(T, D);
  1740. try
  1741. if not FindNextUrlCacheEntryEx(H, T, @D, nil, nil, nil)
  1742. then Result := GetLastError else DeleteUrlCacheEntry(T^.lpszSourceUrlname);
  1743. finally
  1744. FreeMem(T, D)
  1745. end;
  1746. end;
  1747. procedure TEmbeddedWB.ClearCache;
  1748. var
  1749. H: THandle;
  1750. begin
  1751. if DeleteFirstCacheEntry(H) = S_OK then
  1752. repeat
  1753. until DeleteNextCacheEntry(H) = ERROR_NO_MORE_ITEMS;
  1754. FindCloseUrlCache(H)
  1755. end;
  1756. procedure TEmbeddedWB.ClearHistory;
  1757. var
  1758. HistoryStg: IUrlHistoryStg2;
  1759. begin
  1760. HistoryStg := CreateComObject(CLSID_CUrlHistory) as IUrlHistoryStg2;
  1761. HistoryStg.ClearHistory;
  1762. end;
  1763. function TEmbeddedWB.GetOverrideKeyPath(pchKey: POLESTR;
  1764. dw: DWORD): HRESULT;
  1765. begin
  1766. if Assigned(FOnGetOverrideKeyPath) then RESULT := FOnGetOverrideKeyPath(pchkey, dw) else
  1767. Result := S_OK;
  1768. end;
  1769. {$IFDEF USE_IOLECOMMANDTARGET}
  1770. function TEmbeddedWB.Exec(CmdGroup: PGUID; nCmdID, nCmdexecopt: DWORD;
  1771. const vaIn: OleVariant; var vaOut: OleVariant): HResult;
  1772. var
  1773. FCancel, FContinueScript, FShowDialog: Boolean;
  1774. pEventObj: IHTMLEventObj;
  1775. function GetProperty(const PropName: WideString): OLEVariant;
  1776. var
  1777. Dispparams: TDispParams;
  1778. Disp, Status: Integer;
  1779. ExcepInfo: TExcepInfo;
  1780. PPropName: PWideChar;
  1781. begin
  1782. Dispparams.rgvarg := nil;
  1783. Dispparams.rgdispidNamedArgs := nil;
  1784. Dispparams.cArgs := 0;
  1785. Dispparams.cNamedArgs := 0;
  1786. PPropName := PWideChar(PropName);
  1787. Status := pEventObj.GetIDsOfNames(GUID_NULL, @PPropname, 1,
  1788. LOCALE_SYSTEM_DEFAULT, @Disp);
  1789. if Status = 0 then
  1790. begin
  1791. Status := pEventObj.Invoke(disp, GUID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET,
  1792. Dispparams, @Result, @ExcepInfo, nil);
  1793. if Status <> 0 then DispatchInvokeError(Status, ExcepInfo);
  1794. end else
  1795. if Status = DISP_E_UNKNOWNNAME then
  1796. raise EOleError.CreateFmt('''%s'' not supported.', [PropName])
  1797. else
  1798. OleCheck(Status);
  1799. end;
  1800. begin
  1801. if (CmdGroup = nil) then
  1802. begin
  1803. Result := OLECMDERR_E_UNKNOWNGROUP;
  1804. exit;
  1805. end;
  1806. Result := OLECMDERR_E_NOTSUPPORTED;
  1807. if (ncmdID = OLECMDID_ONUNLOAD) and IsEqualGuid(cmdGroup^, CGID_EXPLORER) and
  1808. Assigned(FOnUnload) then FOnUnload(Self);
  1809. if IsEqualGuid(cmdGroup^, CGID_DocHostCommandHandler) then
  1810. begin
  1811. if Assigned(FOnRefresh) and ((nCmdID = 6041 {F5}) or (nCmdID = 6042 {ContextMenu}) or (nCmdID = 2300)) then
  1812. begin
  1813. FCancel := False;
  1814. FOnRefresh(self, nCmdID, FCancel);
  1815. if FCancel then Result := S_OK;
  1816. end else
  1817. case nCmdID of
  1818. OLECMDID_SHOWSCRIPTERROR:
  1819. if Assigned(FOnScriptError)
  1820. then begin
  1821. pEventObj := (Document as IHTMLDocument2).parentWindow.event;
  1822. if pEventObj <> nil then
  1823. begin
  1824. FContinueScript := True;
  1825. FShowDialog := True;
  1826. FOnScriptError(self,
  1827. GetProperty('errorline'),
  1828. GetProperty('errorCharacter'),
  1829. GetProperty('errorCode'),
  1830. GetProperty('errorMessage'),
  1831. GetProperty('errorUrl'),
  1832. FContinueScript, FShowDialog);
  1833. TVariantArg(vaOut).vt := VT_BOOL;
  1834. TVariantArg(vaOut).vbool := FContinueScript;
  1835. if not FShowDialog then Result := S_OK;
  1836. end;
  1837. end;
  1838. end;
  1839. end;
  1840. end;
  1841. function TEmbeddedWB.QueryStatus(CmdGroup: PGUID; cCmds: Cardinal;
  1842. prgCmds: POleCmd; CmdText: POleCmdText): HResult;
  1843. begin
  1844. result := S_OK;
  1845. end;
  1846. {$ENDIF}
  1847. initialization
  1848. Saved8087CW := Default8087CW;
  1849. {$IFDEF VER120}
  1850. bMsgHandler := False;
  1851. {$ENDIF}
  1852. OleInitialize(nil);
  1853. finalization
  1854. Set8087CW(Saved8087CW);
  1855. try
  1856. OleUninitialize;
  1857. except end;
  1858. end.