开发者

CListCtrl: how to get column width when use different fonts on same column?

开发者 https://www.devze.com 2022-12-13 09:23 出处:网络
I derived a class from CListCtrl called CListCtrlCustomDraw, and use NM_CUSTOMDRAW handler to draw the list.

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 o开发者_如何学JAVAf 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消