如何在MFC中的ctreectrl中处理三个复选框状态? [英] How to handle tri-checkbox states in ctreectrl in MFC?

查看:176
本文介绍了如何在MFC中的ctreectrl中处理三个复选框状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在MFC中创建了三态Ctreectrl,但是在单击复选框状态时没有在同一个实例上更新。

例如我检查了复选框,但是通过使用GetItemState()我得到每个项目1。如果相同的项目我取消选中我正在检查。所以,它正在回归旧州,我试图获得新的状态。有人可以通过一些代码片段来帮助我吗?



我尝试过:



我选中了复选框但是通过使用GetItemState()我得到每个项目1。如果相同的项目我取消选中我正在检查。所以,它正在回归旧州,我正试图获得新的州。



[由Jochen Arndt编辑:复制评论]

< pre lang =c ++> ITreeCtrl m_FiletreeCtrl = DEBUG_NEW ITreeCtrl;
HTREEITEM hItem = m_FiletreeCtrl-> GetTreeCtrl()。HitTest(point,& flags);
HTREEITEM hItem2 = m_FilestreeCtrl-> GetTreeCtrl()。GetParentItem(hItem);
HTREEITEM hChildItem = NULL;
while (hItem22!= NULL)
{
hChildItem = m_FilestreeCtrl-> GetTreeCtrl()。GetChildItem(hItem22);
while (hChildItem)
{
UINT nCurrentState =(m_FilestreeCtrl-> GetTreeCtrl()。GetItemState(hChildItem,TVIS_STATEIMAGEMASK)> ;>位于0xC);
}
}



在这棵树中,我只想知道检查了多少项,但GetItemState正在返回旧状态。

[/ EDIT]

解决方案

评论代码:

 UINT nCurrentState =(m_FilestreeCtrl-> ; GetTreeCtrl()GetItemState(hChildItem,TVIS_STATEIMAGEMASK)GT;>位于0xC); 



您没有查询复选框状态,而是状态图像索引。该索引定义实际显示状态图像列表中的哪个图像。按照惯例,索引为零表示没有状态图像。索引为1(由您检测)用于未检查的图像。另请参见如何使用状态图像索引(Windows) [ ^ ]。


Hi,
I created tri-state Ctreectrl in MFC, But while clicked on checkbox state is not updating on same instance.
For e.g. I checked on checkbox but by using GetItemState() i'm getting 1 for each item. If same item i'm unchecking i'm getting checked. So, It is returning Old state I trying to get new state. Can anybody help me out by some code snippet ?

What I have tried:

I checked on checkbox but by using GetItemState() i'm getting 1 for each item. If same item i'm unchecking i'm getting checked. So, It is returning Old state I am trying to get new state.

[EDIT by Jochen Arndt: Copied from comment]

ITreeCtrl m_FiletreeCtrl = DEBUG_NEW ITreeCtrl;
HTREEITEM hItem = m_FiletreeCtrl->GetTreeCtrl().HitTest(point, &flags);
HTREEITEM hItem2 = m_FilestreeCtrl->GetTreeCtrl().GetParentItem(hItem);
HTREEITEM hChildItem = NULL;
while(hItem22 != NULL)
{
    hChildItem = m_FilestreeCtrl->GetTreeCtrl().GetChildItem(hItem22);
    while(hChildItem)
    {
        UINT nCurrentState = (m_FilestreeCtrl->GetTreeCtrl().GetItemState(hChildItem,TVIS_STATEIMAGEMASK)>>0xC);
    }
}


In this Tree I just want to know how many Items are checked, but GetItemState is returning Old state.
[/EDIT]

解决方案

Code from comment:

UINT nCurrentState = (m_FilestreeCtrl->GetTreeCtrl().GetItemState(hChildItem,TVIS_STATEIMAGEMASK)>>0xC);


You are not querying a check box state but the state image index. This index defines which image from the state image list is actually shown. By convention an index of zero indicates that there is no state image. An index of one (as detetected by you) is for the unchecked image. See also How to Work With State Image Indexes (Windows)[^].


这篇关于如何在MFC中的ctreectrl中处理三个复选框状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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