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!"


Visual Studio example and Visual Studio Tutorial and mfc tree control

 
 

Sample Image - FloatTreeControl.gif

Introduction

When we are typing in Visual Studio, there is a auto-completion list for us to complete the parameter infomation for the function we typed or function names for a class. I encountered a requirement that the user should be able to select some words from a tree control to complete the current place in the an editor. So I created this control.

How Does It Work?

The control is publicly derived from CTreeCtrl. You can create it using CreateTree with the size, parent window and optional bitmap icons. When you need to display the control, simply use the member function ShowMe with default parameters. When you double-click on a tree item, the window of the tree control will be closed and it will send a message to the parent window with selected string.

Prototypes

Collapse Copy Code
class CXMLTreeCtrl : public CTreeCtrl
{
public:
    //Create a new tree 
    // rect: size of tree control will be displayed.
    // parent: the parente windows
    // image: resource code for an image as icons will be displayed in the 
    //        tree control
    BOOL CreateTree(CRect rect,CWnd *parent,UINT image=0);
    
    // Display the tree control, auto wrapped will encouter the edge of 
    // parent window
    // pt: The top-left point of window,may be changed when edge of parent 
    // window encouterd
    // show: SW_SHOW for show current tree, SW_HIDE to hide the control
    void ShowMe(CPoint &pt,int show=SW_SHOW);
    
    // Set the image resource as a serial of icons in the control
    // resource , the image resource.
    void SetImages(UINT resource);
    
    // To load XML as the tree item to initialize the tree control
    // strPathName: the file name save the data of tree in XML format
    // bOptimizeMemory: How to draw the tree's item.
    BOOL loadXML(const CString &strPathName, 
                 const BOOL bOptimizeMemory /*= FALSE*/);

    // The following code is borrowed from Frank Le for XML tree 
    // contruction
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);
    // User select a item , close the control and return what he/she selected.
    afx_msg void OnDblclk(NMHDR* pNMHDR, LRESULT* pResult);
    // If user point out the control when it is shown, close it
    afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
    //}}AFX_MSG

How to use it?

Using this code is very simple. First, declare a member variable as CXMLTreeCtrl and Create it.

Collapse Copy Code
void CVs_treectrlView::OnInitialUpdate() 
{
    CView::OnInitialUpdate();
    CRect rect(0,0,200,300);
    m_Tree.CreateTree (rect,this,IDB_BITMAP_TREE_ICONS);
    m_Tree.loadXML("catalog.xml",TRUE);
}

Secondly, override the WM_LBUTTONUP or some other stimulus to display the tree control using ShowMe function.

Collapse Copy Code
void CVs_treectrlView::OnLButtonUp(UINT nFlags, CPoint point) 
{
    m_Tree.ShowMe (point);
    CView::OnLButtonUp(nFlags, point);
}

Finally, deal the message WM_FLOAT_CTRL to do what you have selected from tree control.
 

Collapse Copy Code
LRESULT CVs_treectrlView::OnFloatCtrl(WPARAM wParam, LPARAM lParam)
{
    CString str = (BSTR)wParam;
    MessageBox(str);
    m_Tree.ShowWindow (SW_HIDE);
    return 0;
}
That's all! Enjoy it.

 

 

 

 

Copyright ?1998-2009 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