Search This Blog

Thursday, January 1, 2009

Getting all Titles in Internet explorer running instance using COM

#import "mshtml.tlb" // Internet Explorer 5
#include "msHtml.h"
#include "ExDispID.h"
#import "shdocvw.dll"

#include "ExDisp.h"

void CIETabTiltleDlg::OnBnClickedOk() // Copy the following lines
{
SHDocVw::IShellWindowsPtr m_spSHWinds;
m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows));
ASSERT(m_spSHWinds != NULL);

CString strCount,m_strWinCount;
long nCount = m_spSHWinds->GetCount();
strCount.Format("%i", nCount);
m_strWinCount = strCount;

IDispatchPtr spDisp;
for (long i = 0; i <>
{
_variant_t va(i, VT_I4);
spDisp = m_spSHWinds->Item(va);
SHDocVw::IWebBrowser2Ptr spBrowser(spDisp);
if (spBrowser != NULL)
{
//m_ctlListLoc is the name of list box of your application

m_ctlListLoc.AddString(spBrowser->GetLocationName());
MSHTML::IHTMLDocument2Ptr spDoc(spBrowser->GetDocument());
if (spDoc != NULL)
{
//m_ctlListTitle is the name of list box of your application
m_ctlListTitle.AddString(spDoc->Gettitle());
}
}
}
m_spSHWinds=NULL;
}

No comments: