I change the font of tree items in CTreeCtrl with the following code:
void CTreeCtrlEx::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMTVCUSTOMDRAW pNMCD = reinterpret_cast<LPNMTVCUSTOMDRAW>(pNMHDR);
*pResult = 0;
switch(pNMCD->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
*pResult = CDRF_NOTIFYITEMDRAW;
return;
case CDDS_ITEMPREPAINT:
{
CFont * pco_font = GetSomeFont();
::SelectObject(pNMCD->nmcd.hdc, pco_font->GetSafeHandle());
*pResult = CDRF_NEWFONT;
}
return;
}
}
However, the end of the text is being clipped in the items, apparently it is not being
adjusted to the length of the text with the new font.
what would be the remedy?
I had the same problem and can confirm that CCM_SETVERSION did not work. In fact the only thing that worked reliably for me was to re-set the text after the paint process was finished. The way I did it was by catching the TVN_ITEMEXPANDING message and by re-setting the text. This would correct the text of all sub-items when a node is expanded. Of course this does not work for bold root nodes.
Here is a sketch of my code: