Subclassing a header control to CListCtrl

Hi,
I have a CListCtrl in which I want to replace its CHeaderCtrl to CMyHeaderCtrl. The CListCtrl is created at run-time using create method (not from the resources).
I tried the following code:
int CMyListCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
     if (CListCtrl::OnCreate(lpCreateStruct) == -1)
          return -1;
     
     m_MyHeader.SubclassDlgItem( 0, this);
     
     return 0;
}
This works fine if the CListCtrl is created with WS_VISIBLE style, but unfortunatelly I need it to be created not-visible, and if the WS_VISIBLE style is not set on the creation then the SubclassDlgItem does not succeeded.
I also checked in spy++ that the header-ctrl is not exist after CListCtrl::OnCreate exits.

Can someone please advise ??
thanks,
Yoav.

yoavoAsked:
Who is Participating?
 
Roshan DavisCommented:
Create the List Control with WS_VISBLE style, subclass it , and make it unvisible.

Only first paint comes, the object will draw. So I think , this will not make any difference that creating in invisible style.

GOOD LUCK
0
 
mblatCommented:
Try to do it in PreSubclassWindow() of header control.

Hope it helps...
0
 
mblatCommented:
Try to do it in PreSubclassWindow() of header control.

Hope it helps...
0
 
mblatCommented:
Ok, that's not going to work :-(.

What you can do is this:

1. Derive CMyListCtrl from CListCtrl.
2. Derive CMyHeaderCtrl
3. Overwrite WM_PAINT ( or some other message like this)

 in
 CMyListCtrl
  ......
  CMyHEaderCtrl m_hdr;
  .......
 in there

 static bool bFirstTime = true;

  if(bFirstTime)
  {
    bFirstTime = false;
    m_hdr.SublassWindow(GetHeaderCtrl()->m_hWnd);  
   }



  Hope it helps....
 Typos are possible....
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.