Get ListView item text from another window

I want to create a small application that will change the default playback device in Windows 7. The only solution was to interact with the Sound Applet. I managed to get the SysListView32 window handle with the device name, but I can not get the text from the ListView.

This code is 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) is some Chinese letters. What is wrong with the script?

UPDATE : LVITEM structure:

 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 ... tested in spy ++. What test do I need to run to check where the problem is? I could give you all the script if that helps.

+4
source share
1 answer

Instead, you tried to use LWM_GETITEMTEXTW?

+1
source

All Articles