ctreectrl study SetItemImage Notify

SetItemImage

1
2
3
4
BOOL (
HTREEITEM hItem,
int nImage,
int nSelectedImage);

Notify

NM_CLICK

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
ON_NOTIFY(NM_CLICK, 4, &CFolderView::OnNMClickTree)

void OnNMClickTree(NMHDR *pNMHDR, LRESULT *pResult);

void CFolderView::OnNMClickTree(NMHDR *pNMHDR, LRESULT *pResult)
{
g_pwndMain->m_spWndFileList->ActivateFrame();
*pResult = 0;
}

typedef struct tagNMHDR
{
HWND hwndFrom;
UINT_PTR idFrom;
UINT code;
} NMHDR;

TVN_SELCHANGING

1
2
3
4
5
6
7
8
9
10
ON_NOTIFY(TVN_SELCHANGING, 4, &CFolderView::OnTvnSelchangingFolder)

afx_msg void OnTvnSelchangingFolder(NMHDR *pNMHDR, LRESULT *pResult);

void CFolderView::OnTvnSelchangingFolder(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);

*pResult = 0;
}

TVN_SELCHANGED

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
ON_NOTIFY(TVN_SELCHANGED, 4, &CFolderView::OnTvnSelchangedFolder)

void OnTvnSelchangedFolder(NMHDR *pNMHDR, LRESULT *pResult);

void CFolderView::OnTvnSelchangedFolder(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
HTREEITEM hItem = pNMTreeView->itemNew.hItem;
if (hItem == 0)
{
return;
}
if (hItem != m_curDbRootItem)
{
m_wndTree.SetItemImage(hItem, 1, 1);
}
if (pNMTreeView->itemOld.hItem != m_curDbRootItem)
{
m_wndTree.SetItemImage(pNMTreeView->itemOld.hItem, 2, 2);
}
m_wndTree.Expand(pNMTreeView->itemNew.hItem, TVE_EXPAND);

*pResult = 0;
}