Article ID: 202009
Article Last Modified on 5/11/2006
public IDispatchImpl<ICtrlUI, &IID_ICtrlUI, &LIBID_DHTMLCONTROLLib>,From COM_MAP, replace the following two lines:
COM_INTERFACE_ENTRY(ICtrlUI)
COM_INTERFACE_ENTRY2(IDispatch, ICtrl)
with
)
COM_INTERFACE_ENTRY(IDispatch)
// ICtrlUI
public:
// Example method called by the HTML to change the <BODY> background color
STDMETHOD(OnClick)(IDispatch* pdispBody, VARIANT varColor)
{
CComQIPtr<IHTMLBodyElement> spBody(pdispBody);
if (spBody != NULL)
spBody->put_bgColor(varColor);
return S_OK;
}
// Example method that will be called by the HTML HRESULT OnClick([in]IDispatch* pdispBody, [in]VARIANT varColor);Remove original ICtrlUI interface from interface definition:
[
object, dual,
uuid(C3920EDB-BAD6-11D2-AFA1-00A0C9C9E6C5),
helpstring("ICtrlUI Interface"),
pointer_default(unique)
]
interface ICtrlUI : IDispatch
{
};
Remove original ICtrlUI interface from Ctrl coclass:
interface ICtrlUI;
#include "uiobj.h"
...
LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
CAxWindow wnd(m_hWnd);
HRESULT hr = wnd.CreateControl(IDH_CTRL);
if (SUCCEEDED(hr))
{
// Create sub-object - this implements our window.external methods to be called from HTML
hr = CComObject<CUIObj>::CreateInstance( &m_pUI );
if ( SUCCEEDED(hr) )
{
CComQIPtr<IDispatch> pDisp(m_pUI);
hr = wnd.SetExternalDispatch(pDisp);
}
}
if (SUCCEEDED(hr))
hr = wnd.QueryControl(IID_IWebBrowser2, (void**)&m_spBrowser);
return SUCCEEDED(hr) ? 0 : -1;
}
CComObject<CUIObj>* m_pUI;
[
uuid(....),
help string("UIObj class"),
noncreatable
]
coclass UIObj
{
...
}
188015 TITLE: HOWTO: Access Methods/Properties of Container from Script
Additional query words: kbDSupport kbbeta
Keywords: kbbug kbwebbrowser kbmshtml kbdhtml kbpending KB202009