请注意,因为ie中可能有框架,所以我以下的代码只能获得框架网页的url,我想或得的是整个ie的标题和url.这个脚本该怎么写?
  <script language="VBScript">
Sub OnContextMenu()
   set srcEvent = external.menuArguments.event
   set EventElement = external.menuArguments.document.elementFromPoint(srcEvent.clientX, srcEvent.clientY)
   set fd_Catch=CreateObject("AA.Api")
   Alert(external.menuArguments.document.Url)
   Call fd_Catch.Addurl(external.menuArguments.document.Url)
end Sub
call OnContextMenu()
</script>

解决方案 »

  1.   

    换个说法吧:怎么在IE上点右键菜单,得到这个IE的IHtmlDocument2*啊?
      

  2.   


    标题     根据Internet Explorer_Server窗口得到IHtmlDocument2接口    111222(收藏)  
      
    关键字     根据Internet Explorer_Server窗口得到IHtmlDocument2接口/IE/WebBrowser 
      
    代码很少,自己看#include <mshtml.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;
    };//You can store the interface pointer in a member variable 
    //for easier access
    void CDlg::OnGetDocInterface(HWND hWnd) 
    {
     CoInitialize( NULL ); // Explicitly load MSAA so we know if it's installed
     HINSTANCE hInst = ::LoadLibrary( _T("OLEACC.DLL") );
     if ( hInst != NULL )
     {
      if ( hWnd != NULL )
      {
       HWND hWndChild=NULL;
       // Get 1st document window
       ::EnumChildWindows( hWnd, EnumChildProc, (LPARAM)&hWndChild );
       if ( hWndChild )
       {
        CComPtr<IHTMLDocument2> spDoc;
        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) )
         {
          CComPtr<IDispatch> spDisp;
          CComQIPtr<IHTMLWindow2> spWin;
          spDoc->get_Script( &spDisp );
          spWin = spDisp;
          spWin->get_document( &spDoc.p );
          // Change background color to red
          spDoc->put_bgColor( CComVariant("red") );
         }
        }
       } // else document not ready
      } // else Internet Explorer is not running
      ::FreeLibrary( hInst );
     } // else Active Accessibility is not installed
     CoUninitialize();
    }