创建TreeView控件,响应NM_CLICK消息得到当前点击的节点的信息(SDK版本)

 
// 创建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;

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值