Subclassing an ActiveX control 
Author Message
 Subclassing an ActiveX control

Hi,

In my project, I need to override some functionality of the MSHTML control.
At first, I attempted to simply create a window that derives from the
CAxWindow class, like so:

class CMyHtmlControl : public CWindowImpl< CMyHtmlControl, CAxWindow >
{
    ...
    BEGIN_MSG_MAP( CMyHtmlControl )
        MESSAGE_HANDLER( WM_CREATE, OnCreate )
        MESSAGE_HANDLER(...)
    END_MSG_MAP( )

    LRESULT OnCreate(UINT, WPARAM, LPARAM, BOOL&)
    {
        IUnkown* pMSHTMLUnk = NULL
        // create the control
        ...
        AttachControl( pMSHTMLUnk, NULL);
        return 0;
    }
    ...

Quote:
}

However, my window proc wasn't being called at all after the WM_CREATE
message. Next, I tried this with the CAxHostWindow:

class CMyHtmlControl : public CWindowImpl< CMyHtmlControl >
{
    ...
    CComObject< CAxHostWindow > m_wndAxCtrl;

    HWND Create( HWND hWndParent, ATL::_U_RECT rect, DWORD dwStyle, DWORD
dwExStyle )
    {
        IUnkown* pMSHTMLUnk = NULL
        // create the control
        ...
        m_wndAxCtrl.Create( hWndParent, rect, NULL, dwStyle, dwExStyle );
        m_wndAxCtrl.AttachControl( pMSHTMLUnk, m_wndAxCtrl.m_hWnd );
        SubclassWindow( m_wndAxCtrl.m_hWnd );
    }

    BEGIN_MSG_MAP( CMyHtmlControl )
        MESSAGE_HANDLER(...)
    END_MSG_MAP( )
     ...

Quote:
};

Unfortunately, this didn't help either - with Spy++, I could see that the
only messages my window was getting was WM_MOUSEACTIVATE and
WM_PARENTNOTIFY. Is there any way to subclass an ActiveX control's window
proc? I'm sorry if this seems like a really easy question, I'm pretty new to
ATL.

Thanks,
Yury



Wed, 02 Jun 2004 01:43:21 GMT  
 Subclassing an ActiveX control
Check with Spy++ - WebBrowser control has window hierarchy 4 levels
deep. You a very likely subclassing wrong window. What's the ultimate
goal?
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Quote:
> Hi,

> In my project, I need to override some functionality of the MSHTML
control.
> At first, I attempted to simply create a window that derives from the
> CAxWindow class, like so:

> class CMyHtmlControl : public CWindowImpl< CMyHtmlControl, CAxWindow >
> {
>     ...
>     BEGIN_MSG_MAP( CMyHtmlControl )
>         MESSAGE_HANDLER( WM_CREATE, OnCreate )
>         MESSAGE_HANDLER(...)
>     END_MSG_MAP( )

>     LRESULT OnCreate(UINT, WPARAM, LPARAM, BOOL&)
>     {
>         IUnkown* pMSHTMLUnk = NULL
>         // create the control
>         ...
>         AttachControl( pMSHTMLUnk, NULL);
>         return 0;
>     }
>     ...
> }

> However, my window proc wasn't being called at all after the WM_CREATE
> message. Next, I tried this with the CAxHostWindow:

> class CMyHtmlControl : public CWindowImpl< CMyHtmlControl >
> {
>     ...
>     CComObject< CAxHostWindow > m_wndAxCtrl;

>     HWND Create( HWND hWndParent, ATL::_U_RECT rect, DWORD dwStyle,
DWORD
> dwExStyle )
>     {
>         IUnkown* pMSHTMLUnk = NULL
>         // create the control
>         ...
>         m_wndAxCtrl.Create( hWndParent, rect, NULL, dwStyle,
dwExStyle );
>         m_wndAxCtrl.AttachControl( pMSHTMLUnk, m_wndAxCtrl.m_hWnd );
>         SubclassWindow( m_wndAxCtrl.m_hWnd );
>     }

>     BEGIN_MSG_MAP( CMyHtmlControl )
>         MESSAGE_HANDLER(...)
>     END_MSG_MAP( )
>      ...
> };

