How can I change the height of the header in a ListView ?

Hello,

is there an easy way to adjust the Header's Height for ListView?

Thanks
Best regards,
Thomas

tsp2002Asked:
Who is Participating?
 
mahesh1402Connect With a Mentor Commented:
Here's an approach that might work for you:
1) Choose a font size with height approximately what you want the header to be, then set the header font to it - something like:

// one time initialization
m_sizingFont.CreatePointFont(180, "MS Sans Serif");
m_normalFont.CreatePointFont(80, "MS Sans Serif");

CHeaderCtrl * pHdrCtrl = m_listCtrl.GetHeaderCtrl();

pHdrCtrl->SetFont(&m_sizingFont);

2) Make each header item owner draw.
// for each column do something like the following:
HD_ITEM curItem;

pHdrCtrl->GetItem(column, &curItem);
curItem.mask = HDI_FORMAT;
curItem.fmt = HDF_OWNERDRAW;

pHdrCtrl->SetItem(column, &curItem);

3) Finally, Draw header items, which may be trivial or complex depending on your applkication. The following snippet merely uses whatever was set in the each header item, which you have to do anyway.

void MyListCtrl::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT pdis )
{
ASSERT(pdis->CtlType == ODT_HEADER);

CDC * pdc = CDC::FromHandle(pdis->hDC);
CFont * pOldFont = pdc->SelectObject(&m_normalFont);

LVCOLUMN col;
char buff[64];

col.mask = LVCF_IMAGE | LVCF_TEXT;
col.pszText = buff;
col.cchTextMax = sizeof(buff);

GetColumn(pdis->itemID, &col);

CRect rect(pdis->rcItem);
rect.left += 2;
int height = pdc->DrawText(buff, rect, DT_SINGLELINE | DT_LEFT | DT_TOP | DT_END_ELLIPSIS);

rect.top += height;
m_headerImageList.Draw(pdc, pdis->iImage, rect.TopLeft(), ILD_NORMAL);

pdc->SelectObject(pOldFont);
}


Hope this helps
-MAHESH
0
 
Jaime OlivaresSoftware ArchitectCommented:
there is not an easy way, you have to do owner-draw.
0
 
tsp2002Author Commented:
I now how to do a owner-draw...changed the color of the listview text before.
But how do I get the height and width?
0
 
tsp2002Author Commented:
Hi Mahesh,
thanks for the code...let you know shortly
Best regards
Thomas
0
 
tsp2002Author Commented:
Hi Mahesh,
I can work from here.
Thank you.
Here are your 500 points.
Best regards,
Thomas
0
All Courses

From novice to tech pro — start learning today.