Listview_getitem()宏在win32 api中返回空STRING [英] Listview_getitem() macro returns empty STRING in win32 api

查看:107
本文介绍了Listview_getitem()宏在win32 api中返回空STRING的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试从列表视图中删除所选项时,ListView_GetItem()返回空文本。这里只添加了我从列表视图中获取所选文本项的代码。





When I'm trying to remove the selected item from the list view, the "ListView_GetItem()" returns empty text. Here just added my code for getting selected text item from the list view.


LVITEM lvitem;
int item = ListView_GetNextItem(listView, -1, LVNI_SELECTED);

if (selectedItem != -1)
{
			wchar_t str[1024];
			lvitem.cchTextMax= 552;
			lvitem.mask= LVIF_TEXT;
			lvitem.iItem= selectedItem;
			lvitem.pszText= str;
			ListView_GetItem(listView, &lvitem);
			// Here Printing "lvi.pszText" text
}





注意:我正在使用Windows 10 OS。它对我来说正常。但它在少数同样具有相同Windows 10操作系统的系统中也无法运行。







给我任何建议来解决这个问题...



我尝试了什么:



当我尝试从列表中删除所选项目时在视图中,ListView_GetItem()返回空文本。这里只添加了我从列表视图中获取所选文本项的代码。







Note: I'm using windows 10 OS. It's working correctly for me. But it's not working in few systems that also have same Windows 10 OS.



Give me any suggestions to resolve this problem...

What I have tried:

When I'm trying to remove the selected item from the list view, the "ListView_GetItem()" returns empty text. Here just added my code for getting selected text item from the list view.


LVITEM lvitem;
int item = ListView_GetNextItem(listView, -1, LVNI_SELECTED);

if (selectedItem != -1)
{
			wchar_t str[1024];
			lvitem.cchTextMax= 552;
			lvitem.mask= LVIF_TEXT;
			lvitem.iItem= selectedItem;
			lvitem.pszText= str;
			ListView_GetItem(listView, &lvitem);
			// Here Printing "lvi.pszText" text
}





注意:我正在使用Windows 10 OS。它对我来说正常。但是它在少数同样具有相同Windows 10操作系统的系统中也不起作用。



Note: I'm using windows 10 OS. It's working correctly for me. But it's not working in few systems that also have same Windows 10 OS.

推荐答案

你没有设置 lvitem.iSubItem = 0;

那么,你如何检查返回字符串?
You didn't set lvitem.iSubItem = 0;
By the way, how do you check the return string?


这是你的固定代码:



Here is your fixed code:

LVITEM lvitem;
int item = ListView_GetNextItem(listView, -1, LVNI_SELECTED);

if (selectedItem != -1)
{
	wchar_t str[1024];
	lvitem.cchTextMax = 552;
	lvitem.mask = LVIF_TEXT;
	lvitem.iItem = selectedItem;
	lvitem.pszText = str;
	lvitem.iSubItem = 0;
	ListView_GetItem(listView, &lvitem);
	// Here Printing "lvi.pszText" text
}


我很惊讶这在任何地方都有效。尝试这样的事情:
I am surprised this works ANYWHERE. Try something like this :
int selectedItem = ListView_GetNextItem(listView, -1, LVNI_SELECTED);
if( selectedItem != -1 )
{
    LVITEM lvitem = { 0 };
    const int strsize = 511;
    wchar_t str[strsize+1] = { 0 };
    lvitem.cchTextMax= strsize;
    lvitem.mask= LVIF_TEXT;
    lvitem.iItem= selectedItem;
    lvitem.pszText= str;
    ListView_GetItem( listView, &lvitem );
    // Here Printing "lvi.pszText" text
}


这篇关于Listview_getitem()宏在win32 api中返回空STRING的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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