Click here to Skip to main content
15,895,142 members
Articles / Desktop Programming / MFC

CStaticTreeCtrl - A CStatic derived custom Tree control

Rate me:
Please Sign up or sign in to vote.
4.95/5 (82 votes)
1 May 200617 min read 328.1K   13.3K   169  
Step-by-step creation of a custom Tree control from a CStatic control, implementing basic functionality, eye-candy (font, bitmap background, etc.), scrolling (bars and wheel), multiline (wrapping) text, and audio context menu.
// ContextMenu.h: interface for the CContextMenu class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_CONTEXTMENU_H__910CF638_44A0_4741_8E1A_A0F9C964D199__INCLUDED_)
#define AFX_CONTEXTMENU_H__910CF638_44A0_4741_8E1A_A0F9C964D199__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
//
/////////////////////////////////////////////////////////////////////////////

#if defined( _UNICODE )
	#define STRCPY(x,y)				wcscpy(x,y)
	#define	ODDCHAR					USHORT
#else
	#define STRCPY(x,y)				strcpy(x,y)
	#define	ODDCHAR					TCHAR
#endif

/////////////////////////////////////////////////////////////////////////////
class CContextMenu : public CMenu  
{
public:
	CContextMenu();
	virtual ~CContextMenu();

public:
	virtual CContextMenu&	AppendMenuItem	( UINT nFlags, UINT nID, CString csText, CString csWavFile, CDC* pDC );
	virtual CContextMenu&	SetTextFont		( CFont* font );
	virtual CContextMenu&	ToggleSound		( BOOL bSoundOn );
	virtual CContextMenu&	SetColors		(	COLORREF crText, COLORREF crBackground, COLORREF crDisabled,
												COLORREF crSelected, COLORREF crBorder );

protected:
	virtual void			MeasureItem		( LPMEASUREITEMSTRUCT lpMIS );
	virtual void			DrawItem		( LPDRAWITEMSTRUCT lpDIS );

protected:
	class CContextMenuItem
	{
	public:
		CContextMenuItem( CString csText, CString csWavFile )
		{
			m_csText	= csText;
			m_csWavFile	= csWavFile;
		}

		~CContextMenuItem()
		{
			m_csText.Empty();
			m_csWavFile.Empty();
		}

		CString m_csText;
		CString m_csWavFile;
	};

	CPtrArray		m_cptrMenuItems;
	
	CFont*			m_pFont;

	int				m_iWidth;
	int				m_iHeight;

	BOOL			m_bSoundOn;
	
	COLORREF		m_crText, m_crBackground, m_crDisabled, m_crSelected, m_crBorder;
};

#endif // !defined(AFX_CONTEXTMENU_H__910CF638_44A0_4741_8E1A_A0F9C964D199__INCLUDED_)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Japan Japan
Louis Armstrong, Count Basie, Chick Corea, Miles Davis, Benny Goodman, Spyro Gyra, Dizzy Gillespie, Keith Jarrett, Leroy Jenkins, Yusef Lateef, Al Di Meola, Glenn Miller, McCoy Tyner, Cecil Taylor, John Coltrane, Duke Ellington, Bill Evans, Ella Fitzgerald, Jean-Luc Ponty, John McLaughlin, Fats Navarro, Tito Puente, Paul Whiteman, Sun Ra, Caravan, Joe Farrell, Paco de Lucia, Weather Report, Charles Mingus, Pat Metheny, Charlie Parker, Charlie Byrd, Mahavishnu Orchestra, Wynton Marsalis, Return to Forever, Julien Loureau, Thelonious Monk, Max Roach , Pharaoh Sanders, Albert Ayler, Ornette Coleman, Sidney Bechet,...

Comments and Discussions