ActiveX控件访问所在网页的DHTML文档对象模型(MFC)

void CICWXPlayerCtrl::SetHolderID(CICWXPlayerWindowHolder::enumHolderIndex iHolderIndex,LPCTSTR lpszElementID)
{
IOleClientSite* pClientSite=GetClientSite();
do{
if(pClientSite==NULL)break;
CComQIPtr pISP(pClientSite);
if(pISP==NULL)break;
CComPtr pIWebBrowser2;
pISP->QueryService(IID_IWebBrowserApp, IID_IWebBrowser2,
(void **)&pIWebBrowser2);
if(pIWebBrowser2==NULL)break;
CComPtr spDocument;
pIWebBrowser2->get_Document(&spDocument);
CComQIPtr pIHTMLDocument2(spDocument);
if(pIHTMLDocument2==NULL)break;
CComPtr pHTMLElementCollection;
pIHTMLDocument2->get_all(&pHTMLElementCollection);
if(pHTMLElementCollection==NULL)break;
COleVariant varName(lpszElementID,VT_BSTR);
COleVariant varindex;

CComPtr spElement;
pHTMLElementCollection->item(varName,varindex,&spElement);
if(spElement==NULL)break;
//is it an Iframe?
CComQIPtr pFrame(spElement);
if(pFrame){
switch(iHolderIndex){
case CICWXPlayerWindowHolder::WebHolder:
case CICWXPlayerWindowHolder::TextHolder:
m_holders[iHolderIndex].SetTarget(spElement);
break;
}
}
CComQIPtr pObjectElement(spElement);
if(pObjectElement==NULL)break;
CComPtr spObject;
pObjectElement->get_object(&spObject);
m_holders[iHolderIndex].SetTarget(spObject);
}
while(FALSE);
}

你可能感兴趣的:(ActiveX控件访问所在网页的DHTML文档对象模型(MFC))