YOU CAN CODE!

 

With The Case Of UCanCode.net  Release The Power OF  Visual C++ !   HomeProducts | PurchaseSupport | Downloads  
Download Evaluation
Pricing & Purchase?
E-XD++Visual C++/ MFC Products
Overview
Features Tour 
Electronic Form Solution
Visualization & HMI Solution
Power system HMI Solution
CAD Drawing and Printing Solution

Bar code labeling Solution
Workflow Solution

Coal industry HMI Solution
Instrumentation Gauge Solution

Report Printing Solution
Graphical modeling Solution
GIS mapping solution

Visio graphics solution
Industrial control SCADA &HMI Solution
BPM business process Solution

Industrial monitoring Solution
Flowchart and diagramming Solution
Organization Diagram Solution

Graphic editor Source Code
UML drawing editor Source Code
Map Diagramming Solution

Architectural Graphic Drawing Solution
Request Evaluation
Purchase
ActiveX COM Products
Overview
Download
Purchase
Technical Support
  General Q & A
Discussion Board
Contact Us

Links

Get Ready to Unleash the Power of UCanCode .NET


UCanCode Software focuses on general application software development. We provide complete solution for developers. No matter you want to develop a simple database workflow application, or an large flow/diagram based system, our product will provide a complete solution for you. Our product had been used by hundreds of top companies around the world!

"100% source code provided! Free you from not daring to use components because of unable to master the key technology of components!"


VC++ Tool: Tree Controls Methods
 

 
 

After adding or creating a tree control, you may want to fill it with the necessary items. Each node of the control is an HTREEITEM object. To create a new node, call the CTreeCtrl::InsertItem() method. It comes in various versions. One of them is:

HTREEITEM InsertItem(LPCTSTR lpszItem,
                                    HTREEITEM hParent = TVI_ROOT,
                                    HTREEITEM hInsertAfter = TVI_LAST );

The easiest way to add an item consists of calling the InsertItem() method with a null-terminated string as argument because this is the only required argument of this version. Here is an example:

BOOL CTree1Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	TreeSoft->Create(WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP,
		CRect(10, 10, 240, 280), this, 0x1221);

	TreeSoft->InsertItem("Office Production");

	return TRUE;  // return TRUE  unless you set the focus to a control
}

In this case, the item would appear as the root. You can add as many nodes like that and each would appear as a root:

BOOL CTree1Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	TreeSoft->Create(WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP,
		CRect(10, 10, 240, 280), this, 0x1221);

	TreeSoft->InsertItem("Office Production");
	TreeSoft->InsertItem("Company Management");
	TreeSoft->InsertItem("Software Development");
	TreeSoft->InsertItem("Human Interaction");

	return TRUE;  // return TRUE  unless you set the focus to a control
}

A Tree List With All Items As

When calling this version of the InsertItem() method, if you do not pass the second argument, the node is created as root. This is because the root item has an HTREEITEM value of TVI_ROOT, which is passed as default. You can also pass the second argument as NULL, which would produce the same effect.

The InsertItem() method returns an HTREEITEM value. You can use this value as a parent to a leaf item. This is done by passing it as the second argument when creating a leaf. Here is an example:

BOOL CTree1Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	TreeSoft->Create(WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP |
		             TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT |
			 TVS_SINGLEEXPAND | TVS_SHOWSELALWAYS |  
			 TVS_TRACKSELECT,
		             CRect(10, 10, 200, 240), this, 0x1221);
	
	HTREEITEM hTree, hCompany;

	hTree = TreeSoft->InsertItem("Software Production", TVI_ROOT);
	
	hCompany = TreeSoft->InsertItem("Microsoft", hTree);
	TreeSoft->InsertItem("Office", hCompany);
	TreeSoft->InsertItem("Visual Studio", hCompany);
	TreeSoft->InsertItem("Servers", hCompany);
	
	hCompany = TreeSoft->InsertItem("Jasc", hTree);
	TreeSoft->InsertItem("Paint Shop Pro", hCompany);
	TreeSoft->InsertItem("Animation Shop", hCompany);
	
	hCompany = TreeSoft->InsertItem("Lotus", hTree);
	TreeSoft->InsertItem("Notes", hCompany);
	TreeSoft->InsertItem("Smart Office", hCompany);

	hCompany = TreeSoft->InsertItem("Macromedia", hTree);
	TreeSoft->InsertItem("Flash", hCompany);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

When using the InsertItem() method as we have done so far, the items are added in the order of their appearance. Besides creating new nodes, the InsertItem() method also allows you to control the order in which to insert the new item. The new leaf can be added as the first or the last child of a node. To do this, pass a third argument to this version of the InsertItem() method and give it the TVI_FIRST to be the first child or TVI_LAST to be the last child of the current parent node. Here is an example:

BOOL CTree1Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	TreeSoft->Create(WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP |
		             TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT |
			 TVS_SINGLEEXPAND | TVS_SHOWSELALWAYS |  
			 TVS_TRACKSELECT,
		             CRect(10, 10, 200, 240), this, 0x1221);
	
	HTREEITEM hTree, hCompany;

	hTree = TreeSoft->InsertItem("Software Production", TVI_ROOT);
	
	hCompany = TreeSoft->InsertItem("Microsoft", hTree);
	TreeSoft->InsertItem("Office", hCompany);
	TreeSoft->InsertItem("Graphics Manipulation", hCompany, TVI_LAST);
	TreeSoft->InsertItem("Project Management", hCompany);
	TreeSoft->InsertItem("Software Develoment", hCompany);
	TreeSoft->InsertItem("Operating Systems", hCompany, TVI_FIRST);
	TreeSoft->InsertItem("Software Documentation", hCompany);

	hCompany = TreeSoft->InsertItem("Jasc", hTree);
	TreeSoft->InsertItem("Paint Shop Pro", hCompany);
	TreeSoft->InsertItem("Animation Shop", hCompany);
	
	hCompany = TreeSoft->InsertItem("Lotus", hTree);
	TreeSoft->InsertItem("Notes", hCompany);
	TreeSoft->InsertItem("Smart Office", hCompany);
	
	hCompany = TreeSoft->InsertItem("Macromedia", hTree);
	TreeSoft->InsertItem("Flash", hCompany);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

 

 

Copyright ?1998-2025 UCanCode.Net Software , all rights reserved.
Other product and company names herein may be the trademarks of their respective owners.

Please direct your questions or comments to webmaster@ucancode.net