分类: C/C++
2008-08-01 16:55:35
{ TCHAR HostName[2*MAX_PATH]; CComPtr本程序在VC7 WINXP下编译通过,详细请看源代码! 下载本文示例代码spDispatch; CComQIPtr pDoc2; CComPtr pElementCol; CComPtr pLoct; // TODO: Add your control notification handler code here int n = m_LinksList.GetItemCount();//GetCount(); for (int i = 0; i < n; i ){ IWebBrowser2 *pBrowser = (IWebBrowser2 *)m_LinksList.GetItemData(i); if (pBrowser){ pBrowser->Release(); } } m_LinksList.DeleteAllItems(); m_LinksNum = 0; Log("**************************************************************"); Log("\r\n"); if (m_spSHWinds){ int n = m_spSHWinds->GetCount(); for (int i = 0; i < n; i ){ _variant_t v = (long)i; IDispatchPtr spDisp = m_spSHWinds->Item(v); SHDocVw::IWebBrowser2Ptr spBrowser(spDisp); //生成一个IE窗口的智能指针 if (spBrowser){ if (SUCCEEDED(spBrowser->get_Document( &spDispatch))) pDoc2 = spDispatch; if(pDoc2!=NULL) { if (SUCCEEDED(pDoc2->get_links(&pElementCol))) { // AfxMessageBox("IHTMLElementCollection"); long p=0; if(SUCCEEDED(pElementCol->get_length(&p))) if(p!=0) { m_LinksNum = m_LinksNum p; UpdateData(FALSE); for(long i=0;i<=(p-1);i ) { BSTR String; _variant_t index = i; if(SUCCEEDED(pElementCol->item( index, index, &spDispatch))) if(SUCCEEDED(spDispatch->QueryInterface( IID_IHTMLAnchorElement,(void **) &pLoct))) pLoct->get_href(&String); ZeroMemory(HostName,2*MAX_PATH); lstrcpy(HostName,_bstr_t(String)); m_LinksList.InsertItem(i,HostName); m_LinksList.SetCheck(i,TRUE); pLoct->get_hostname(&String); ZeroMemory(HostName,2*MAX_PATH); lstrcpy(HostName,_bstr_t(String)); if(lstrlen(HostName)) { m_LinksList.SetItemText(i,1,HostName); Log(HostName ); Log("\r\n"); } } } } } } } } }