Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to change header color of ListView?
#1
I cant find the example Macro like this,any suggeations? :?:
#2
Is it listview control in your dialog?
If yes, use custom drawing. I did not try it but I think it's possible.
If not, you cannot change color.
#3
google and found this:

http://windowsmobiledn.com/qa-how-can-i ... t-control/
QA: How can I change the background color of the header of a List Control?
January 26th, 2005 by Joao Paulo Figueira
Question

How can I change the background color of the header of a List Control?
Answer

There are two answers for this question: 1 – The window background color is changed by overriding the WM_ERASEBKGND message processing and painting the background with the chosen color (yellow on the picture). 2 – The item background color is changed by using the custom draw service (red and blue items on the picture).

So, how does one go about it? You have to specialize the CListCtrl’s embedded CHeaderCtrl. The sample application shows how this can be done through two specialized classes CColorListCtrl and CColorHeaderCtrl. The list holds an instance of the header which is subclassed when the list is created (or subclassed):


// CColorListCtrl::SubclassHeader
//
// Subclasses the header control, if any
// The return value is used for OnCreate
//
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;
}

There is nothing more to say about CColorListCtrl (by the way, the header control can be subclassed “outside” the list control: we use this here for convenience). Now, let’s see what the CColorHeaderCtrl is doing. First, the 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;
}

As you can see, it is very simple: it just paints the client area with yellow. The item painting code is a bit more tricky because it uses the custom draw service. This service interacts with the window through a message exchange mechanism. It uses the NM_CUSTOMDRAW notification message (reflected here) to tell the window in what stage the drawing process is (we handle CDDS_PREPAINT and CDDS_ITEMPREPAINT) and to request it to override the desired settings. Here, we only change the text and background colors according to the item number:


// CColorHeaderCtrl::OnCustomDraw
//
// Handles custom draw
//
void CColorHeaderCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
NMCUSTOMDRAW* pCD = (NMCUSTOMDRAW*)pNMHDR;
DWORD dwDrawStage, dwItemSpec;

*pResult = CDRF_DODEFAULT;

dwDrawStage = pCD->dwDrawStage;
dwItemSpec = pCD->dwItemSpec;

if(dwDrawStage == CDDS_PREPAINT)
{
*pResult = CDRF_NOTIFYITEMDRAW;
}
else if(dwDrawStage == CDDS_ITEMPREPAINT)
{
HDC hDC = pCD->hdc;

SetTextColor(hDC, RGB(255, 255, 255));

if(dwItemSpec)
SetBkColor(hDC, RGB( 0, 0, 255)); // Blue
else
SetBkColor(hDC, RGB( 255, 0, 0)); // Red

*pResult = CDRF_NEWFONT;
}
}

It works like this: First, the service tells us that it is about to paint the header (CDDS_PREPAINT). We reply saying that we want to be notified for the painting of each item (CDRF_NOTIFYITEMDRAW). Next, the service tells us that it is about to paint an item (CDDS_ITEMPREPAINT). We change the appropriate colors on the DC and reply saying that we did so (CDRF_NEWFONT). Note that we could even have changed the font, specifying a different one per item. For all the other states we don’t care about, we tell the service to do the default painting (CDRF_DODEFAULT).

And that’s it.
Sample

You can download the sample project from here – ListColor.zip (182K).
#4
and found a example: :lol: :lol: :lol:

messages3
NMHDR* nh=+lParam
sel nh.idFrom
case 3 ;;list
sel nh.code
case NM_CUSTOMDRAW
NMLVCUSTOMDRAW* cd=+nh
sel cd.nmcd.dwDrawStage
case CDDS_PREPAINT ret DT_Ret(hDlg CDRF_NOTIFYITEMDRAW)
case CDDS_ITEMPREPAINT
cd.clrTextBk=iif(cd.nmcd.lItemlParam 0xffff iif(cd.nmcd.dwItemSpec&1 0xF8F8F8 0xFFFFFF))
#5
Function dlg_header_custom_draw
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

if(!ShowDialog("dlg_header_custom_draw" &dlg_header_custom_draw)) ret

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;3 SysListView32 0x54030001 0x0 0 0 224 114 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030203 "" "" ""

ret
;messages
int h=id(3 hDlg)
sel message
,case WM_INITDIALOG
,TO_LvAddCol h 0 "A" 100
,TO_LvAddCol h 1 "B" 100
,h=SendMessage(h LVM_GETHEADER 0 0)
,if(_winver>=0x501) SetWindowTheme h L"" L"" ;;cannot change background if themed
,;create several brushes
,__GdiHandle-- b1(CreateSolidBrush(0x80e0e0)) b2(CreateSolidBrush(0x80ffc0)) b3(CreateSolidBrush(0x456789))
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto messages3
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
;messages3
;OutWinMsg message wParam lParam
NMHDR* nh=+lParam
sel nh.idFrom
,case 0
,sel nh.code
,,case NM_CUSTOMDRAW
,,NMCUSTOMDRAW* cd=+nh
,,sel cd.dwDrawStage
,,,case CDDS_PREPAINT
,,,FillRect cd.hdc &cd.rc b3
,,,ret DT_Ret(hDlg CDRF_NOTIFYITEMDRAW)
,,,
,,,case CDDS_ITEMPREPAINT
,,,;out cd.dwItemSpec
,,,;set background color
,,,FillRect cd.hdc &cd.rc iif(cd.dwItemSpec&1 b1 b2)
,,,;set text color
,,,SetTextColor cd.hdc 0xff0000
,,,SetBkMode cd.hdc TRANSPARENT
#6
it works very well,thanks a lot! :lol: :lol: :lol:


Forum Jump:


Users browsing this thread: 1 Guest(s)