0

First of all, i would customize - among other things - color of text and selection color(text background). For example, text color should be blue; color of text background should be transparent. So, I have overriden OnPaint() method; I call SetTextColor() and SetBkColor() functions, but unfortunately I always get invalid colors, or I get an annoying "infinite loop flash" effect. Here you can see his complete implementation.

void CustomTree::OnPaint() 
{
    CPaintDC dc(this);

    CDC memDC;
    memDC.CreateCompatibleDC(&dc);

    CRect rcClip, rcClient;
    dc.GetClipBox( &rcClip );
    GetClientRect(&rcClient);

    CBitmap bitmap;
    bitmap.CreateCompatibleBitmap( &dc, rcClient.Width(), rcClient.Height() );
    memDC.SelectObject( &bitmap );

    CRgn rgn;
    rgn.CreateRectRgnIndirect( &rcClip );
    memDC.SelectClipRgn(&rgn);
    rgn.DeleteObject();

    /* WHAT IS the correct usage of SetText/Bk Color? */

    // ::SetTextColor(memDC, RGB(0, 0, 255));
    // ::SetBkColor(memDC, RGB(0, 0, 255));
    // COLORREF col = SetTextColor(RGB(0,0,255));
    // COLORREF co2 = memDC.SetTextColor(RGB(0,0,255));

    // First let the control do its default drawing.

    CWnd::DefWindowProc(WM_PAINT, (WPARAM)memDC.m_hDC, 0);

    // do some others stuffs...

    dc.BitBlt(rcClip.left, rcClip.top, rcClip.Width(), rcClip.Height(), &memDC, 
                rcClip.left, rcClip.top, SRCCOPY);

    memDC.DeleteDC();
}

Where is the error?

Thanks

IT

IT.
  • 311
  • 1
  • 5
  • 24

1 Answers1

0

If you want to change color and font for a treeview, you have to catch and respond to NM_CUSTOMDRAW. Simply setting the properties before calling the default is insufficient.

Joel Lucsy
  • 8,520
  • 1
  • 29
  • 35