Change CHeaderCtrl BackGround and TextColor

Is there any way to chnage the background or text color of the CHeaderCtrl without making it ownerdrawn ?  I was able to change the font text pretty easily not to sure about the colors.  Is it maybe easier to not have the header control and draw a label, which would represenet the header.
cophiAsked:
Who is Participating?
 
mahesh1402Connect With a Mentor Commented:
You need owner drawn control only..

You may take help of this :
http://www.codeproject.com/listctrl/filterheaderctrl.asp
http://www.codeproject.com/listctrl/skinlist.asp

Also you may Subclass your control something like

int CColorListCtrl::SubclassHeader()
{
      CHeaderCtrl* pHeader;
      int nRval = 0;

      //
      // Subclass the header control
      //
      pHeader = GetHeaderCtrl();
      if(pHeader && pHeader->GetSafeHwnd())
      {
            if(!m_hdr.SubclassWindow(pHeader->GetSafeHwnd()))
                  nRval = -1;
      }

      return nRval;
}

then Header window backgroung painting code:

// CColorHeaderCtrl::OnEraseBkgnd
//
// This is where we specify the background color of the header
//
BOOL CColorHeaderCtrl::OnEraseBkgnd(CDC* pDC)
{
      CRect rc;
      GetClientRect(&rc);
      pDC->FillSolidRect(&rc, RGB(255, 255, 0)); // Yellow
      return TRUE;
}

-MAHESH
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
I'd do an owner drawn header control.
It really isn't difficult.

There are various ettings that change the appearance of the header control - as you talk about a label use the 'no sort' option of the list control to make the header look more like a label.
Don't forget - no header and it will require code from you to implement column resizing.
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
You might want to look at the WM_CTLCOLOR message.  Intercepting that is the *usual* way to change colours but, I guess, you are talking about a list control which consists of more than one control so that makes it more difficult to supply a text/background colour at that point.
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
I don't know if a header control supports custom draw.  If it does that may be simpler than owner draw for you to implement.
(I've not tried that with a header control).
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.