Objective Toolkit : Chapter 27 Web Browser Extensions : Feature List
Feature List
 
Getting the IWebBrowser2 Interface in IE
The Microsoft-recommended way to hook into Internet Explorer (IE) and get hold of the IWebBrowser2 control in an instance of IE is to write a Browser Helper Object (BHO). However, BHOs are cumbersome to deal with in that they need to reside in their own DLLs— exposing a specified interface— and they are always loaded with IE, whether needed or not.
We provide two ways to hook into IE and get hold of the underlying IWebBrowser2 interface on an as-needed basis.
IWebBrowser2 from a NEW IE instance
The WBUtils COM server we provide (under Studio\COMservers\Toolkit\WBUtils) with source code provides you an interface through which you can ask it to create a new instance of IE and provides you with an IWebBrowser2 interface of the underlying Web browser control (asynchronously via an IDispatch).
Take a look at the IWBUtilFuncs::CreateNewIEInstance() function in the COM Server.
Grab IE under HWND
You could instead get hold of the IWebBrowser2 interface in IE (only in IE) under a specified screen point (or the HWND under that point).
The WalkAndExamineIEBrowsers() function uses ShellWindows to walk through the collection of IE windows (as described in MSDN Knowledge Base article Q176792) and determines the browser control associated with the specified HWND. Also, as mentioned in the above article, the limitations with this approach hold true.
NOTE >> You can search for article Q176792 in the Microsoft Knowledge Base at: http://search.support.microsoft.com/kb/c.asp.
Init IWebBrowser2 with HTML in Memory
There is no easy way to initialize a Web browser control via HTML in memory. The LoadHTML() method in the COM Server interface is one way. Another way is the LoadWBViaIPersist() utility function, which, as the name implies, uses the IPersistStreamInit interface to load the control with HTML.
Retrieve HTML in IWebBrowser2
We also provide three different ways to save the HTML displayed in the browser control to a file. As mentioned below, each of them retrieves a different source associated with the control.
The three different utility functions are:
SaveWBViaCache()— Will save the original HTML source stored in the local cache.
SaveWBViaIPersistFile()— Will save the resultant HTML (scripts expanded) as rendered by the Web browser control.
SaveWBViaDOM()— Will save the HTML with the latest changes applied to the document via the DOM.
You could also use SaveWBViaIPersist() to retrieve the HTML as a BSTR. (This is the equivalent of SaveWBViaIPersistFile(), described above).
The COM Server exposes two functions (SaveHTML() and SaveToFile()), which in turn use the above functions to retrieve the HTML into memory and file, respectively.
CHTMLView Extensions
SECHTMLView, deriving from CHTMLView, provides:
A IDocHostUIHandler implementation to listen for the corresponding events and the Document events.
DDX-like macros for bi-directional transfer between client data structures and Web browser control element properties.
A utility class to simplify finding elements by id/tagName.
Miscellaneous Utility Functions
Other simple utility functions and classes are declared in include\toolkit\WBExt\WBUtilFuncs.h, which you could use while working with the IWebBrowser2 interface.