当前的树在视图中,并且为实现多选继承了一个多选树,在设置节点颜色时,无法重绘节点颜色,单独做个程序试就好用,发现没有进入到封装的树的ONPAINT函数,是否是因为当前的为视图类?如何解决该问题呢?请各位帮帮忙哦!先谢!!!

解决方案 »

  1.   

    ON_NOTIFY ( NM_CUSTOMDRAW,ID,fun)
    void fun(NMHDR* pNMHDR, LRESULT* pResult)
    {
    NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );

        // Take the default processing unless we set this to something else below.
        *pResult = CDRF_DODEFAULT;

        // First thing - check the draw stage. If it's the control's prepaint
        // stage, then tell Windows we want messages for every item.
    if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
    {
            *pResult = CDRF_NOTIFYITEMDRAW;
    }
        else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
    {
            // This is the notification message for an item.  We'll request
            // notifications before each subitem's prepaint stage.

            *pResult = CDRF_NOTIFYSUBITEMDRAW;
    COLORREF clrNewTextColor, clrNewBkColor;       HTREEITEM    nItem = (HTREEITEM)( pLVCD->nmcd.dwItemSpec );

    BOOL bSelect = FALSE;

    HTREEITEM  selitem = m_TreeTest.GetSelectedItem();
    if (selitem==nItem)
    bSelect = TRUE;


    if(bSelect)
    {
    clrNewTextColor = RGB(255,255,255); //Set the text to red
    clrNewBkColor = RGB(49,106,197); //Set the bkgrnd color to blue
    }
    else
    {

    clrNewTextColor = RGB(0,0,0); //Leave the text black
    clrNewBkColor = RGB(255,255,255); //leave the bkgrnd color white
    }

    pLVCD->clrText = clrNewTextColor;
    pLVCD->clrTextBk = clrNewBkColor;

            
            // Tell Windows to paint the control itself.
            *pResult = CDRF_DODEFAULT;
            
            

    }
        else if ( (CDDS_ITEMPREPAINT | CDDS_SUBITEM) == pLVCD->nmcd.dwDrawStage )
    {
            
            // Tell Windows to paint the control itself.
            *pResult = CDRF_DODEFAULT;
            
            
    }
    }
      

  2.   

    反正就离不开自画控件,要么就是CUSTOMDRAW,要么就是OwnerDraw