以下是MSDN上的说明,非常管用,我在IE5成功!位于Knowledge Base/Internet Explore Development/How to Connecting to a running instance of IE Add references to Shdocvw.dll and Mshtml.dll to the project: #import "mshtml.h" #import "shdocvw.dll" exclude("tagREADYSTATE") Declare an instance of an IShellWindows pointer: SHDocVw::IShellWindowsPtr m_spSHWinds; Create an instance of a ShellWindows object: m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows)); Use the ShellWindows object: void CConnectIEView::OnInitialUpdate() { CFormView::OnInitialUpdate(); ASSERT(m_spSHWinds != NULL); CString strCount; long nCount = m_spSHWinds->GetCount(); strCount.Format("%i", nCount); m_strWinCount = strCount; UpdateData(FALSE); IDispatchPtr spDisp; for (long i = 0; i < nCount; i++) { _variant_t va(i, VT_I4); spDisp = m_spSHWinds->Item(va); SHDocVw::IWebBrowser2Ptr spBrowser(spDisp); if (spBrowser != NULL) { m_ctlListLoc.AddString(spBrowser->GetLocationName()); MSHTML::IHTMLDocument2Ptr spDoc(spBrowser->GetDocument()); if (spDoc != NULL) { m_ctlListTitle.AddString(spDoc->Gettitle()); } } } } The previous method for connecting to a running instance of the Internet Explorer does not work if Shell Integration is not installed or if "Browse in a new process" is selected in Internet Explorer 4.0.
看看你有没有注册正确?
Add references to Shdocvw.dll and Mshtml.dll to the project:
#import "mshtml.h"
#import "shdocvw.dll" exclude("tagREADYSTATE")
Declare an instance of an IShellWindows pointer: SHDocVw::IShellWindowsPtr m_spSHWinds;
Create an instance of a ShellWindows object: m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows));
Use the ShellWindows object: void CConnectIEView::OnInitialUpdate()
{
CFormView::OnInitialUpdate(); ASSERT(m_spSHWinds != NULL); CString strCount;
long nCount = m_spSHWinds->GetCount(); strCount.Format("%i", nCount);
m_strWinCount = strCount; UpdateData(FALSE); IDispatchPtr spDisp;
for (long i = 0; i < nCount; i++)
{
_variant_t va(i, VT_I4);
spDisp = m_spSHWinds->Item(va); SHDocVw::IWebBrowser2Ptr spBrowser(spDisp);
if (spBrowser != NULL)
{
m_ctlListLoc.AddString(spBrowser->GetLocationName()); MSHTML::IHTMLDocument2Ptr spDoc(spBrowser->GetDocument());
if (spDoc != NULL)
{
m_ctlListTitle.AddString(spDoc->Gettitle());
}
}
}
}
The previous method for connecting to a running instance of the Internet Explorer does not work if Shell Integration is not installed or if "Browse in a new process" is selected in Internet Explorer 4.0.