How to: Obtain the top-level IWebBrowser2 interface in ActiveX Control

Source: Internet
Author: User
The information in this article is applied to: MicrosoftInternetExplorer (programming) versions 4.0, 4.01, 4.01SP1, 4.01SP2, 5, 5.01, 5.5. Note: support. microsoft. comdefault. aspx? Scidkb; en-us; Q257717 overview Microsoft Knowledge Base Article Q172763 information: Description of Object Model access in ActiveX

Information about this article applies to: Microsoft Internet Explorer (programming) versions 4.0, 4.01, 4.01 SP1, 4.01 SP2, 5, 5.01, 5.5 reporter Note: http://support.microsoft.com/default.aspx? Scid = kb; en-us; Q257717 summary Microsoft Knowledge Base Article Q172763 information: Description of Object Model access in ActiveX

The information in this article is applied:

  • Microsoft Internet Explorer (programming) Version 4.0, 4.01, 4.01 SP1, 4.01 SP2, 5, 5.01, 5.5

Note: http://support.microsoft.com/default.aspx? Scid = kb; en-us; Q257717

Summary

Microsoft Knowledge Base Article

Q172763: access the object model in ActiveX

Describes how to obtain the IWebBrowser2 reference of the window in the control. However, developers often need to reference top-level IWebBrowser2 with a framework set. For example, you can use the statusText () command to set the value of the status bar before loading the webpage. This attribute is invalid for the WebBrowser control, so calling the IWebBrowser2 function of the Framework produces an error.

More information

To obtain the top-level IWebBrowser2 reference, obtain IServiceProvider from the customer site and perform a QueryService operation to obtain the IID_IServiceProvider service SID_STopLevelBrowser (defined in Shlguid. h ). For the second IServiceProvider, execute a QueryService to obtain the IID_IWebBrowser2 service SID_SWebBrowserApp.

The best way to do this is in the SetClientSite () method of IOleObject:

#include 
 
  #define COMRELEASE(ptr)/if (ptr != NULL) {/ptr->Release();/ptr = NULL;/}IWebBrowser2 *browser = NULL;STDMETHODIMP SetClientSite(IOleClientSite *pClientSite){HRESULT hr = S_OK;IServiceProvider *isp, *isp2 = NULL;if (!pClientSite){COMRELEASE(browser);}else{hr = pClientSite->QueryInterface(IID_IServiceProvider, reinterpret_cast
  
   (&isp));if (FAILED(hr)){hr = S_OK;goto cleanup;}hr = isp->QueryService(SID_STopLevelBrowser, IID_IServiceProvider, reinterpret_cast
   
    (&isp2));if (FAILED(hr)){hr = S_OK;goto cleanup;}hr = isp2->QueryService(SID_SWebBrowserApp, IID_IWebBrowser2, reinterpret_cast
    
     (&browser));if (FAILED(hr)){hr = S_OK;goto cleanup;}cleanup:// Free resources.COMRELEASE(isp);COMRELEASE(isp2);return hr;}} 
    
   
  
 

Reference

For more information, click the document number below to view the article in the Microsoft Knowledge Base.

Q172763: access the object model in ActiveX

Yes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.