HOWTO: Connect to a Running Instance of Internet Explorer Q176792 -------------------------------------------------------------------------------- The information in this article applies to:Microsoft Internet Explorer (Programming) versions 4.0, 4.01, 5 Microsoft Internet Client SDK, versions 4.0, 4.01 In C++, a connection can be accomplished in roughly the same way. Visual C++ Native Com Support is used here for the sake of brevity. Add references to Shdocvw.dll and Mshtml.dll to the project: #import <mshtml.dll> // Internet Explorer 4.0x #import <mshtml.tlb> // Internet Explorer 5 #import <shdocvw.dll> Declare an instance of an IShellWindows pointer in your view class: SHDocVw::IShellWindowsPtr m_spSHWinds; Create an instance of a ShellWindows object in your view's constructor: m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows)); Use the ShellWindows object in your view's OnInitialUpdate function: 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 information in this article applies to:Microsoft Internet Explorer (Programming) versions 4.0, 4.01, 5
Microsoft Internet Client SDK, versions 4.0, 4.01
In C++, a connection can be accomplished in roughly the same way. Visual C++ Native Com Support is used here for the sake of brevity. Add references to Shdocvw.dll and Mshtml.dll to the project: #import <mshtml.dll> // Internet Explorer 4.0x
#import <mshtml.tlb> // Internet Explorer 5
#import <shdocvw.dll>
Declare an instance of an IShellWindows pointer in your view class: SHDocVw::IShellWindowsPtr m_spSHWinds;
Create an instance of a ShellWindows object in your view's constructor: m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows));
Use the ShellWindows object in your view's OnInitialUpdate function: 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());
}
}
}
}
http://playguy.onchina.net
1.EnumWindows,这个代码简单,但我这里的代码没有了,你到网络上找找吧
2.GetWindow和GetNextWindow一起使用,可以枚举所有窗口!见MSDN就可以了,代码很简单的!