如何在mfc中检测ctree控件中的mousedown事件 [英] How to detect mousedown event in ctree control in mfc

查看:75
本文介绍了如何在mfc中检测ctree控件中的mousedown事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的对话框上有一个树形控件我要显示已选中的项目

看到我们可以选择多个复选框我要显示上一个选中的项目



我尝试过:



I have one tree control on my dialog i want to show the checked item
see we can select multiple checkboxes i want to show last checked item

What I have tried:

void CTreeSetControlDlg::OnNMClickTreereletion(NMHDR *pNMHDR, LRESULT *pResult)
{
	// TODO: Add your control notification handler code here
	// Select the item that is at the point myPoint.
	static int i=0;
	CString m;
	HTREEITEM hItem=NULL;
	if(WM_LBUTTONDOWN)
	{
		hItem=m_treeRel.GetSelectedItem();
		m=m_treeRel.GetItemText(hItem);
		//m.Format(_T("Captured...%d"),i);
		ShowMessage(m);
		i++;
	}

	*pResult = 0;
}

推荐答案

您正在处理 NM_CLICK 通知单击树控件中的左按钮时发送。因此无需检查左键是否已关闭。



但是当您的代码处理此消息时,尚未调用默认处理,以便点击的商品尚未被选中。



要获得点击的商品,您可以使用类似的商品

You are handling the NM_CLICK notification which is send when clicking the left button within the tree control. So there is no need to check if the left button is down.

But when this message is handled by your code, the default handling has not yet been called so that the clicked item is not yet selected.

To get the clicked item you can use something like
UINT uFlags = 0;
CPoint pt(0, 0);
GetCursorPos(&pt);
m_treeRel.ScreenToClient(&pt);
HTREEITEM hItem = m_treeRel.HitTest(pt, &uFlags);
if(NULL != hItem && (TVHT_ONITEM  & uFlags))
{
    // Do something with clicked item
}



目前还不是很清楚你最终想要实现的目标。但是,通常会有多个通知和消息可用于特定任务。所以你也应该看看这些。候选人可能是 TVN_SELCHANGING通知代码(Windows) [ ^ ]。


这篇关于如何在mfc中检测ctree控件中的mousedown事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