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



Comments

  • How to change 16-color Icons into truecolor

    Posted by Legacy on 04/27/2003 12:00am

    Originally posted by: Jack

    How to change 16-color Icons into truecolor?
    use SetImageList only allow to use 16-color bitmap.

    Reply
  • How to place two sidepanes in the same column?

    Posted by Legacy on 09/18/2002 12:00am

    Originally posted by: Min Tang

    It is very good and the the very thing I was looking for, but I still have problem on it needing help.
    That is, I want to place the second sidepane to the bottom of the first one, but I found I can't. The second sidepane is always on the left side of the first one. How to solve this problem? Thank you very much!

    Reply
  • Changes for debug version

    Posted by Legacy on 09/04/2002 12:00am

    Originally posted by: eflame

    // sizecbar.h
    class CSizingControlBar : public CControlBar
    {...
    virtual BOOL Create(CWnd* pParentWnd,sizeDefault, UINT nID, DWORD dwStyle = CBRS_TOP);
    ...
    }

    // sizecbar.cpp
    BOOL CSizingControlBar::Create(CWnd* pParentWnd, CSize sizeDefault, UINT nID, DWORD dwStyle)
    {
    ...
    dwStyle |= CCS_NOMOVEY|CCS_NODIVIDER|CCS_NORESIZE|WS_CHILD|WS_VISIBLE;
    ...
    }


    Reply
  • Error

    Posted by Legacy on 08/28/2002 12:00am

    Originally posted by: hongky

    !!!!Memery Error!!!!

    Reply
  • 干得不错,伙计~~~

    Posted by Legacy on 03/10/2002 12:00am

    Originally posted by: 麟麟

    辛苦辛苦,值得表扬。
    
    建议中国人在此就说中国话吧,呵呵,
    发扬国语。
    也可以加英文注释。

    Reply
  • Windows2000 is not play..

    Posted by Legacy on 10/12/2001 12:00am

    Originally posted by: Chung daewon

    how >??

    Reply
  • Release Build Error

    Posted by Legacy on 03/29/2001 12:00am

    Originally posted by: Bryan

    This code does not work in Release mode. After building the .exe in Release, if you click on the DragCaption ("Tree Menu"), the program bombs with this error:

    "The instruction at "..." referenced memory at "...". The memory could not be "read"."

    I suggest reverting back to Cristi Posea's original code (found here at CodeGuru) and modifying it yourself to suit your app.

    Reply
  • Help Me

    Posted by Legacy on 09/20/1999 12:00am

    Originally posted by: Rajabhakshi

    I compiled this demo successfully in VC6.0 by commenting SetBorder() and GetBorder() functions. While executing it gave me assertion failure.

    Help me as soon as possible

    Reply
  • fix the bug

    Posted by Legacy on 08/19/1999 12:00am

    Originally posted by: Danny Wang

    on implementation of CSizingControlBar::Create()
    
    modify the dwstyle assignation,
    replace
    /* dwStyle &= ~CBRS_ALL;
    dwStyle |= CCS_NOMOVEY|CCS_NODIVIDER|CCS_NORESIZE;
    */
    by
    SetBarStyle(dwStyle & CBRS_ALL);

    this avoid the assert error of CControlBar::AssertValid() ;

    Reply
  • How to compile successfully.

    Posted by Legacy on 08/17/1999 12:00am

    Originally posted by: angler


    Disable all line error occured. and compile in release mode in VC 6:

    1)CoolTreeCtrl.h
    /* int SetBorder(DWORD dwFlags, int xBorder, int yBorder)
    { ASSERT(::IsWindow(m_hWnd));
    return (int)SendMessage(TVM_SETBORDER, (WPARAM)dwFlags, (LPARAM)MAKELPARAM(xBorder, yBorder)); }

    int GetBorder()
    { ASSERT(::IsWindow(m_hWnd));
    return (int)SendMessage(TVM_GETBORDER, (WPARAM)0, (LPARAM)0); }
    */

    2)Sidepane.cpp
    // m_pControl->GetTreeMenuCtrl()->SetBorder(TVSBF_XBORDER|TVSBF_YBORDER, 2, 0);

    3)TreeMenuDemo.cpp
    // m_TreeMenu.m_tree.SetBorder(TVSBF_XBORDER|TVSBF_YBORDER, 2, 0);

    4)sidepane.h
    //#include "flatbmpbtn.h"

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As your content grows, it can be challenging to define the proper rules, regulations and policies that govern that content and ensure proper protection and compliance. Entrusting your content to Box – the only secure, modern content platform in the cloud – is the right first step. The next step is to evaluate your retention, disposition and defensible discovery needs and to establish the proper buy-in to satisfy all your needs. In this Information Governance webinar, learn how Box Governance can add …

  • On-demand Event You can scale your mobile apps' data throughput and storage elastically with a fully managed, planet-scale NoSQL database service built for fast and predictable performance, high availability, elastic scaling, global distribution, and ease of development. This 40-minute on-demand webinar will demonstrate the scalability of DocumentDB and explore how the MongoDB API for DocumentDB, along with Xamarin, can simplify mobile application development for your organization. About Azure …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date