Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. ATL experts, help! Navigating to a new page in an ATL Active X control

ATL experts, help! Navigating to a new page in an ATL Active X control

Scheduled Pinned Locked Moved ATL / WTL / STL
c++helptutorialcom
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mcase
    wrote on last edited by
    #1

    I wrote an Active X control using only ATL (no MFC), for use on a web page. When the control ends, it needs to go to another web page within the SAME IE browser window. I am currently using: ShellExecute(NULL,"open",NewPage,NULL,NULL,SW_SHOW) to do this. The problem is that this opens the new web page (whose URL is NewPage) in the default Browser, which isn't always always IE (it might be Netscape for example). It also opens a new IE window if the user has unselected "Reuse windows for launching shortcuts" in their IE Internet options. The most common problem, however, is that it opens a new "tab" in "Slimbrowser" and other "tab" based browsers. The only solution seems to be to get a "IServiceProvider" pointer to the current browser window, then I can do a "IServiceProvider::QueryService" to get a "IWebBrowser2" pointer, and then use "IWebBrowser2::Navigate" to go to the new URL in the same window. This technique is described here: http://msdn.microsoft.com/msdnmag/issues/01/06/c/ However, I can't for the life of me figure out how to get the "IServiceProvider" pointer. In the above mentioned article, they said they got the pointer from the "Active Accessibility SDK", but not how. Also, I would prefer not to have to use this SDK. I'm sure there is an easier way to do this. Remember that I can't use MFC! Thanks in advance for any help you can give me!

    J 1 Reply Last reply
    0
    • M mcase

      I wrote an Active X control using only ATL (no MFC), for use on a web page. When the control ends, it needs to go to another web page within the SAME IE browser window. I am currently using: ShellExecute(NULL,"open",NewPage,NULL,NULL,SW_SHOW) to do this. The problem is that this opens the new web page (whose URL is NewPage) in the default Browser, which isn't always always IE (it might be Netscape for example). It also opens a new IE window if the user has unselected "Reuse windows for launching shortcuts" in their IE Internet options. The most common problem, however, is that it opens a new "tab" in "Slimbrowser" and other "tab" based browsers. The only solution seems to be to get a "IServiceProvider" pointer to the current browser window, then I can do a "IServiceProvider::QueryService" to get a "IWebBrowser2" pointer, and then use "IWebBrowser2::Navigate" to go to the new URL in the same window. This technique is described here: http://msdn.microsoft.com/msdnmag/issues/01/06/c/ However, I can't for the life of me figure out how to get the "IServiceProvider" pointer. In the above mentioned article, they said they got the pointer from the "Active Accessibility SDK", but not how. Also, I would prefer not to have to use this SDK. I'm sure there is an easier way to do this. Remember that I can't use MFC! Thanks in advance for any help you can give me!

      J Offline
      J Offline
      Jason De Arte
      wrote on last edited by
      #2

      You're on the right track. But missing one detail - IOleObject::GetClientSite Here's a code snip that I used in a recent ATL based ActiveX control to get the IHTMLDocument2 interface of the parent IE WebBrowser. Sure it goes a little farther than what you want by getting the document (one extra call), but it demonstrates the concept.

      inline HRESULT GetIEDocument(IOleObject* pObject, IHTMLDocument2 ** ppDocument2 )
      {
      CComPtr<IOleClientSite> spClientSite;
      CComPtr<IServiceProvider> spSrvProv;
      CComPtr<IWebBrowser2> spWebBrowser;
      CComPtr<IHTMLDocument2> spHTMLDoc2;

      // Param check
      if( !ppDocument2 || !pObject )
      {
      	ATLASSERT(!"Bad pointer param");
      	return E\_POINTER;
      }
      
      //
      // Dig our way up to the Document that contains us
      //
      HRESULT hr = pObject->GetClientSite((IOleClientSite \*\*)&spClientSite);
      if( FAILED(hr) )
      	return hr;
      
      hr = spClientSite->QueryInterface(IID\_IServiceProvider, (void \*\*)&spSrvProv);
      if( FAILED(hr) )
      	return hr;
      
      hr = spSrvProv->QueryService(SID\_SWebBrowserApp, IID\_IWebBrowser2, (void \*\*)&spWebBrowser);
      if( FAILED(hr) )
      	return hr;
      
      hr = spWebBrowser->get\_Document((LPDISPATCH\*)&spHTMLDoc2);
      if( FAILED(hr) )
      	return hr;
      
      //
      // All Done
      //
      (\*ppDocument2) = spHTMLDoc2;
      (\*ppDocument2)->AddRef();
      return S\_OK;
      

      }

      BTW, To the best of my knowlege ActiveX controls don't work in Nutscrape. Did you find a way for them to work? [ Jason De Arte | Toy Maker | 1001010.com ]

      M 2 Replies Last reply
      0
      • J Jason De Arte

        You're on the right track. But missing one detail - IOleObject::GetClientSite Here's a code snip that I used in a recent ATL based ActiveX control to get the IHTMLDocument2 interface of the parent IE WebBrowser. Sure it goes a little farther than what you want by getting the document (one extra call), but it demonstrates the concept.

        inline HRESULT GetIEDocument(IOleObject* pObject, IHTMLDocument2 ** ppDocument2 )
        {
        CComPtr<IOleClientSite> spClientSite;
        CComPtr<IServiceProvider> spSrvProv;
        CComPtr<IWebBrowser2> spWebBrowser;
        CComPtr<IHTMLDocument2> spHTMLDoc2;

        // Param check
        if( !ppDocument2 || !pObject )
        {
        	ATLASSERT(!"Bad pointer param");
        	return E\_POINTER;
        }
        
        //
        // Dig our way up to the Document that contains us
        //
        HRESULT hr = pObject->GetClientSite((IOleClientSite \*\*)&spClientSite);
        if( FAILED(hr) )
        	return hr;
        
        hr = spClientSite->QueryInterface(IID\_IServiceProvider, (void \*\*)&spSrvProv);
        if( FAILED(hr) )
        	return hr;
        
        hr = spSrvProv->QueryService(SID\_SWebBrowserApp, IID\_IWebBrowser2, (void \*\*)&spWebBrowser);
        if( FAILED(hr) )
        	return hr;
        
        hr = spWebBrowser->get\_Document((LPDISPATCH\*)&spHTMLDoc2);
        if( FAILED(hr) )
        	return hr;
        
        //
        // All Done
        //
        (\*ppDocument2) = spHTMLDoc2;
        (\*ppDocument2)->AddRef();
        return S\_OK;
        

        }

        BTW, To the best of my knowlege ActiveX controls don't work in Nutscrape. Did you find a way for them to work? [ Jason De Arte | Toy Maker | 1001010.com ]

        M Offline
        M Offline
        mcase
        wrote on last edited by
        #3

        Thanks Jason! I only had to make a few changes to get your code working in my app. I didn't need to pass the "IOleObject* pObject" object, since this code was in the same class as the main ATL ActiveX control. Aside from that, I just had to add the template definitions for the ATL classes used (IOleClientSite,IServiceProvider,IWebBrowser2). Also, "m_sLandingPage" is a global char* to the URL to navigate to. I think this code should work in almost any ATL ActiveX control. And no, unfortunately, we weren't able to figure out a way to get ActiveX controls to work in Netscape, after much effort. The conclusion we came to was that it would require so much of Java wrapper that it was impractical. bool Ccompctrl::LaunchURL() { CComPtr spClientSite; CComPtr spSrvProv; CComPtr spWebBrowser; HRESULT hr = GetClientSite((IOleClientSite **)&spClientSite); if( FAILED(hr) ) return false; hr = spClientSite->QueryInterface(IID_IServiceProvider, (void **)&spSrvProv); if( FAILED(hr) ) return false; hr = spSrvProv->QueryService(SID_SWebBrowserApp, IID_IWebBrowser2, (void **)&spWebBrowser); if( FAILED(hr) ) return false; CComVariant vNull; CComBSTR bsLandingPage = m_sLandingPage; hr = spWebBrowser->Navigate(bsLandingPage, &vNull, &vNull, &vNull, &vNull); if( FAILED(hr) ) return false; return true; }

        1 Reply Last reply
        0
        • J Jason De Arte

          You're on the right track. But missing one detail - IOleObject::GetClientSite Here's a code snip that I used in a recent ATL based ActiveX control to get the IHTMLDocument2 interface of the parent IE WebBrowser. Sure it goes a little farther than what you want by getting the document (one extra call), but it demonstrates the concept.

          inline HRESULT GetIEDocument(IOleObject* pObject, IHTMLDocument2 ** ppDocument2 )
          {
          CComPtr<IOleClientSite> spClientSite;
          CComPtr<IServiceProvider> spSrvProv;
          CComPtr<IWebBrowser2> spWebBrowser;
          CComPtr<IHTMLDocument2> spHTMLDoc2;

          // Param check
          if( !ppDocument2 || !pObject )
          {
          	ATLASSERT(!"Bad pointer param");
          	return E\_POINTER;
          }
          
          //
          // Dig our way up to the Document that contains us
          //
          HRESULT hr = pObject->GetClientSite((IOleClientSite \*\*)&spClientSite);
          if( FAILED(hr) )
          	return hr;
          
          hr = spClientSite->QueryInterface(IID\_IServiceProvider, (void \*\*)&spSrvProv);
          if( FAILED(hr) )
          	return hr;
          
          hr = spSrvProv->QueryService(SID\_SWebBrowserApp, IID\_IWebBrowser2, (void \*\*)&spWebBrowser);
          if( FAILED(hr) )
          	return hr;
          
          hr = spWebBrowser->get\_Document((LPDISPATCH\*)&spHTMLDoc2);
          if( FAILED(hr) )
          	return hr;
          
          //
          // All Done
          //
          (\*ppDocument2) = spHTMLDoc2;
          (\*ppDocument2)->AddRef();
          return S\_OK;
          

          }

          BTW, To the best of my knowlege ActiveX controls don't work in Nutscrape. Did you find a way for them to work? [ Jason De Arte | Toy Maker | 1001010.com ]

          M Offline
          M Offline
          mcase
          wrote on last edited by
          #4

          I guess the same thing happened to you that just happened to me. The the template definitions, which were inclosed in "<>" were lost because it was considered HTML. Here are the correct first three lines : CComPtr spClientSite; CComPtr spSrvProv; CComPtr spWebBrowser;

          J 1 Reply Last reply
          0
          • M mcase

            I guess the same thing happened to you that just happened to me. The the template definitions, which were inclosed in "<>" were lost because it was considered HTML. Here are the correct first three lines : CComPtr spClientSite; CComPtr spSrvProv; CComPtr spWebBrowser;

            J Offline
            J Offline
            Jason De Arte
            wrote on last edited by
            #5

            d'oh! Updated. [ Jason De Arte | Toy Maker | 1001010.com ]

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups