C++/(COM)IWeb Browser2와 IHTML Document2, IHTML Window2 구하기 Edit Diff Refresh Backlink Random Search History Help Setting Hide Show Contents 1. IWebBrowser2 2. IHTMLDocument2 3. IHTMLWindow2 1. IWebBrowser2 # 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 ; } 2. IHTMLDocument2 # 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; } 3. IHTMLWindow2 # 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 C++ COM IHTMLDocument2 IHTMLWindow2 IWebBrowser2 이 글에는 0 개의 댓글이 있습니다. Please enable JavaScript to view the comments powered by Disqus. comments powered by Disqus