[vc]-[mfc]CTreeCtrl中通过单击获取当前选项文本

NM_CLICK事件

void C?Dlg::OnNMClickTreeGroup(NMHDR *pNMHDR, LRESULT *pResult)
{
	// TODO: 在此添加控件通知处理程序代码
	//得到单击选中的项的文本值
	DWORD   dwpos = GetMessagePos();   
	TVHITTESTINFO ht = {0};   

	ht.pt.x = GET_X_LPARAM(dwpos);
	ht.pt.y = GET_Y_LPARAM(dwpos);
	::MapWindowPoints(HWND_DESKTOP,pNMHDR->hwndFrom,&ht.pt,1); //把屏幕坐标转换成控件坐标
	TreeView_HitTest(pNMHDR->hwndFrom,&ht);   //确定点击的是哪一项
	CString strText;
	strText = m_CtrlTree.GetItemText(ht.hItem);
	MessageBox(strText);
	*pResult = 0;
}

    #ServerAdmin 419844484@qq.com
    DocumentRoot /var/www/shoutui
	ServerName www.shoutuiba.net
	ServerAlias shoutuiba.net
    CustomLog logs/shoutuiba.net.log combined

Leave a Reply