HOWTO: Access Methods/Properties of Container From ScriptID: Q188015
|
When hosting the WebBrowser control in a Visual C++ application, it may be necessary to access methods or properties of the container from script on a Web page. This article describes how to do this by implementing the IDocHostUIHandler interface.
By implementing the IDocHostUIHandler interface, you can control many of
the User Interface features of the WebBrowser control in your hosting
application. IDocHostUIHandler also allows you to extend the Dynamic HTML
(DHTML) Object Model to access methods and properties of the container from
within script.
The GetExternal() method of IDocHostUIHandler provides this functionality.
When script on a Web page calls "window.external.yourMethod," the
WebBrowser control calls your GetExternal method to retrieve a pointer to
the IDispatch of your hosting application. It is through this pointer that
the WebBrowser control is able to access your methods and properties.
Once the WebBrowser control has a pointer to the IDispatch of the
container, it then calls IDispatch::GetIDsOfNames() to get the DISPID of
the method or property called from script, yourMethod in this case.
Finally, the WebBrowser control calls IDispatch::Invoke() with the DISPID
retrieved from GetIDsOfNames().
Here are the steps you must follow to extend the DHTML Object Model to be
able to access the container's methods and properties from script:
STDMETHOD(GetExternal)(IDispatch** ppDispatch)
{
*ppDispatch = this; // Assumes you inherit from IDispatch
return S_OK;
}
STDMETHODIMP CAtlBrCon::Invoke(DISPID dispidMember, REFIID riid,
LCID lcid, WORD wFlags,
DISPPARAMS* pDispParams,
VARIANT* pvarResult,
EXCEPINFO* pExcepInfo, UINT* puArgErr)
{
switch (dispidMember)
{
case DISPID_MYMETHOD_OR_PROPERTY:
// Do something here
default:
return E_INVALIDARG;
}
return S_OK;
}
<SCRIPT LANGUAGE="VBScript">
Sub SomeControl_OnClick
window.external.yourMethod
End Sub
</SCRIPT>
For more information about the technologies discussed in this article, please refer to the documentation regarding Advanced Hosting Interfaces and IDocHostUIHandler in the MSDN Online Web Workshop:
http://msdn.microsoft.com/workshop/(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Scott Roberts, Microsoft Corporation
Additional query words: kbIE400 kbIE401 kbWebBrowser kbIE401sp1
Keywords : kbIE400 kbIE401 kbWebBrowser kbIE500
Version : WINDOWS:4.0,4.01,4.01 SP1
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: April 27, 1999