简体   繁体   English

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

[英]Get ListView item text from other window

I want to make a little application that changes the default playback device in windows 7. The only solution was to interact with the Sound Applet. 我想创建一个小应用程序来更改Windows 7中的默认播放设备。唯一的解决方案是与Sound Applet交互。 I succeeded to get the handle to the SysListView32 window that has the devices name but i cant get the text from the ListView. 我成功获取了具有设备名称的SysListView32窗口的句柄,但我无法从ListView获取文本。

This is the code used: 这是使用的代码:

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);

The result (strLvi) are some chinese letters. 结果(strLvi)是一些中文字母。 What is wrong in the script? 脚本有什么问题?

UPDATE : LVITEM struct is this: 更新 :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;
}

The sLIstView handle is correct... a checked in spy++. sLIstView句柄是正确的...签入间谍++。 What test do i need to perform to check where is the problem? 我需要做什么测试来检查问题出在哪里? I could give you all the script if that would help. 如果能有所帮助,我可以给你所有的剧本。

您是否尝试过使用LWM_GETITEMTEXTW?

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM