Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. I succeeded to get the handle to the SysListView32 window that has the devices name but i cant get the text from the 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. What is wrong in the script?

UPDATE: LVITEM struct is this:

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++. What test do i need to perform to check where is the problem? I could give you all the script if that would help.

like image 477
Sp3ct3R Avatar asked Nov 13 '22 16:11

Sp3ct3R


1 Answers

Have you tried using LWM_GETITEMTEXTW instead?

like image 130
Sergey Kudriavtsev Avatar answered Dec 16 '22 19:12

Sergey Kudriavtsev