ListView_GetItem()返回FALSE
我有一个Windows应用程序,在其中调用ListView_GetItem(),它返回FALSE(错误)。请参阅下面的代码。传递的值是sel_index的第10行,Col的第1行,buf足够大,GetLastError()返回0。ListView_GetItem()返回FALSE,listview,winapi,listviewitem,Listview,Winapi,Listviewitem,我有一个Windows应用程序,在其中调用ListView_GetItem(),它返回FALSE(错误)。请参阅下面的代码。传递的值是sel_index的第10行,Col的第1行,buf足够大,GetLastError()返回0。ListView_GetItem宏的Windows联机文档没有说明失败的原因或可能的错误代码。 有人能告诉我可能出了什么问题吗? 我用 hList = CreateWindow(WC_LISTVIEW, "", WS_CHILD | WS_BORDER | LVS_RE
ListView_GetItem宏的Windows联机文档没有说明失败的原因或可能的错误代码。 有人能告诉我可能出了什么问题吗?
我用
hList = CreateWindow(WC_LISTVIEW, "", WS_CHILD | WS_BORDER | LVS_REPORT | WS_HSCROLL | WS_VSCROLL | WS_EX_CLIENTEDGE, ... etc
{
LV_ITEM Item; // List view item structure
char buf[10];
Item.mask=LVIF_TEXT;
Item.pszText = buf; // buffer
Item.iItem = sel_index; // selected line
Item.iSubItem = Col; // want subitem
if(!ListView_GetItem(hList, &Item))
{
PrintErr("\r\nGetSubItem failed, error=%d",GetLastError());
return "";
}
return (Item.pszText);
}
您未初始化大部分字段。不设置
cchTextMax
是最痛的。初始化结构,如下所示:
LV_ITEM Item = {0};
并将cchTextMax
设置为10
Item.pszText = buf;
Item.cchTextMax = 10;
您未初始化大部分字段。不设置
cchTextMax
尤其令人震惊。初始化结构:LV_ITEM={0}
并将cchTextMax
设置为10
。没错,这就是问题所在,非常感谢!。你能把这当作一个答案而不是评论,这样我们就可以把问题标记为已解决了吗?