#cs GetItemText(hList, item)
@param1 = handle to the listview (hWnd)
@param2 = index of the item
@ret = on error, "", on success, the item's text.
#ce
Func GetItemText
(hList
, item
)
; the one in structureconstants.au3 seems to be wrong
const LVITEM
= "UINT mask;int iItem;int iSubItem;UINT state;UINT stateMask; ptr pszText;" & _
"int cchTextMax;int iImage;LPARAM lParam;int iIndent;int iGroupId;UINT cColumns;" & _
"UINT puColumns;int piColFmt;int iGroup;"
; Create and fill the buffer.
Local lvitem
_buf
= DllStructCreate(LVITEM
)
DllStructSetData(lvitem
_buf
, "iSubItem", 0)
DllStructSetData(lvitem
_buf
, "cchTextMax", 0xFF)
DllStructSetData(lvitem
_buf
, "mask", $LVIF_TEXT)
DllStructSetData(lvitem
_buf
, "iItem", item
)
Local size
= DllStructGetSize(lvitem
_buf
)
; Open process and allocate a buffer large enough for the lvitem and the text (appended at back)
Local hMem
= ProcOpen
(hList
), buf
= AllocMemory
(hMem
, size
+ 0xFF)
if not buf
then return ""
; Calc pointer to text, and set it in the lvitem, and write it to the process
Local pText
= buf
+ size
DllStructSetData(lvitem
_buf
, "pszText", pText
)
WriteMemory
(hMem
, buf
, size
)
; Send the message and collect the amount of characters written
Local chars
= _SendMessage(hList
, $LVM_GETITEMTEXTW, DllStructGetData(lvitem
_buf
, "iItem"), buf
, 0)
; Collect a binary string (for debug)
Local bytes
= ReadMemory
(hMem
, buf
, "byte[" & size
+ 0xFF & "]")
; Calc pointer to text to be sure, and get the string.
Local ptextout
= ReadMemory
(hMem
, buf
+ offsetof
(lvitem
_buf
, "pszText"), "ptr")
Local stext
= ReadMemory
(hMem
, ptextout
, "wchar[256]")
; Debug stuff
debugout
(consolewrite, bytes
)
debugout
(consolewrite, "[chars = " & chars
& "]" & stext
)
debugout
(consolewrite, _WinApi_GetLastErrorMessage())
; Clean up
FreeMemory
(hMem
, buf
, size
+ 0xFF)
CloseHandle
(hMem
)
return stext
EndFunc