加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 从其他窗口获取ListView项目文本

发布时间:2020-12-15 21:24:08 所属栏目:百科 来源:网络整理
导读:我想创建一个小应用程序来更改 Windows 7中的默认播放设备.唯一的解决方案是与Sound Applet交互.我成功获取了具有设备名称的SysListView32窗口的句柄,但我无法从ListView获取文本. 这是使用的代码: IntPtr sListView = (window handle received from anothe
我想创建一个小应用程序来更改 Windows 7中的默认播放设备.唯一的解决方案是与Sound Applet交互.我成功获取了具有设备名称的SysListView32窗口的句柄,但我无法从ListView获取文本.

这是使用的代码:

IntPtr sListView = (window handle received from another function)
LVITEM lvi = new LVITEM();
lvi.mask = LVIF_TEXT;
lvi.cchTextMax = 1024;
lvi.iItem = 0; // i tried with a loop trought all the items
lvi.iSubItem = 0;
lvi.pszText = Marshal.AllocHGlobal(1024);

IntPtr ptrLvi = Marshal.AllocHGlobal(Marshal.SizeOf(lvi));
Marshal.StructureToPtr(lvi,ptrLvi,false);

SendMessage(sListView,(int)WinMesages.LVM_GETITEMW,IntPtr.Zero,ptrLvi);

string strLvi = Marshal.PtrToStringAuto(lvi.pszText);

结果(strLvi)是一些中文字母.脚本有什么问题?

更新:LVITEM结构是这样的:

private struct LVITEM
{
    public uint mask;
    public int iItem;
    public int iSubItem;
    public uint state;
    public uint stateMask;
    public IntPtr pszText;
    public int cchTextMax;
    public int iImage;
    public IntPtr lParam;
}

sLIstView句柄是正确的…签入间谍.
我需要做什么测试来检查问题出在哪里?如果能有所帮助,我可以给你所有的剧本.

解决方法

您是否尝试过使用LWM_GETITEMTEXTW?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读