1. IWebBrowser2 #
- inline IWebBrowser2* GetIWebPointer()
- {
- HRESULT hr ;
- IOleContainer *pIContainer = NULL ;
- IWebBrowser2 *pIWeb = NULL ;
- IServiceProvider *pISP = NULL ;
-
- LPOLECLIENTSITE pIClientSite = NULL;
- GetClientSite(&pIClientSite);
-
- hr = pIClientSite->GetContainer(&pIContainer) ;
- if (hr != S_OK) {
- pIClientSite->Release() ;
- return NULL ;
- }
-
- hr = pIClientSite->QueryInterface(IID_IServiceProvider,(void **)&pISP) ;
- if (hr != S_OK) {
- pIContainer->Release() ;
- pIClientSite->Release() ;
- return NULL ;
- }
-
- hr = pISP->QueryService(IID_IWebBrowserApp, IID_IWebBrowser2, (void**)&pIWeb) ;
- if (hr != S_OK) {
- pIContainer->Release() ;
- pIClientSite->Release() ;
- pISP->Release() ;
- return NULL ;
- }
-
- pIContainer->Release() ;
- pIClientSite->Release() ;
- pISP->Release() ;
- return pIWeb ;
- }
2. IHTMLDocument2 #
- inline IHTMLDocument2 *GetDocument(IWebBrowser2* pWebBrower)
- {
- IHTMLDocument2 *document = NULL;
- if (pWebBrower != NULL) {
-
- IDispatch *document_dispatch = NULL;
- HRESULT hr = pWebBrower->get_Document(&document_dispatch);
- if (SUCCEEDED(hr) && (document_dispatch != NULL)) {
-
- hr = document_dispatch->QueryInterface(IID_IHTMLDocument2,
- (void **)&document);
-
- document_dispatch->Release();
- }
- }
- return document;
- }
3. IHTMLWindow2 #
- HRESULT hr;
- CComVariant vtResult(0);
- CComPtr<IDispatch> spDisp = NULL;
-
- IWebBrowser2* pWebBrower = GetIWebPointer();
- CComPtr<IHTMLDocument2> spDocument = GetDocument(pWebBrower);
- CComPtr<IHTMLWindow2> 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