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

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Aug 6, 1998
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.