简体   繁体   English

“int”类型的参数与“HTREEITEM”类型的参数不兼容

[英]argument of type “int” is incompatible with parameter of type “HTREEITEM”

I'm getting error in line:我在行中遇到错误:

if (TreeView.GetItemState(item, TVIS_SELECTED) == TVIS_SELECTED)

It's not accepting item .它不接受item New to using HTREEITEM , which is an opaque handle to a tree item in the default TreeView control on Window.使用HTREEITEM的新手,它是 Window 上默认 TreeView 控件中树项的不透明句柄。

How can I get rid of the error?我怎样才能摆脱这个错误? Only including part of the code with error:仅包含部分错误代码:

int item, num;

for(item = 0; item < total; ++item)
{
    if (TreeView.GetItemState(item, TVIS_SELECTED) == TVIS_SELECTED)  //error here on item
    {
        num= item;
        break;
    }
}

The GetItemState() method expects an HTREEITEM handle to a specific tree node, but you are giving it a loop index instead. GetItemState()方法需要一个特定树节点的HTREEITEM句柄,但您却给它一个循环索引。 Tree nodes are not required to be sequential, and so indexing requires more work.树节点不需要是顺序的,因此索引需要更多的工作。 The correct way to iterate a TreeView is to use methods like GetRootItem() , GetNextItem() , GetChildItem() , etc which all return HTREEITEM handles.迭代 TreeView 的正确方法是使用GetRootItem()GetNextItem()GetChildItem()等方法,它们都返回HTREEITEM句柄。 For example:例如:

HTREEITEM item = NULL;

HTREEITEM node = TreeView.GetRootItem();

for(int num = 0; num < total; ++num)
{
    if (TreeView.GetItemState(node, TVIS_SELECTED) == TVIS_SELECTED)
    {
        item = node;
        break;
    }

    node = TreeView.GetNextItem(node, TVGN_NEXT);
}

However, in your particular example, it would be easier to use the GetSelectedItem() method instead of a manual GetItemState() loop, eg:但是,在您的特定示例中,使用GetSelectedItem()方法而不是手动GetItemState()循环会更容易,例如:

HTREEITEM item = TreeView.GetSelectedItem();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型为“ int”的参数与类型为“ int *”的参数不兼容 - Argument of type “int” is incompatible with parameter of type “int *” 类型“ int”的参数与参数类型“ int **”不兼容 - argument of type “int” is incompatible with parameter type “int **” 类型“int”的参数与类型“int”的参数不兼容 - argument of type “int” incompatible with parameter of type “int” int(*)[] 类型的参数与“int**”类型的参数不兼容 - Argument of type int(*)[] is incompatible with parameter of type “int**” “int”类型的参数与“int*”类型的参数不兼容 - argument of type “int” incompatible with parameter of type “int*” “ int”类型的参数与“ char”类型的参数不兼容 - Argument of type 'int' is incompatible with parameter of type 'char' 错误:参数类型int与参数类型不兼容 - ERROR: argument type int incompatible for parameter type “类型为 &#39;int(*)()&#39; 的参数与类型为 int 的参数不兼容”错误? - "argument of type ”int(*)()“ is incompatible with parameter of type int" error? “int*”类型的参数与“int**”类型的参数不兼容 C++ 中的错误 - argument of type “int*” is incompatible with parameter of type “int**” error in C++ “unsigned int *”类型的参数与“size_t *”类型的参数不兼容 - argument of type “unsigned int *” is incompatible with parameter of type “size_t *”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM