如何获得IE的URL地址??
请详细说说!

解决方案 »

  1.   

    你看一下CHtmlView的成员函数不就知道了。
    CString GetLocationURL( ) const;
      

  2.   

    include <Mshtml.h>
    #include <windows.h>
    #include <stdio.h>
    #include <comdef.h>
    #include <tchar.h>
    #include <atlbase.h>
    #include <oleacc.h>
    BOOL CALLBACK EnumChildProc(HWND hwnd,LPARAM lParam)
    {
    TCHAR buf[100]; ::GetClassName( hwnd, (LPTSTR)&buf, 100 );
    if ( _tcscmp( buf, _T("Internet Explorer_Server") ) == 0 )
    {
    *(HWND*)lParam = hwnd;
    return FALSE;
    }
    else
    return TRUE;
    };IHTMLDocument2*  GetDocInterface(HWND  hWnd)    
    {  
               //  我们需要显示地装载OLEACC.DLL,这样我们才知道有没有安装MSAA  
               HINSTANCE  hInst  =  ::LoadLibrary(  _T("OLEACC.DLL")  );  
               IHTMLDocument2*  pDoc2=NULL;  
               if  (  hInst  !=  NULL  ){  
        HWND hWndChild=NULL;
    // Get 1st document window
    ::EnumChildWindows( hWnd, EnumChildProc, (LPARAM)&hWndChild );                       if  (  hWndChild  !=  NULL  ){  
                                       CComPtr<IHTMLDocument>  spDoc=NULL;  
                                       LRESULT  lRes;  
     
                                       UINT  nMsg  =  ::RegisterWindowMessage(  _T("WM_HTML_GETOBJECT")  );  
                                       ::SendMessageTimeout(  hWndChild,  nMsg,  0L,  0L,  SMTO_ABORTIFHUNG,  1000,  (DWORD*)&lRes  );  
     
                                       LPFNOBJECTFROMLRESULT  pfObjectFromLresult  =  (LPFNOBJECTFROMLRESULT)::GetProcAddress(  hInst,  _T("ObjectFromLresult")  );  
                                       if  (  pfObjectFromLresult  !=  NULL  ){  
                                                   HRESULT  hr;  
                                                   hr=pfObjectFromLresult(lRes,IID_IHTMLDocument,0,(void**)&spDoc);  
                                                   if  (  SUCCEEDED(hr)  )
       {  
       printf("here\n");
                                                               CComPtr<IDispatch>  spDisp;  
                                                               CComQIPtr<IHTMLWindow2>  spWin;  
                                                               spDoc->get_Script(  &spDisp  );  
                                                               spWin  =  spDisp;  
                                                               spWin->get_document(  &pDoc2  );  
                                                   }  
                                       }  
       else
       {
       printf("pfObjectFromLresult  ==  NULL\n");
       }
                           }  
                           ::FreeLibrary(hInst);  
               }    
               else{//如果没有安装MSAA  
                           printf(_T("请您安装Microsoft  Active  Acces\nsibility"));  
               }  
               return  pDoc2;  
    }    
    BOOL CALLBACK EnumWindowsProc(
      HWND hwnd,      // handle to parent window
      LPARAM lParam   // application-defined value
    )
    {
    IHTMLDocument2* pdoc2=GetDocInterface(hwnd);
    if(pdoc2!=NULL)
    {
    BSTR bsturl;
    pdoc2->get_URL(&bsturl); printf("find IE window:%x,url:%s\n",hwnd,(char*)_bstr_t(bsturl));
    SysFreeString(bsturl);
    pdoc2->Release();
    }
    // else
    // printf("%x is not IE window\n",hwnd);
    return true;
    }
    void main()
    {
    CoInitialize(NULL);
    EnumWindows(EnumWindowsProc,0);
    CoUninitialize();
    }