Nevermind, here's a working example:
Code:
/*
typedef struct {
UINT mask;
int iItem;
int iSubItem;
UINT state;
UINT stateMask;
LPTSTR pszText;
int cchTextMax;
int iImage;
LPARAM lParam;
#if (_WIN32_IE >= 0x0300)
int iIndent;
#endif
#if (_WIN32_WINNT >= 0x0501)
int iGroupId;
UINT cColumns;
UINT puColumns;
#endif
#if (_WIN32_WINNT >= 0x0600)
int piColFmt;
int iGroup;
#endif
} LVITEM, *LPLVITEM;
*/
SetlParam(RowNumber, lParam, hwnd)
{
if(!this.IndependentSorting)
return
VarSetCapacity(LVITEM, 13*4 + 2 * A_PtrSize, 0)
mask := 0x4 ; LVIF_PARAM := 0x4
NumPut(mask, LVITEM, 0, "UInt")
NumPut(RowNumber - 1, LVITEM, 4, "Int") ; iItem
NumPut(lParam, LVITEM, 7*4 + A_PtrSize, "PTR")
;~ string := this.hex(LVITEM, "UINT|INT|INT|UINT|UINT|PTR|INT|INT|PTR|INT|INT|UINT|UINT|INT|INT")
SendMessage, % LVM_SETITEM := (A_IsUnicode ? 0x1000 + 76 : 0x1000 + 6), 0, &LVITEM,,% "ahk_id " hwnd
;~ result := errorlevel
;~ result := DllCall("SendMessage", "PTR", hwnd, "UInt", LVM_SETITEM := (A_IsUnicode ? 0x1000 + 76 : 0x1000 + 6), "PTR", 0, "PTRP", LVITEM, "PTR")
;~ lParam2 := this.GetlParam(RowNumber, hwnd)
return ErrorLevel
}
GetlParam(RowNumber, hwnd)
{
if(!this.IndependentSorting)
return RowNumber
VarSetCapacity(LVITEM, 13*4 + 2 * A_PtrSize, 0)
mask := 0x4 ; LVIF_PARAM := 0x4
NumPut(mask, LVITEM, 0, "UInt")
NumPut(RowNumber - 1, LVITEM, 4, "Int") ; iItem
;~ NumPut(lParam, LVITEM, 7*4 + A_PtrSize, "PTR")
;~ string := this.hex(LVITEM, "UINT|INT|INT|UINT|UINT|PTR|INT|INT|PTR|INT|INT|UINT|UINT|INT|INT")
SendMessage, % LVM_GETITEM := (A_IsUnicode ? 0x1000 + 75 : 0x1000 + 5), 0, &LVITEM,,% "ahk_id " hwnd
;~ result := errorlevel
;~ result := DllCall("SendMessage", "PTR", hwnd, "UInt", LVM_GETITEM := (A_IsUnicode ? 0x1000 + 75 : 0x1000 + 5), "PTR", 0, "PTRP", LVITEM, "PTR")
;~ string := this.hex(LVITEM, "UINT|INT|INT|UINT|UINT|PTR|INT|INT|PTR|INT|INT|UINT|UINT|INT|INT")
lParam := NumGet(LVITEM, 7*4 + A_PtrSize, "PTR")
return lParam
}
;Returns the sorted index (by which AHK usually accesses listviews) by searching for a custom index that is independent of sorting
/*
typedef struct tagLVFINDINFO {
UINT flags; 4
LPCTSTR psz; 4-8
LPARAM lParam; 4- 8
POINT pt; 8
UINT vkDirection; 4
} LVFINDINFO, *LPFINDINFO;
*/
GetSortedIndex(UnsortedIndex, hwnd)
{
if(!this.IndependentSorting)
return UnsortedIndex
;Create the LVFINDINFO structure
VarSetCapacity(LVFINDINFO, 4*4 + 2 * A_PtrSize, 0)
mask := 0x1 ; LVFI_PARAM := 0x1
NumPut(mask, LVFINDINFO, 0, "UInt")
NumPut(UnsortedIndex, LVFINDINFO, 4 + A_PtrSize, "PTR")
;~ string := hex(LVFINDINFO, "UINT|INT|INT|UINT|UINT|PTR|INT|INT|PTR|INT|INT|UINT|UINT|INT|INT")
SendMessage, % LVM_FINDITEM := (A_IsUnicode ? 0x1000 + 83 : 0x1000 + 13), -1, &LVFINDINFO,,% "ahk_id " hwnd
;~ MsgReply := ErrorLevel > 0x7FFFFFFF ? -(~ErrorLevel) - 1 : ErrorLevel
;~ result := DllCall("SendMessage", "PTR", hwnd, "UInt", LVM_FINDITEM := (A_IsUnicode ? 0x1000 + 83 : 0x1000 + 13), "PTR", -1, "UIntP", LVITEM, "PTR") + 1
return ErrorLevel + 1
}
Adjust it to your needs as it's a snippet from my code. I'm writing a listview feature that makes it possible to access listview rows by an index that is independent of the sorting of the listview, so it is easier to sync an array with the listview data.