Subclassing in a composite ATL control 
Author Message
 Subclassing in a composite ATL control

Hi ,
I have a following problem
A composite control includes atlcontrols.h and uses MFC.
I've derived a class like

#include "atlcontrols.h"
using namespace ATLControls;
class CMyListView : public ATLControls::CListViewCtrl
{
public:
 BEGIN_MSG_MAP(CMyListView)
 MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
    END_MSG_MAP()
 CMyListView();
 virtual ~CMyListView();

 LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
 {
  AfxMessageBox("left button down");
  return TRUE;
 }

Quote:
};

I also have in my control class ---------------
public:
 CMyListView m_List;
and -----------
 LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
 {

  m_List.Attach(GetDlgItem(IDC_LIST1));

I am unable to trap window  messages in CMyListView.  What could be the
problem? Am I doing the subclassing wrong>?

Thanks,

D.G.



Tue, 03 Feb 2004 06:53:48 GMT  
 Subclassing in a composite ATL control
Well, yes, you don't subclass at all. Replace Attach with SubclassWindow
and derive your class from CWindowImpl:

class CMyListView :
    piblic CWindowImpl<CMyListView, ATLControls::CListViewCtrl,
CControlTraits>

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================


Quote:
> Hi ,
> I have a following problem
> A composite control includes atlcontrols.h and uses MFC.
> I've derived a class like

> #include "atlcontrols.h"
> using namespace ATLControls;
> class CMyListView : public ATLControls::CListViewCtrl
> {
> public:
>  BEGIN_MSG_MAP(CMyListView)
>  MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
>     END_MSG_MAP()
>  CMyListView();
>  virtual ~CMyListView();

>  LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
> bHandled)
>  {
>   AfxMessageBox("left button down");
>   return TRUE;
>  }
> };

> I also have in my control class ---------------
> public:
>  CMyListView m_List;
> and -----------
>  LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
> bHandled)
>  {

>   m_List.Attach(GetDlgItem(IDC_LIST1));

> I am unable to trap window  messages in CMyListView.  What could be the
> problem? Am I doing the subclassing wrong>?

> Thanks,

> D.G.



Tue, 03 Feb 2004 08:03:57 GMT  
 Subclassing in a composite ATL control
Thanks,
excellent - that is exactly what I was trying to do
class CMyListView :  public CWindowImpl<CMyListView,
ATLControls::CListViewCtrl, CControlWinTraits>
I did subclassing with a separate class but obviously that wasn't the best
solution.

Dmitri


Quote:
> Well, yes, you don't subclass at all. Replace Attach with SubclassWindow
> and derive your class from CWindowImpl:

> class CMyListView :
>     piblic CWindowImpl<CMyListView, ATLControls::CListViewCtrl,
> CControlTraits>

> --
> =====================================
> Alexander Nickolov
> Microsoft MVP [VC], MCSD

> MVP VC FAQ: http://www.mvps.org/vcfaq
> =====================================



> > Hi ,
> > I have a following problem
> > A composite control includes atlcontrols.h and uses MFC.
> > I've derived a class like

> > #include "atlcontrols.h"
> > using namespace ATLControls;
> > class CMyListView : public ATLControls::CListViewCtrl
> > {
> > public:
> >  BEGIN_MSG_MAP(CMyListView)
> >  MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
> >     END_MSG_MAP()
> >  CMyListView();
> >  virtual ~CMyListView();

> >  LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
> > bHandled)
> >  {
> >   AfxMessageBox("left button down");
> >   return TRUE;
> >  }
> > };

> > I also have in my control class ---------------
> > public:
> >  CMyListView m_List;
> > and -----------
> >  LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
> > bHandled)
> >  {

> >   m_List.Attach(GetDlgItem(IDC_LIST1));

> > I am unable to trap window  messages in CMyListView.  What could be the
> > problem? Am I doing the subclassing wrong>?

> > Thanks,

> > D.G.



Tue, 03 Feb 2004 10:04:22 GMT  
 Subclassing in a composite ATL control
Hi,

An Attach behavior of CListViewCtrl in ATL does not provide the needed
Message Map for the control IDC_LIST1. We need to subclass the control with
a class derived from CWindow, and handled the messages there. Therefore, we
can add CWindowImpl<CMyListView> as a based class to resolve this issue:

class CMyListView : public ATLControls::CListViewCtrl,
                     public CWindowImpl<CMyListView>
.....
//Then subclass the control:
....
LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
 {
        m_List.SubclassWindow(GetDlgItem(IDC_LIST1));
  return S_OK;
        }

Thanks,
Freist



Sat, 07 Feb 2004 09:05:17 GMT  
 Subclassing in a composite ATL control
This derivation is incorrect - you derive from CWindow twice.
See my previous post.

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================


Quote:
> Hi,

> An Attach behavior of CListViewCtrl in ATL does not provide the needed
> Message Map for the control IDC_LIST1. We need to subclass the control
with
> a class derived from CWindow, and handled the messages there. Therefore,
we
> can add CWindowImpl<CMyListView> as a based class to resolve this issue:

> class CMyListView : public ATLControls::CListViewCtrl,
>                      public CWindowImpl<CMyListView>
> .....
> //Then subclass the control:
> ....
> LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
> bHandled)
>  {
> m_List.SubclassWindow(GetDlgItem(IDC_LIST1));
>   return S_OK;
> }

> Thanks,
> Freist



Sun, 08 Feb 2004 05:09:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. ATL Full Control - mouse activation problems in Composite Control

2. ATL Full Control - mouse activation problems in Composite Control

3. Using ActiveX controls in ATL Composite control

4. Message Handling - Controls - ATL Composite Controls

5. How to invoke methods of contained ActiveX control from ATL Composite Control

6. mfc control in atl composite control wont destruct

7. Standard Windows Controls in ATL Composite Control

8. mfc control instantiated in atl composite control using CAxWindow wont destruct

9. A composite control calling another composite control in web browser

10. Composite control hosted by a composite control.

11. VC7 ATL Composite Control bug?

12. atl composite control

 

 
Powered by phpBB® Forum Software