> Unfortunately, this didn't help either - with Spy++, I could see that
the
> only messages my window was getting was WM_MOUSEACTIVATE and
> WM_PARENTNOTIFY. Is there any way to subclass an ActiveX control's
window
> proc? I'm sorry if this seems like a really easy question, I'm pretty
new to
> ATL.

> Thanks,
> Yury



Wed, 02 Jun 2004 02:08:15 GMT  
 Subclassing an ActiveX control
Igor,

No, I checked again, the hierarchy is 2 levels - the first window is
classname "AtlAxWin7", and its child is "Internet Explorer_Server". I am not
using the WebBrowser control - instead, I chose to just use the MSHTML to
shave off 1 mb from the footprint, since I don't need in-place linking. The
goal is for my window to have first crack at some mouse and menu messages.
You could be right though, since I'm subclassing the AtlAxWin7 and not the
internet explorer window.

How would I get the handle to that window then? And suppose I would want to
do the same thing for a windowless control - would the subclassing procedure
be different then?

Thanks for your insight,
Yury


Quote:
> Check with Spy++ - WebBrowser control has window hierarchy 4 levels
> deep. You a very likely subclassing wrong window. What's the ultimate
> goal?
> --
> With best wishes,
>     Igor Tandetnik

> "For every complex problem, there is a solution that is simple, neat,
> and wrong." H.L. Mencken



> > Hi,

> > In my project, I need to override some functionality of the MSHTML
> control.
> > At first, I attempted to simply create a window that derives from the
> > CAxWindow class, like so:

> > class CMyHtmlControl : public CWindowImpl< CMyHtmlControl, CAxWindow >
> > {
> >     ...
> >     BEGIN_MSG_MAP( CMyHtmlControl )
> >         MESSAGE_HANDLER( WM_CREATE, OnCreate )
> >         MESSAGE_HANDLER(...)
> >     END_MSG_MAP( )

> >     LRESULT OnCreate(UINT, WPARAM, LPARAM, BOOL&)
> >     {
> >         IUnkown* pMSHTMLUnk = NULL
> >         // create the control
> >         ...
> >         AttachControl( pMSHTMLUnk, NULL);
> >         return 0;
> >     }
> >     ...
> > }

> > However, my window proc wasn't being called at all after the WM_CREATE
> > message. Next, I tried this with the CAxHostWindow:

> > class CMyHtmlControl : public CWindowImpl< CMyHtmlControl >
> > {
> >     ...
> >     CComObject< CAxHostWindow > m_wndAxCtrl;

> >     HWND Create( HWND hWndParent, ATL::_U_RECT rect, DWORD dwStyle,
> DWORD
> > dwExStyle )
> >     {
> >         IUnkown* pMSHTMLUnk = NULL
> >         // create the control
> >         ...
> >         m_wndAxCtrl.Create( hWndParent, rect, NULL, dwStyle,
> dwExStyle );
> >         m_wndAxCtrl.AttachControl( pMSHTMLUnk, m_wndAxCtrl.m_hWnd );
> >         SubclassWindow( m_wndAxCtrl.m_hWnd );
> >     }

> >     BEGIN_MSG_MAP( CMyHtmlControl )
> >         MESSAGE_HANDLER(...)
> >     END_MSG_MAP( )
> >      ...
> > };

> > Unfortunately, this didn't help either - with Spy++, I could see that
> the
> > only messages my window was getting was WM_MOUSEACTIVATE and
> > WM_PARENTNOTIFY. Is there any way to subclass an ActiveX control's
> window
> > proc? I'm sorry if this seems like a really easy question, I'm pretty
> new to
> > ATL.

> > Thanks,
> > Yury



Wed, 02 Jun 2004 09:53:11 GMT  
 Subclassing an ActiveX control
For a windowless control, mouse messages actually come to AtlAx window,
which then forwards them to the control in the form of
IOleInPlaceObjectWindowless::OnWindowMessage call.

For windowed controls, query the control for IOleWindow and call
IOleWindow::GetWindow to obtain control's HWND. Be aware that there may
be windowed controls on the page itself (e.g. <SELECT> control), in
which case window hierarchy is deeper and you will lose some mouse
messages. You can preprocess all messages inside the message loop -
after GetMessage but before DispatchMessage. Or, you can install a
message hook - see SetWindowsHookEx.

