A Control like IE 4's Favorites/History/Channels View

Everyone knows the new menu-like left pane view's in IE4. But did you know that this is only a extended TreeView? You can do this by using CUSTONDRAW notification in the new from CTreeCtrl derived class. I called it CTreeMenu. To do this is quite easy. See an code extract below.
But note: This works only with the extended TreeCtrl that comes with IE4. You can use my wrapper class or the one from Luis Barreira IE4 Classes. This should also work, but I didn't test it. Also on Codeguru's Webpage.

I wrote a class, that makes the handling pretty easy. Included are a Button to close the view and some Bevel stuff to be uptodate with the Windows style. There is also a self RegisterClass() function to use as a CustomControl on Dialog Templates.

The Frame use the SizingControlBar from Cristi Posea also found here on Codeguru's Webpage.

See more details in code comments.

void CTreeMenu::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult) 
{

	NMTVCUSTOMDRAW *pTVCD = (NMTVCUSTOMDRAW*)pNMHDR;
	
	CDC* pDC = CDC::FromHandle(pTVCD->nmcd.hdc);

	// The rect for the cell gives correct left and right values
	CRect rect = pTVCD->nmcd.rc;
	
	// By default set the return value to do the default behavior
	*pResult = 0;

	
	switch( pTVCD->nmcd.dwDrawStage )
		{
		// First stage (for the whole control
		case  CDDS_PREPAINT: 
			{		
				*pResult = CDRF_NOTIFYITEMDRAW;
			}
			break;

		// Stage three (called for each subitem of the focused item
		case CDDS_ITEMPREPAINT | CDDS_SUBITEM: 
			{
				*pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NOTIFYPOSTPAINT;
			}
			break;

		// Stage four (called for each subitem of the focused item
		case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM: 
			{
				*pResult = CDRF_SKIPDEFAULT;	
			}
			break;
		
		default: 
			// Stage two handled here. (called for each item
			if (pTVCD->nmcd.uItemState & CDIS_HOT)
			{
				pDC->Draw3dRect( &rect, m_clr3DHilight, m_clr3DShadow );
				pDC->SetBkColor(GetBkColor());
				pDC->SetTextColor(RGB(0,0,255));
	
				// Tell the control that to draw it again
				*pResult = CDRF_NOTIFYPOSTPAINT;

			}

			if (pTVCD->nmcd.uItemState & CDIS_SELECTED)
			{
				*pResult = CDRF_SKIPDEFAULT;
			}

			if( (pTVCD->nmcd.uItemState & CDIS_FOCUS) )
			{
				pDC->Draw3dRect( &rect, m_clr3DShadow, m_clr3DHilight );
				pDC->SetBkColor(m_clrSelBkColor);
				pDC->SetTextColor(m_clrSelTextColor);
	
				*pResult = CDRF_NOTIFYPOSTPAINT;
			}	
			
			if( (pTVCD->nmcd.uItemState & CDIS_CHECKED) )
			{
				*pResult = CDRF_DODEFAULT;
			}	
			
			break;
		}
}

Download demo - 70KB

P.S: Did everyone has successfull experienced with the new pager control (see latest "commctrl.h"), please send a notice to Rainer Pfitzner

Date Posted: 05/13/98