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.
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.
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++)
{
IWebBrowser2* pBrowser;
hr = pUnk->QueryInterface(IID_IWebBrowser2, (void**)&pBrowser);
pUnk->Release();
if (SUCCEEDED(hr))
{
// Refresh the frame
pBrowser->Refresh();
pBrowser->Release();
}
}
pEnumerator->Release();
}
'웹, HTML' 카테고리의 다른 글
웹해킹 베이직, 취약과 방어 (2) | 2009.10.16 |
---|---|
자신의 ip 알아내기 참조 (1) | 2009.10.04 |
Ftp 이어 받기, 이어 올리기 구현할 때 (2) | 2009.10.03 |
IHTMLWindow2->get_document가 E_ACCESSDENIED를 뱉는 경우(아래와 다른 해결방법) (2) | 2009.09.28 |
IHTMLWindow2::get_document returns E_ACCESSDENIED 뱉을 경우 (3) | 2009.09.28 |
ShellExecute,WinExec,CreateProcess (IE 실행방법) (0) | 2009.07.25 |
HTMLElement 객체/ Event - JavaScript - (0) | 2009.07.21 |