#keywords C++, COM, IWebBrowser2, IHTMLDocument2, IHTMLWindow2
[[TableOfContents]]
= IWebBrowser2 =
{{{#!gcode
inline IWebBrowser2* GetIWebPointer()
{
HRESULT hr ;
IOleContainer *pIContainer = NULL ;
IWebBrowser2 *pIWeb = NULL ;
IServiceProvider *pISP = NULL ;
// Get IOleClientSite interface pointer.
LPOLECLIENTSITE pIClientSite = NULL;
GetClientSite(&pIClientSite);
// Get IOleContainer interface poineter.
hr = pIClientSite->GetContainer(&pIContainer) ;
if (hr != S_OK) {
pIClientSite->Release() ;
return NULL ;
}
// Get IServiceProvider interface pointer.
hr = pIClientSite->QueryInterface(IID_IServiceProvider,(void **)&pISP) ;
if (hr != S_OK) {
pIContainer->Release() ;
pIClientSite->Release() ;
return NULL ;
}
// Get IWebBrowser2 interface pointer.
hr = pISP->QueryService(IID_IWebBrowserApp, IID_IWebBrowser2, (void**)&pIWeb) ;
if (hr != S_OK) {
pIContainer->Release() ;
pIClientSite->Release() ;
pISP->Release() ;
return NULL ;
}
// release interface.
pIContainer->Release() ;
pIClientSite->Release() ;
pISP->Release() ;
return pIWeb ;
}
}}}
= IHTMLDocument2 =
{{{#!gcode
inline IHTMLDocument2 *GetDocument(IWebBrowser2* pWebBrower)
{
IHTMLDocument2 *document = NULL;
if (pWebBrower != NULL) {
// get browser document's dispatch interface
IDispatch *document_dispatch = NULL;
HRESULT hr = pWebBrower->get_Document(&document_dispatch);
if (SUCCEEDED(hr) && (document_dispatch != NULL)) {
// get the actual document interface
hr = document_dispatch->QueryInterface(IID_IHTMLDocument2,
(void **)&document);
// release dispatch interface
document_dispatch->Release();
}
}
return document;
}
}}}
= IHTMLWindow2 =
{{{#!gcode
HRESULT hr;
CComVariant vtResult(0);
CComPtr spDisp = NULL;
// 도큐먼트 인터페이스 구하기
IWebBrowser2* pWebBrower = GetIWebPointer();
CComPtr spDocument = GetDocument(pWebBrower);
CComPtr spWindow = NULL;
hr = spDocument->get_parentWindow(&spWindow);
spDocument = NULL;
#if 0 // delete me (예제)
if (SUCCEEDED(hr) && spWindow != NULL)
{
spWindow->execScript(varResult.bstrVal,
CComBSTR(_T("JScript")), &vtResult);
spWindow = NULL;
}
#endif
}}}
----
{{{
}}}