HOWTO: Get the WebBrowser Object Model of an HTML Frame
ID: Q196340
|
The information in this article applies to:
-
Microsoft Internet Explorer (Programming) versions 5.0, 4.0, 4.01, 4.01sp1, 5.0dp1, 5_beta
SUMMARY
This article details the standard technique WebBrowser control hosts can
use to access the WebBrowser object model of frame windows in an HTML page
inside the control. This object model provides extra functionality that is
not exposed for the frame window through the HTML object model.
MORE INFORMATION
The following code demonstrates how to access the WebBrowser Object Model
of frames in an HTML page to refresh the contents of each frame.
The most important piece of the code uses the IOleContainer::EnumObjects
method of the HTML Document object to enumerate embeddings on the page.
Each of these embeddings represents a control on the page. By querying each
control object for IWebBrowser2, this code can determine whether the
control is a sub-frame. And IWebBrowser2 represents the WebBrowser Object
Model; if QueryInterface succeeds for this interface, the result is a
reference to the WebBrowser Object Model.
// Get the IDispatch of the document
LPDISPATCH lpDisp = NULL;
lpDisp = m_webBrowser.GetDocument();
if (lpDisp)
{
IOleContainer* pContainer;
// Get the container
HRESULT hr = lpDisp->QueryInterface(IID_IOleContainer,
(void**)&pContainer);
lpDisp->Release();
if (FAILED(hr))
return hr;
IEnumUnknown* pEnumerator;
// Get an enumerator for the frames
hr = pContainer->EnumObjects(OLECONTF_EMBEDDINGS, &pEnumerator);
pContainer->Release();
if (FAILED(hr))
return hr;
IUnknown* pUnk;
ULONG uFetched;
// Enumerate and refresh all the frames
for (UINT i = 0; S_OK == pEnumerator->Next(1, &pUnk, &uFetched); i++)
{
// QI for IWebBrowser here to see if we have an embedded browser
IWebBrowser2* pBrowser;
hr = pUnk->QueryInterface(IID_IWebBrowser2, (void**)&pBrowser);
pUnk->Release();
if (SUCCEEDED(hr))
{
// Refresh the frame
pBrowser->Refresh();
pBrowser->Release();
}
}
pEnumerator->Release();
}
NOTE: ActiveX controls hosted in an HTML page can use this technique in a
similar manner. In general, an ActiveX control that accesses the unsafe
WebBrowser Object Model is not safe for scripting and should implement
IObjectSafety interface accordingly for security.
REFERENCES
Reusing Browser Technology in SBN Workshop:
http://msdn.microsoft.com/workshop/browser/default.asp
(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Scott
Roberts, Microsoft Corporation.
Additional query words:
WebBrowser Frame
Keywords : kbIE400 kbIE401 kbWebBrowser kbIE401sp1 kbIE500dp1 kbIE500 kbIEFAQ
Version : WINDOWS:4.0,4.01,4.01sp1,5.0,5.0dp1,5_beta
Platform : WINDOWS
Issue type : kbhowto