LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
RECT rc;
GetWindowRect(&rc);
rc.right -= rc.left;
rc.bottom -= rc.top;
rc.top = rc.left = 0;
InitCommonControls();
// {
m_ctlSysTreeView32.Create(m_hWnd, rc,
NULL,
WS_VISIBLE | WS_CHILD | TVS_LINESATROOT | TVS_HASLINES | TVS_EDITLABELS |
TVS_HASBUTTONS | TVS_FULLROWSELECT | TVS_SHOWSELALWAYS, WS_EX_CLIENTEDGE/* , IDC_TREE */);
// m_ctlSysTreeView32.Create(m_hWnd, rc);
_ASSERTE(m_ctlSysTreeView32.m_hWnd != NULL);
m_hImageList = ImageList_LoadBitmap(_Module.GetModuleInstance(),
MAKEINTRESOURCE(IDB_IMAGELIST), 18, 3, OleTranslateColor(m_oleFourColor, NULL, &m_clrFourColor));
_ASSERTE(m_hImageList != NULL);
PopulateTreeCtrlEx();
m_ctlSysTreeView32.SetFocus();
// }
return 0;
}
void PopulateTreeCtrlEx()
{
TV_INSERTSTRUCT TreeCtrlItem;
HTREEITEM hChildItem;
HTREEITEM hRoot;
TreeCtrlItem.hParent = TVI_ROOT;
TreeCtrlItem.hInsertAfter = TVI_LAST;
TreeCtrlItem.item.mask = TVIF_TEXT | TVIF_IMAGE |TVIF_PARAM | TVIF_SELECTEDIMAGE;
TreeCtrlItem.item.pszText = "...";
TreeCtrlItem.item.iImage = 0;
TreeCtrlItem.item.iSelectedImage = 1;
TreeCtrlItem.item.lParam = NULL;
// hRoot = reinterpret_cast<HTREEITEM>(m_ctlSysTreeView32.SendMessage(TVM_INSERTITEM ,
// 0, reinterpret_cast<LPARAM>(&TreeCtrlItem)));
hRoot = (HTREEITEM)(m_ctlSysTreeView32.SendMessage(TVM_INSERTITEM ,
0, (LPARAM)(LPTVINSERTSTRUCT)(&TreeCtrlItem)));
TreeCtrlItem.hParent = hRoot;
TreeCtrlItem.hInsertAfter = TVI_LAST;
TreeCtrlItem.item.mask = TVIF_TEXT | TVIF_IMAGE |TVIF_PARAM | TVIF_SELECTEDIMAGE;
TreeCtrlItem.item.pszText = "...";
TreeCtrlItem.item.iImage = 0;
TreeCtrlItem.item.iSelectedImage = 1;
TreeCtrlItem.item.lParam = NULL;
hChildItem = reinterpret_cast<HTREEITEM>(m_ctlSysTreeView32.SendMessage(TVM_INSERTITEM,
0, reinterpret_cast<LPARAM>(&TreeCtrlItem)));
TreeCtrlItem.hParent = hChildItem;
TreeCtrlItem.hInsertAfter = TVI_LAST;
TreeCtrlItem.item.mask = TVIF_TEXT | TVIF_IMAGE |TVIF_PARAM | TVIF_SELECTEDIMAGE;
TreeCtrlItem.item.pszText = "...";
TreeCtrlItem.item.iImage = 0;
TreeCtrlItem.item.iSelectedImage = 1;
TreeCtrlItem.item.lParam = NULL;
m_ctlSysTreeView32.SendMessage(TVM_INSERTITEM,
0, reinterpret_cast<LPARAM>(&TreeCtrlItem));
...
TreeCtrlItem.hParent = hRoot;
TreeCtrlItem.hInsertAfter = TVI_LAST;
TreeCtrlItem.item.mask = TVIF_TEXT | TVIF_IMAGE |TVIF_PARAM | TVIF_SELECTEDIMAGE;
TreeCtrlItem.item.pszText = "...";
TreeCtrlItem.item.iImage = 0;
TreeCtrlItem.item.iSelectedImage = 1;
TreeCtrlItem.item.lParam = NULL;
hChildItem = reinterpret_cast<HTREEITEM>(m_ctlSysTreeView32.SendMessage(TVM_INSERTITEM,
0, reinterpret_cast<LPARAM>(&TreeCtrlItem)));
TreeCtrlItem.hParent = TVI_ROOT;
TreeCtrlItem.hInsertAfter = TVI_LAST;
TreeCtrlItem.item.mask = TVIF_TEXT | TVIF_IMAGE |TVIF_PARAM | TVIF_SELECTEDIMAGE;
TreeCtrlItem.item.pszText = "...";
TreeCtrlItem.item.iImage = 0;
TreeCtrlItem.item.iSelectedImage = 1;
TreeCtrlItem.item.lParam = NULL;
hRoot = reinterpret_cast<HTREEITEM>(m_ctlSysTreeView32.SendMessage(TVM_INSERTITEM ,
0, reinterpret_cast<LPARAM>(&TreeCtrlItem)));
...
}
LRESULT OnNew(WORD wNotifyCode, WORD wID, HWND hWndCtlr, BOOL& bHandled)
{
HTREEITEM hSel = TreeView_GetSelection(m_ctlSysTreeView32.m_hWnd);
if(hSel)
{
...
hSel = InsertItem(this->m_ctlSysTreeView32.m_hWnd, "...", 0, 1, MAKELPARAM(3, 0), hSel);
TreeView_Expand(this->m_ctlSysTreeView32.m_hWnd, hSel, TVE_EXPAND);
TreeView_SelectItem(this->m_ctlSysTreeView32.m_hWnd, hSel);
m_ctlSysTreeView32.SetFocus();
}
return 0;
}
LRESULT OnDelete(WORD wNotifyCode, WORD wID, HWND hWndCtlr, BOOL& bHandled)
{
HTREEITEM hSel = TreeView_GetSelection(m_ctlSysTreeView32.m_hWnd);
if(hSel)
{
TreeView_DeleteItem(m_ctlSysTreeView32.m_hWnd, hSel);
}
return 0;
}
LRESULT OnRename(WORD wNotifyCode, WORD wID, HWND hWndCtlr, BOOL& bHandled)
{
HTREEITEM hSel = TreeView_GetSelection(m_ctlSysTreeView32.m_hWnd);
TreeView_EditLabel(this->m_ctlSysTreeView32.m_hWnd, hSel);
return 0;
}
참조 사이트: