• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1701
  • Last Modified:

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.
0
cophi
Asked:
cophi
  • 3
1 Solution
 
AndyAinscowCommented:
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
 
AndyAinscowCommented:
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
 
AndyAinscowCommented:
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
 
mahesh1402Commented:
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now