#import <mshtml.tlb>
#import <shdocvw.dll>SHDocVw::IShellWindowsPtr m_spSHWinds;
if(m_spSHWinds==NULL)
{
if(m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows))!=S_OK)
{
AfxMessageBox("Create instance Failed!");
CoUninitialize();
...
}
}
...CoInitialize(NULL);
...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);
if(spBrowser)
{
spBrowser->AddRef();
MSHTML::IHTMLDocument2Ptr spDoc=spBrowser->GetDocument();
if(spDoc==NULL)
break; BSTR bsTitle;
spDoc->get_title(&bsTitle);
CString strTitle=(CString)bsTitle;
//MessageBox(strTitle,"IE窗口标题",MB_OK);
...
}
}
}.../////////////////////////////////////////////////
以上代码在IE5中实现,
如何才能在IE7中实现呢?吐血跪求各位路过大哥!!!!!!!!!!

解决方案 »

  1.   

    偶在Win2K+IE5下实现不知道IE7在XP、Vista下实现方法有什么不同
      

  2.   

    CoInitialize要放在最前面,然后才能CoCreateInstance
      

  3.   

    HWND hWnd = ::FindWindow(TEXT("IEFrame"), NULL);while (hWnd)
    {
        ::PostMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0);
        Sleep(100);
        hWnd = ::FindWindow(TEXT("IEFrame"), NULL);
    }
      

  4.   

    不好意思,没注意看LZ的问题
    我以为你要关闭所有IE窗口呢
      

  5.   

    IE 7没有直接的API来提供相关的TAB窗口枚举,看看下面的思路:2) I use EnumWindows to find all windows of the class IEFrame.  
    Those are just HWND’s and cannot be cast to IWebBrowser objects; you’ll see the point of getting HWND’s at all in a bit.3) I use the IShellWindows interface – obtained using CoCreateInstance(CLSID_ShellWindows) – 
    to enumerate all shell windows on the system.  I then cast each one to an IWebBrowser2.  
    This actually works for both IE windows and explorer windows, so I need to get rid of the explorer windows.  
    So I call IWebBrowser2->get_hwnd() on each window.  For IE tabs, this doesn’t give you the HWND for the tab, 
    it gives you the HWND for the top-level IE window. 
    So I check the get_hwnd() value against my IEFrame HWND list from step (2), and anything that doesn’t match isn’t an IE tab.4) Now I have IWebBrowser2 objects for each tab, and if I care, I know which IE windows they belong to.  
    If I want to enumerate open URL’s, this is enough; I can call get_LocationURL() to get the URL from each tab.5) If I want to open a link in the active tab, I can’t just call IWebBrowser2->navigate() or IWebBrowser2->navigate2(),
     because this opens a new tab.  And in fact I can’t even ask which tab is active through this interface.  So I cast each one 
    to an IServiceProvider, then to an IOleWindow, on which I call GetWindow, which gives me the HWND for each tab.  
    Then I can call ::IsWindowEnabled(hwnd); the active tab is always enabled and the background tabs are not.  
    Now I know which of my IWebBrowser2’s is the active tab.6) I get an IHTMLDocument2 from that IWebBrowser2 (via get_document()) and call set_url() on the document, 
    which opens a specified document in that tab (note that using IWebBrowser2->navigate() still opens a new tab, 
    so I use the IHTMLDocument2 approach instead...)
      

  6.   

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=924475&SiteID=1