you can customize header control of listview control ,refer to http://www.codeguru.com/listview/HeaderCtrlEx.shtml
如果你想这样做的话,就必须重载一个类出来,基类是CLISTCTR。
download http://www.codeguru.com/listview/HeaderCtrlEx_src.zip, decompress it, create a subdirectory "res", put HeaderCtrlEx.ico, HeaderCtrlExDoc.ico, Toolbar.bmp and HeaderCtrlEx.rc2 under "res\", then you can compile the project successfully. the following code change background of header control to red. void CHeaderCtrlEx::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { ASSERT(lpDrawItemStruct->CtlType == ODT_HEADER); HDITEM hdi; TCHAR lpBuffer[256]; hdi.mask = HDI_TEXT; hdi.pszText = lpBuffer; hdi.cchTextMax = 256; GetItem(lpDrawItemStruct->itemID, &hdi); CDC* pDC; pDC = CDC::FromHandle(lpDrawItemStruct->hDC); //THIS FONT IS ONLY FOR DRAWING AS LONG AS WE DON'T DO A SetFont(...) pDC->SelectObject(GetStockObject(DEFAULT_GUI_FONT)); // Draw the button frame. ::DrawFrameControl(lpDrawItemStruct->hDC, &lpDrawItemStruct->rcItem, DFC_BUTTON, DFCS_BUTTONPUSH); UINT uFormat = DT_CENTER; CBrush backbrush(RGB(244,0,20)); ::FillRect(lpDrawItemStruct->hDC,&lpDrawItemStruct->rcItem,backbrush); SetBkMode(lpDrawItemStruct->hDC,TRANSPARENT); //DRAW THE TEXT ::DrawText(lpDrawItemStruct->hDC, lpBuffer, strlen(lpBuffer), &lpDrawItemStruct->rcItem, uFormat); pDC->SelectStockObject(SYSTEM_FONT);}
the following code change background of header control to red.
void CHeaderCtrlEx::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{ ASSERT(lpDrawItemStruct->CtlType == ODT_HEADER); HDITEM hdi;
TCHAR lpBuffer[256]; hdi.mask = HDI_TEXT;
hdi.pszText = lpBuffer;
hdi.cchTextMax = 256; GetItem(lpDrawItemStruct->itemID, &hdi);
CDC* pDC;
pDC = CDC::FromHandle(lpDrawItemStruct->hDC); //THIS FONT IS ONLY FOR DRAWING AS LONG AS WE DON'T DO A SetFont(...)
pDC->SelectObject(GetStockObject(DEFAULT_GUI_FONT));
// Draw the button frame.
::DrawFrameControl(lpDrawItemStruct->hDC,
&lpDrawItemStruct->rcItem, DFC_BUTTON, DFCS_BUTTONPUSH);
UINT uFormat = DT_CENTER;
CBrush backbrush(RGB(244,0,20));
::FillRect(lpDrawItemStruct->hDC,&lpDrawItemStruct->rcItem,backbrush);
SetBkMode(lpDrawItemStruct->hDC,TRANSPARENT);
//DRAW THE TEXT
::DrawText(lpDrawItemStruct->hDC, lpBuffer, strlen(lpBuffer),
&lpDrawItemStruct->rcItem, uFormat); pDC->SelectStockObject(SYSTEM_FONT);}