// TreeView
case WM_CREATE:
{
INITCOMMONCONTROLSEX icc = {sizeof(icc), ICC_TREEVIEW_CLASSES};
if(InitCommonControlsEx(&icc))
{
HWND hTreeView = CreateWindow
(
_T("SysTreeView32"),
_T("TreeView"),
WS_CHILD | WS_VISIBLE | WS_BORDER | TVS_FULLROWSELECT | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT,
0, 0, 100, 100,
hWnd,
(HMENU)0x11,
hInst,
NULL
);
TVINSERTSTRUCT ti = {0};
TCHAR szText[MAX_COUNT] = {0};
ti.item.mask = TVIF_TEXT;
ti.item.cchTextMax = MAX_COUNT;
ti.item.pszText = szText;
_stprintf(szText, _T("%s"), _T("AAA"));
TreeView_InsertItem(hTreeView, &ti);
_stprintf(szText, _T("%s"), _T("BBB"));
TreeView_InsertItem(hTreeView, &ti);
_stprintf(szText, _T("%s"), _T("CCC"));
TreeView_InsertItem(hTreeView, &ti);
}
}
break;
// NM_CLICK WM_NOTIFY
case WM_NOTIFY:
{
LPNMHDR lpnmh = (LPNMHDR)lParam;
if(NM_CLICK == lpnmh->code)
{
DWORD dwPos = GetMessagePos();
POINT pt;
pt.x = LOWORD(dwPos);
pt.y = HIWORD(dwPos);
ScreenToClient(lpnmh->hwndFrom, &pt);
TVHITTESTINFO ht = {0};
ht.pt = pt;
ht.flags = TVHT_ONITEM;
HTREEITEM hItem = TreeView_HitTest(lpnmh->hwndFrom, &ht);
TVITEM ti = {0};
ti.mask = TVIF_HANDLE | TVIF_TEXT;
TCHAR buf[MAX_COUNT] = {0};
ti.cchTextMax = MAX_COUNT;
ti.pszText = buf;
ti.hItem = hItem;
TreeView_GetItem(lpnmh->hwndFrom, &ti);
MessageBox(hWnd, buf, NULL, 0);
}
}
break;