gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 12:51:08 27 4
gpt4 key购买 nike

我想制作一个小应用程序来更改 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 句柄是正确的...已在 spy++ 中检查过。我需要执行什么测试来检查问题出在哪里?如果有帮助,我可以给你所有的脚本。

最佳答案

您是否尝试过使用 LWM_GETITEMTEXTW?

关于c# - 从其他窗口获取 ListView 项目文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7589592/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com