When we are typing in Visual Studio, there is an auto-completion list for us to complete the parameter information 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 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
class CXMLTreeCtrl : public CTreeCtrl
BOOL CreateTree(CRect rect,CWnd *parent,UINT image=0);
void ShowMe(CPoint &pt,int show=SW_SHOW);
void SetImages(UINT resource);
BOOL loadXML(const CString &strPathName,
const BOOL bOptimizeMemory );
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);
afx_msg void OnItemexpanding(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnDblclk(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
How to Use It?
Using this code is very simple. First, declare a member variable as
Secondly, override the
WM_LBUTTONUP or some other stimulus to display the tree control using
void CVs_treectrlView::OnLButtonUp(UINT nFlags, CPoint point)
Finally, deal the message
WM_FLOAT_CTRL to do what you have selected from tree control.
LRESULT CVs_treectrlView::OnFloatCtrl(WPARAM wParam, LPARAM lParam)
CString str = (BSTR)wParam;
That's all! Enjoy it.
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.
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 :firstname.lastname@example.org Software Engineering and CAD is my mainly research program.
You also can reach me on msn: email@example.com