CTreeCtrl点击节点左边的按钮或者图标等处理

问题引出:在CTreeCtrl 上点击节点,使用GetItemText 直接获取到了该节点的文本值,在树创建时是TVS_HASBUTTONS的时候,节点左边还会存在  +/-按钮,我想在点击 +/-按                        钮时候只做展开和折叠操作,而不直接去获取节点的内容

解决方案:经过搜索后,发现HitTest可以获取这个位置的状态(工作区),于是直接使用

解决代码:

 UINT ClickLocation;
	 CPoint Point;
	 ::GetCursorPos(&Point);
	 ScreenToClient(&Point);
	 m_tree.HitTest(Point, &ClickLocation);
	 if(TVHT_ONITEMBUTTON&ClickLocation || TVHT_ONITEMINDENT & ClickLocation)//根据获取到的内容判断
	 {
		 return 0;
	 }

MSDN:

<span style="white-space:pre">	</span><pre name="code" class="cpp">HTREEITEM HitTest(
   CPoint pt,
   UINT* pFlags = NULL
) const;
HTREEITEM HitTest(
   TVHITTESTINFO* pHitTestInfo 
) const;

 

<h2 class="LW_CollapsibleArea_TitleDiv" style="font-family: 'Segoe UI Semibold', 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; color: rgb(68, 68, 68); font-size: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-bottom: 5px; padding-top: 20px; font: normal normal 100 1.5em/normal 'Segoe UI Light', 'Segoe UI', Helvetica, Garuda, Arial, sans-serif !important; font-style: normal !important; line-height: normal; "><div style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; "><a target=_blank href="https://msdn.microsoft.com/zh-cn/library/vstudio/x0w7ft34(v=vs.110).aspx" class="LW_CollapsibleArea_TitleAhref" title="折叠" role="button" style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: rgb(0, 188, 242); "><span class="LW_CollapsibleArea_Title" style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; display: block; color: rgb(0, 0, 0); font-size: 22px; ">参数</span></a></div></h2><div class="sectionblock" style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; padding-left: 20px; display: block; padding-bottom: 0px; padding-top: 0px; padding-right: 0px; "><a target=_blank id="parametersToggle" style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; text-decoration: none; color: rgb(19, 130, 206); "></a><dl class="authored" style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; "><dt style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; "><span class="parameter" style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; font-style: italic; ">pt</span></dt><dd style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; "><p style="margin-top: 0px; margin-bottom: 14px; padding-bottom: 15px; font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; color: rgb(102, 102, 102); line-height: 21px; font-size: 14px; "><span id="mt2" class="sentence" data-guid="98a601b0947b33015beebb256c6bff56" data-source="Client coordinates of the point to test." xml:space="preserve" style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; "><sentencetext xmlns="http://www.w3.org/1999/xhtml" style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; ">测试的点工作区坐标。</sentencetext></span></p></dd><dt style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; "><span class="parameter" style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; font-style: italic; ">pFlags</span></dt><dd style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; "><p style="margin-top: 0px; margin-bottom: 14px; padding-bottom: 15px; font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; color: rgb(102, 102, 102); line-height: 21px; font-size: 14px; "><span id="mt3" class="sentence" data-guid="a318f2de3e47bf4066cbf00dd06c381a" data-source="Pointer to an integer that receives information about the results of the hit test." xml:space="preserve" style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; "><sentencetext xmlns="http://www.w3.org/1999/xhtml" style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; ">为获取有关命中测试的结果的信息的整数的指针测试。</sentencetext> </span><span id="mt4" class="sentence" data-guid="ce58cda36d690c8a9422f4aa2aaafc99" data-source="It can be one or more of the values listed under the <strong>flags</strong> member in the Remarks section." xml:space="preserve" style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; "><sentencetext xmlns="http://www.w3.org/1999/xhtml" style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; ">它可以是一个或多个值列表的"备注"部分的 <span xmlns="http://www.w3.org/1999/xhtml" style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; ">flags</span> 成员下。</sentencetext></span></p></dd><dt style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; "><span class="parameter" style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; font-style: italic; ">pHitTestInfo</span></dt><dd style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; "><p style="margin-top: 0px; margin-bottom: 14px; padding-bottom: 15px; font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; color: rgb(102, 102, 102); line-height: 21px; font-size: 14px; "><span id="mt5" class="sentence" data-guid="27e8f49f8a71cbef4507061c173a65d0" data-source="Address of a <span class="mtpsTagOuterHtml" ><span>TVHITTESTINFO</span></span> structure that contains the position to hit test and that receives information about the results of the hit test." xml:space="preserve" style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; "><sentencetext xmlns="http://www.w3.org/1999/xhtml" style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; ">包含该位置命中 <a target=_blank href="https://msdn.microsoft.com/zh-cn/library/vstudio/bb773448(v=vs.110).aspx" style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; text-decoration: none; color: rgb(19, 130, 206); ">TVHITTESTINFO</a> 结构的地址测试和获取有关命中测试的结果的信息。</sentencetext></span></p></dd></dl></div>

返回值

所指定的树视图项目中处理点或 NULL,如果项目不占据点。


当调用该函数时时,pt 参数指定点的坐标测试。 如果项目不占据点,该函数返回指定的项的处理点或 NULL 此外,pFlags 参数包含一个值来指定点的位置。 可能的值包括:

含义

TVHT_ABOVE

在客户端区域。

TVHT_BELOW

在工作区中。

TVHT_NOWHERE

在工作区,但是,在最后一项下。

TVHT_ONITEM

在位图或标签与项目。

TVHT_ONITEMBUTTON

在按钮上与项目。

TVHT_ONITEMICON

在位图与项目。

TVHT_ONITEMINDENT

在缩进与项目。

TVHT_ONITEMLABEL

在标签(字符串)与项目。

TVHT_ONITEMRIGHT

在项目右边的区域。

TVHT_ONITEMSTATEICON

在一个用户定义状态的树视图项的状态图标。

TVHT_TOLEFT

在工作区左边。

TVHT_TORIGHT

在工作区的右侧。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值