Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » Skinned CExtTreeCtrl Collapse All
Subject Author Date
Robert Hofstetter May 25, 2010 - 1:47 AM

Could you tell me if the CExtTreeCtrl skinnable?


My dialog window has blackdiamond skin and its tree control has black texts on white background.


Is it possible to make the tree control to have white texts on the same black gradient background as the dialog?


If yes, could you show me some sample code?


Thanks

Technical Support May 25, 2010 - 9:05 AM

First of all, you will need to override the CExtTreeCtrl::OnPaintEntireTree() virtual method in your CExtTreeCtrl-derived class:

void C_YOUR_TreeCtrl::OnPaintEntireTree( CDC & dc )
{
            ASSERT_VALID( this );
            ASSERT( dc.GetSafeHdc() != NULL );
CRect rcClient;
            GetClientRect( &rcClient );
COLORREF clrTreeBkColor = TreeBkColorGet();
            if( clrTreeBkColor == COLORREF(-1L) )
                        clrTreeBkColor = ::GetSysColor( COLOR_WINDOW );
            if( ! PmBridge_GetPM()->PaintDockerBkgnd( true, dc, this ) ) // try to paint themed dialog background first
                        dc.FillSolidRect( &rcClient, clrTreeBkColor ); // if paint manager does not support it, then paint default background
CFont * pOldFont = dc.SelectObject( &m_fontNormal );
COLORREF clrBackgroundOld = dc.SetBkColor( clrTreeBkColor );
COLORREF clrText = ::GetSysColor( COLOR_BTNTEXT );
COLORREF clrTextOld = dc.SetTextColor( clrText );
int nOldBkMode = dc.SetBkMode( TRANSPARENT );
bool bFocusedWindow = OnQueryWindowFocusedState();
HTREEITEM htiFirst = GetNextItem( NULL, TVGN_FIRSTVISIBLE );
HTREEITEM htiFocus = GetFocusedItem();
HTREEITEM htiDH = GetNextItem( NULL, TVGN_DROPHILITE );
HTREEITEM hti = htiFirst;
            for( ; hti != NULL; hti = GetNextItem( hti, TVGN_NEXTVISIBLE ) )
            {
                        bool bDisabledItem = ! OnQueryItemEnabledState( hti );
                        bool bFocusedItem = ( hti == htiFocus ) ? true : false;
                        bool bSelectedItem = IsItemSelected( hti );
                        bool bDH = ( hti == htiDH ) ? true : false;
                        CRect rcItemEntire;
                        TreeItemRectGet( hti, rcItemEntire, e_tirt_entire );
                        if( rcItemEntire.top > rcClient.bottom )
                                    break;
                        OnPaintTreeItem(
                                    hti,
                                    dc,
                                    rcItemEntire,
                                    bFocusedWindow,
                                    bDisabledItem,
                                    bSelectedItem,
                                    bFocusedItem,
                                    bDH/*,
                                    clrBackground*/
                                    );
                        dc.SetBkColor( clrTreeBkColor );
                        dc.SetTextColor( clrText );
            }
            dc.SetBkMode( nOldBkMode );
            dc.SetTextColor( clrTextOld );
            dc.SetBkColor( clrBackgroundOld );
            dc.SelectObject( pOldFont );
}

This method provides the tree control with the themed dialog background.
Second, you should provide all the tree items with the white text color in the normal non-selected state. The CExtTreeCtrl::TREEITEMINFO_t::m_clrTextNormal property of each tree item should be set to the RGB(255,255,255) value. I.e. you should adjust this text color after inserting each tree item.