Microsoft KB Archive/247073

= CustWBC.exe sample shows how to control the WebBrowser control that is embedded in an ATL HTML control =

Article ID: 247073

Article Last Modified on 6/7/2005

-

APPLIES TO

 Microsoft ActiveX Template Library 3.0, when used with:  Microsoft Visual C++ 6.0 Enterprise Edition

 Microsoft Visual C++ 6.0 Professional Edition

 Microsoft Visual C++ 6.0 Standard Edition 

-

<div class="notice_section">

This article was previously published under Q247073

<div class="summary_section">

SUMMARY
CustWBC.exe is a sample that illustrates how you can control the WebBrowser control that is embedded in an ATL HTML control. In particular, the sample demonstrates three points:
 * 1) How to provide a custom implementation of the IDocHostUIHandlerDispatch interface. The custom implementation disables the context menu of the WebBrowser control.
 * 2) How to extend the functionality of the WebBrowser control with additional methods accessible through window.external from within the control's HTML. This feature is present in Wizard-generated code, but take special actions to integrate this feature into your custom IDocHostUIHandlerDispatch.
 * 3) How to provide a sink for the WebBrowser control events. The sink interface presented here reacts when the browser notifies your control that the user requested to navigate in a new browser window (by shift+clicking a link). Instead of opening a new window, use the window already open to go to the requested URL.

<div class="moreinformation_section">

MORE INFORMATION
The following file is available for download from the Microsoft Download Center:

CustWBC.exe

Release Date: May 17, 2000

For more information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 How to obtain Microsoft support files from online services

Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help prevent any unauthorized changes to the file. The implementation of the HTML control actually requires four separate objects: the control itself, the object that implements the IDocHostUIHandlerDispatch interface, the object that implements the extender methods, and the object that implements the sink. You need all four objects because all of them need to implement IDispatch.

The IDocHostUIHandlerDispatch implementation returns E_NOTIMPL for most of the methods except the ShowContextMenu method. This method returns S_OK without displaying anything. This convinces the WebBrowser control that it doesn't need to do anything about the right button click.

The sink only implements the Invoke method of IDispatch as follows: STDMETHOD (Invoke) (DISPID dispidMember, REFIID riid, LCID lcid,                       WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult,                        EXCEPINFO* pexcepinfo, UINT* puArgErr) {     HRESULT hr = S_OK; if (pdispparams) {        switch (dispidMember) {        // When a request comes in asking for a new window, go to the // URL specified in the request, but within the old Web browser window. case DISPID_NEWWINDOW: // case DISPID_FRAMENEWWINDOW: if (m_pBrowser) {              VARIANT defArg; defArg.vt = VT_ERROR; defArg.scode = DISP_E_PARAMNOTFOUND; m_pBrowser->Navigate(pdispparams->rgvarg[5].bstrVal,                          &defArg, &defArg, pdispparams->rgvarg[2].pvarVal, &defArg); }           *(pdispparams->rgvarg[0].pboolVal) = VARIANT_TRUE; hr = S_OK; break; default: hr = DISP_E_PARAMNOTFOUND; break; }     }      else hr = DISP_E_PARAMNOTFOUND;

return hr; } Finally, the control's OnCreate method instantiates all these elements and sets everything up.

(c) Microsoft Corporation 1999, All Rights Reserved. Contributions by Cosmin Radu, Microsoft Corporation.

<div class="references_section">