views:

247

answers:

1

I derived a class from CListCtrl called CListCtrlCustomDraw, and use NM_CUSTOMDRAW handler to draw the list.
The problem is I have different fonts for selected item and unselected item, they are member variables of the list control, but when I use

m_list.SetColumnWidth(iCol, LVSCW_AUTOSIZE); 
int nTextWidth = m_list.GetColumnWidth(iCol);
m_list.SetColumnWidth(iCol, LVSCW_AUTOSIZE_USEHEADER);
int nColTitleWidth = m_list.GetColumnWidth(iCol); 
m_list.SetColumnWidth(iCol,max(nTextWidth, nColTitleWidth));

to calculate the column width, the list use the unselected item's font, which is not as wide
as the selected item's font(bold font), so there will be some content can't be show in the
selected item even they have same content.

Can I set to use which font to calculate column width?
I've tried to set font before the above codes, but there is no effect.
Any advise will be appreciate.

+3  A: 

You'll need to manage the width of the column manually. Use GetTextExtentPoint32 to compute the size of your longest string in your largest font, and set the column width that way.

Mordachai