views:

19

answers:

1

Hi,
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?

A: 

From my copy of MSDN, which I can't seem to find online:

Most common controls can be handled in essentially the same way. However, the list-view and tree-view controls have some features that require a somewhat different approach to custom draw.

For Version 5.0, these two controls may display clipped text if you change the font by returning CDRF_NEWFONT. This behavior is necessary for backward compatibility with earlier versions of the common controls. If you want to change the font of a list-view or tree-view control, you will get better results if you send a CCM_SETVERSION message with the wParam value set to 5 before adding any items to the control.

See also the documentation for CCM_SETVERSION.

Mark Ransom
have you tested it and it worked for you?http://visual-c.itags.org/visual-c-c++/298775/
Greg
tested - of course it doesn't help
Greg