CTreeCtrl은 탐색기의 디렉토리를 보여주는 녀석이다
트리컨트롤에 데이터를 넣는 방법은
InserItem 이라는 함수를 사용하면 되는데,
이 함수를 유심히 살펴보면 HTREEITEM hParen = TVI_ROOT 라는 것이 있다.
// afxcmn.h
// Operations
HTREEITEM InsertItem(LPTVINSERTSTRUCT lpInsertStruct);
HTREEITEM InsertItem(UINT nMask, LPCTSTR lpszItem, int nImage,
int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam,
HTREEITEM hParent, HTREEITEM hInsertAfter);
HTREEITEM InsertItem(LPCTSTR lpszItem, HTREEITEM hParent = TVI_ROOT,
HTREEITEM hInsertAfter = TVI_LAST);
HTREEITEM InsertItem(LPCTSTR lpszItem, int nImage, int nSelectedImage,
HTREEITEM hParent = TVI_ROOT, HTREEITEM hInsertAfter = TVI_LAST);
// commctrl.h
#define TVI_ROOT ((HTREEITEM)0xFFFF0000)
#define TVI_FIRST ((HTREEITEM)0xFFFF0001)
#define TVI_LAST ((HTREEITEM)0xFFFF0002)
#define TVI_SORT ((HTREEITEM)0xFFFF0003)
별 다른 것은 없고, 이번에 추가하는 아이템은 Root 아이템으로 적용을 하라는 것인데,
Root 아이템은 위의 이미지에서 Expanded Node / Leaf 라는 두녀석이다.
아무튼 위와 같이 tree 구조로 넣기위해서는 InserItem 함수의 return 값을 유심히 봐야한다.
HTREEITEM InsertItem(LPCTSTR lpszItem, HTREEITEM hParent = TVI_ROOT, HTREEITEM hInsertAfter = TVI_LAST);
|
InsertItem은 리턴값으로 추가한 녀석의 핸들을 돌려준다.
그리고 입력으로 TVI_ROOT가 들어가거나 혹은 핸들이 들어간다.
위와 같은 구조로 하기 위해서는 아래와 같이 구현하면 된다.
HTREEITEM expand;
HTREEITEM expand_2nd;
HTREEITEM expand_3rd;
expand= InsertItem("Expanded Node", TVI_ROOT, TVI_LAST);
expand_2nd = InsertItem("Expanded Node", expand, TVI_LAST);
InsertItem("Leaf", expand_2nd, TVI_LAST);
InsertItem("Leaf", expand_2nd, TVI_LAST);
expand_3rd = InsertItem("Collapsed Node", expand, TVI_LAST);
InsertItem("Leaf", expand_3rd, TVI_LAST);
InsertItem("Leaf", expand_3rd, TVI_LAST);
InsertItem("Leaf", TVI_ROOT, TVI_LAST);
|
[링크 :
http://msdn.microsoft.com/ko-kr/library/7w95665f%28VS.80%29.aspx] CTreeCtrl Members
[링크 :
http://msdn.microsoft.com/ko-kr/library/cc468290%28VS.71%29.aspx]