Click here to Skip to main content
15,886,541 members
Articles / Desktop Programming / MFC

A Float Tree Control like the Parameter List Control in Visual Studio

Rate me:
Please Sign up or sign in to vote.
3.44/5 (6 votes)
9 Apr 20021 min read 135.1K   2.6K   25  
In Visual Studio, you will find an auto-completion list when you type your code in the IDE. This is a similar control but using a tree.
#if !defined(AFX_XMLTREECTRL_H__9C37AE6A_3FF2_4105_8938_A3984DE1AE9E__INCLUDED_)
#define AFX_XMLTREECTRL_H__9C37AE6A_3FF2_4105_8938_A3984DE1AE9E__INCLUDED_
//***********************************************
/* Author : Johnson Zhou(ZhouQiang)
/* Purpose: header file for a floating tree control like
/*			list parameter infomation list .
/*I borrowed code of XML tree from Frank Le from www.codeproject.com
/*Copyright by Johnson Zhou(ZhouQiang) (c) 2002
//***********************************************/
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// XMLTreeCtrl.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CXMLTreeCtrl window
// Image indexes.
const int ILI_ROOT = 0;
const int ILI_ELEMENT = 1;
const int ILI_TEXT = 2;
const int ILI_OTHER = 3;
const int ILI_ATTRIBUTE = 4;
const int ILI_COMMENT = 5;
#import "msxml.dll" named_guids

#define WM_FLOAT_CTRL WM_USER+2002

class CXMLTreeCtrl : public CTreeCtrl
{
// Construction
public:
	CXMLTreeCtrl();

// Attributes
public:

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CXMLTreeCtrl)
	public:
	protected:
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	//}}AFX_VIRTUAL

// Implementation
public:
	BOOL CreateTree(CRect rect,CWnd *parent,UINT image=0);
	void ShowMe(CPoint &pt,int show=SW_SHOW);
	void SetImages(UINT resource);
	virtual ~CXMLTreeCtrl();
	BOOL loadXML(const CString &strPathName, const BOOL bOptimizeMemory /*= FALSE*/);
protected:
    BOOL populateNode(MSXML::IXMLDOMElement* node, const HTREEITEM& hItem);
	BOOL populateAttributes(MSXML::IXMLDOMElement *node, const HTREEITEM &hParent);
    HTREEITEM insertItem(MSXML::IXMLDOMElement* node, 
        const CString &nodeName, int nImage, int nSelectedImage, 
        HTREEITEM hParent = TVI_ROOT, HTREEITEM hInsertAfter = TVI_LAST);
    void deleteFirstChild(const HTREEITEM& hItem);
	void deleteAllChildren(const HTREEITEM& hItem);
	int getIconIndex(MSXML::IXMLDOMElement* node);
	CImageList m_theImageList;
	BOOL m_bOptimizeMemory;
	// Generated message map functions
protected:
	//{{AFX_MSG(CXMLTreeCtrl)
	afx_msg void OnItemexpanding(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnDblclk(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_XMLTREECTRL_H__9C37AE6A_3FF2_4105_8938_A3984DE1AE9E__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.


Written By
Software Developer (Senior)
China China
I'm write program from 1990. My research field is CAG,CAD and Image processing. I select C/C++, ASP, Java, XML as my usaully developing tools. Occasional , write code in Delphi and VB. I'm using Visual C++ from 1996. If you have anything unclear, e-mail to :zhou_cn123@sina.com Software Engineering and CAD is my mainly research program.

You also can reach me on msn: zhoujohnson@hotmail.com

Comments and Discussions