所有的IE都是在一个进程中不同的线程中运行的,所以用一般的方法是不太好用的,我以前也做了一个获取IE句柄的程序,不过是很久以前的事情了,凭记忆随便讲一下吧,可能还要你自己在去研究一下
1。在头文件中加入以下几行(我只稍稍试了试,没有做到底)
#include<commctrl.h>
#import"mshtml.tlb"
//或msthml.dll
#import"showcvw.dll"exclude("tagREADYSTATE")
2。用CoInitialize(NULL)与CoUninitalize()来初始化COM接口
3。IE未在运行对象表中注册,而是在ShellWindows中,声明以下变量用以得到ShellWindows对象
SHDocVw::IShellWindowsPtr  spsWnds;
spsWnds.CreateInstance(__uuidof(SHDocVw::ShellWindows));
if( NULL == spsWnds )
    //没有Shellwindow启动,IE也就没运行了
long count = spsWnds->GetCount();
if( count<0 )
//没有Shellwindow启动,IE也就没运行了
//==0时有一个
4.获取一个IE窗口
IDispatchPtr  spDisp;
long index;  //从0到Count-1循环
_variant_t  va(index , VI_I4 );  
spDisp=spsWnd->Item( va );
SHDocVw::IWebBrowserzPtr  spBrowser( spDisp );
if( NULL == spBrowser )
//无IE运行
得到IE后就可以用GetDocument与SetDocument等此类的函数来控制此IE了(很长时间了,有些什么函数也忘了,不过如果对VC与COM都较熟的话获得IE后就很简单了)
另外还得视当前的IE版本灵活应用,不同的版本相应函数也不同

解决方案 »

  1.   

    所有的IE都是在一个进程中不同的线程中运行的,所以用一般的方法是不太好用的,我以前也做了一个获取IE句柄的程序,不过是很久以前的事情了,凭记忆随便讲一下吧,可能还要你自己在去研究一下
    1。在头文件中加入以下几行(我只稍稍试了试,没有做到底)
    #include<commctrl.h>
    #import"mshtml.tlb"
    //或msthml.dll
    #import"showcvw.dll"exclude("tagREADYSTATE")
    2。用CoInitialize(NULL)与CoUninitalize()来初始化COM接口
    3。IE未在运行对象表中注册,而是在ShellWindows中,声明以下变量用以得到ShellWindows对象
    SHDocVw::IShellWindowsPtr  spsWnds;
    spsWnds.CreateInstance(__uuidof(SHDocVw::ShellWindows));
    if( NULL == spsWnds )
        //没有Shellwindow启动,IE也就没运行了
    long count = spsWnds->GetCount();
    if( count<0 )
    //没有Shellwindow启动,IE也就没运行了
    //==0时有一个
    4.获取一个IE窗口
    IDispatchPtr  spDisp;
    long index;  //从0到Count-1循环
    _variant_t  va(index , VI_I4 );  
    spDisp=spsWnd->Item( va );
    SHDocVw::IWebBrowserzPtr  spBrowser( spDisp );
    if( NULL == spBrowser )
    //无IE运行
    得到IE后就可以用GetDocument与SetDocument等此类的函数来控制此IE了(很长时间了,有些什么函数也忘了,不过如果对VC与COM都较熟的话获得IE后就很简单了)
    另外还得视当前的IE版本灵活应用,不同的版本相应函数也不同
      

  2.   

    The following Visual C++ source code demonstrates how to implement this in your own application. This code uses smart pointers created by the #import statement. You must include this #import statement in one of your source code files, preferably Stdafx.h: 
    #import "C:\winnt\system32\mshtml.tlb" // location of mshtml.tlb   void CMyClass::ExecuteScriptFunction()
       {
          // m_WebBrowser is an instance of IWebBrowser2
          MSHTML::IHTMLDocument2Ptr spDoc(m_WebBrowser.GetDocument());      if (spDoc)
          {
             IDispatchPtr spDisp(spDoc->GetScript());
             if (spDisp)
             {
                // Evaluate is the name of the script function.
                OLECHAR FAR* szMember = L"evaluate";
                DISPID dispid;            HRESULT hr = spDisp->GetIDsOfNames(IID_NULL, &szMember, 1,
                                               LOCALE_SYSTEM_DEFAULT, &dispid);            if (SUCCEEDED(hr))
                {
                   COleVariant vtResult;
                   static BYTE parms[] = VTS_BSTR;               COleDispatchDriver dispDriver(spDisp);               dispDriver.InvokeHelper(dispid, DISPATCH_METHOD, VT_VARIANT,
                                           (void*)&vtResult, parms,
                                           "5+Math.sin(9)");
                }
             }
          }
       } 
      

  3.   

    查阅msdn:how to connect internet explorer
      

  4.   

    只要打破进程边界,用COM编程就好了!!
      

  5.   

    只要打破进程边界,用COM编程就好了!!