For MSHTML control in particular, you can intercept mouse messages
through DOM events. The control generates onclick, ondblclick,
onmousemove and so on. Be aware that if you handle mouse events this
way, you will receive them after any scripted event handlers present on
the page.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Quote:
> Igor,

> No, I checked again, the hierarchy is 2 levels - the first window is
> classname "AtlAxWin7", and its child is "Internet Explorer_Server". I
am not
> using the WebBrowser control - instead, I chose to just use the MSHTML
to
> shave off 1 mb from the footprint, since I don't need in-place
linking. The
> goal is for my window to have first crack at some mouse and menu
messages.
> You could be right though, since I'm subclassing the AtlAxWin7 and not
the
> internet explorer window.

> How would I get the handle to that window then? And suppose I would
want to
> do the same thing for a windowless control - would the subclassing
procedure
> be different then?

> Thanks for your insight,
> Yury



> > Check with Spy++ - WebBrowser control has window hierarchy 4 levels
> > deep. You a very likely subclassing wrong window. What's the
ultimate
> > goal?
> > --
> > With best wishes,
> >     Igor Tandetnik

> > "For every complex problem, there is a solution that is simple,
neat,
> > and wrong." H.L. Mencken



> > > Hi,

> > > In my project, I need to override some functionality of the MSHTML
> > control.
> > > At first, I attempted to simply create a window that derives from
the
> > > CAxWindow class, like so:

> > > class CMyHtmlControl : public CWindowImpl< CMyHtmlControl,
CAxWindow >
> > > {
> > >     ...
> > >     BEGIN_MSG_MAP( CMyHtmlControl )
> > >         MESSAGE_HANDLER( WM_CREATE, OnCreate )
> > >         MESSAGE_HANDLER(...)
> > >     END_MSG_MAP( )

> > >     LRESULT OnCreate(UINT, WPARAM, LPARAM, BOOL&)
> > >     {
> > >         IUnkown* pMSHTMLUnk = NULL
> > >         // create the control
> > >         ...
> > >         AttachControl( pMSHTMLUnk, NULL);
> > >         return 0;
> > >     }
> > >     ...
> > > }

> > > However, my window proc wasn't being called at all after the
WM_CREATE
> > > message. Next, I tried this with the CAxHostWindow:

> > > class CMyHtmlControl : public CWindowImpl< CMyHtmlControl >
> > > {
> > >     ...
> > >     CComObject< CAxHostWindow > m_wndAxCtrl;

> > >     HWND Create( HWND hWndParent, ATL::_U_RECT rect, DWORD
dwStyle,
> > DWORD
> > > dwExStyle )
> > >     {
> > >         IUnkown* pMSHTMLUnk = NULL
> > >         // create the control
> > >         ...
> > >         m_wndAxCtrl.Create( hWndParent, rect, NULL, dwStyle,
> > dwExStyle );
> > >         m_wndAxCtrl.AttachControl( pMSHTMLUnk,

m_wndAxCtrl.m_hWnd );

- Show quoted text -

Quote:
> > >         SubclassWindow( m_wndAxCtrl.m_hWnd );
> > >     }

> > >     BEGIN_MSG_MAP( CMyHtmlControl )
> > >         MESSAGE_HANDLER(...)
> > >     END_MSG_MAP( )
> > >      ...
> > > };

> > > Unfortunately, this didn't help either - with Spy++, I could see
that
> > the
> > > only messages my window was getting was WM_MOUSEACTIVATE and
> > > WM_PARENTNOTIFY. Is there any way to subclass an ActiveX control's
> > window
> > > proc? I'm sorry if this seems like a really easy question, I'm
pretty
> > new to
> > > ATL.

> > > Thanks,
> > > Yury



Sat, 05 Jun 2004 00:51:17 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Subclassing an ActiveX control

2. subclassing ListView32 in an activex-control

3. subclassing controls w/ ActiveX

4. ActiveX Control: Subclassing from ListView

5. Subclassing Activex controls from commctrl (treectrl) in MFC

6. Control webbrowser ActiveX control in composit ActiveX control

7. ActiveX control inside another activex control

8. Need help with ActiveX control containing other activex controls

9. ATL ActiveX Control hosting code fails to initialize ActiveX Controls on Win9x

10. ActiveX control inside another ActiveX control

11. Need help with ActiveX control containing other activex controls

12. ActiveX control in an ActiveX control

 

 
Powered by phpBB® Forum Software