ATL Event Handling and IDispatch Implementation RRS feed

  • Question

  • Hi.


    I'm working on an ActiveX control using attributed ATL8 with MFC8 support under Visual Studio 2005. The control acts as a rich content editor. It's class (let's refer to her: CMyControl) derives from CComCompositeControl (using an empty dialog template) and hosts a Internet Explorer WebBrowser ("Shell.Explorer.2", CLSID_WebBrowser) using CAxWindow. The WebBrowser is customized as much as I was able to do so, so CMyControl also derives from

    IHTMLEditDesigner and IDocHostUIHandler.


    [ coclass ... ]

    class ATL_NO_VTABLE CMyControl :

    public IMyControl,


    public CComCompositeControl<CMyControl >,

    public IDispEventImpl<1001, CMyControl >,

    public IDispatchImpl<IHTMLEditDesigner, &IID_IHTMLEditDesigner, &LIBID_ATLLib>,

    public IDispatchImpl<IDocHostUIHandler, &IID_IDocHostUIHandler, &LIBID_ATLLib>





    During the initialization (WM_INITDIALOG) I'm creating the WebBrowser, attaching the designer, setting the IDocHostUIHandler and many, many more things. The usage of a dialog-based control makes my editor reacting on keys such as Delete or Ctrl-C.


    Is that ok (in that story so far) ?


    The WebBrowser is hosted using the CAxWindow, a child of CMyControl window. I'm receiving events from WebBrowser using fully automated IDispEventImpl class. Additionally, I have a toolbar and tweaked context menu, using NewMenu (created by Bruno Podetti), which are implemented in MFC (so my ActiveX control works only when it is hosted in MFC application...).


    Or I did it incorrectly...?


    I can't host the WebBrowser manually (custom OLE containment), as the WebBrowser asks it's IOleClientSink for IDocHostShowUI, IDocHostUIHandler, IDocHostUIHandler2... Other customization techniques also requires own "QueryInterface() provider". The sample EditHost shows very chaotic piece of ATL code, which still doesn't satisfy me.




    According to Rob Manderson and his article, there's a trick in receiving the IDispatch::Invoke()-based events. For instance, I'd like to receive DISPID_HTMLELEMENTEVENTS_ONDRAGSTART from a certain HTML element, so I hook myself (CMyControl) with



    CComVariant vEventDispatchTarget(this);




    How to react on this event without implementing Invoke() on my own? Has anybody done anything like that?


    I'd be very grateful for some valueable advices from experienced COM-programmer, especially Internet Explorer Developers. I picked "Visual C++ General" for this thread, as ATL seems to be little more problem-making than WebBrowser/MSHTML.


    Best regards

     ~ ~ Mario


    p.s. I can't show you my codes, as they are the property of company I'm working with.

    Friday, August 31, 2007 1:42 PM