AutoHotkey Community

It is currently May 27th, 2012, 1:39 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 19 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: March 12th, 2011, 11:58 pm 
Offline

Joined: May 3rd, 2009, 7:16 pm
Posts: 345
Location: OH, USA
Updated to 1.01.

This is probably the last update that will be done for a while unless any bugs are found or anyone requests a new feature.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 24th, 2011, 8:27 pm 
Offline

Joined: October 13th, 2009, 10:09 pm
Posts: 1389
Could you demonstrate how to properly get/set the lParam property of LVITEM structure and how to find a list item with a specific lParam value?

I tried to do so using LVM_SETITEM, LVM_GETITEM and LVM_FINDITEM, but I must be doing something wrong.

Here's my current approach:
Code:
SetlParam(RowNumber, lParam, hwnd)
{
   WinGetClass, class, ahk_id %hwnd%
   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")
   result := DllCall("SendMessage", "PTR", hwnd, "UInt", LVM_SETITEM := (A_IsUnicode ? 0x1000 + 76 : 0x1000 + 6), "PTR", 0, "UIntP", LVITEM, "UINT")
   lParam2 := this.GetlParam(RowNumber, hwnd)
   return result
}
GetlParam(RowNumber, hwnd)
{
   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")
   result := DllCall("SendMessage", "PTR", hwnd, "UInt", LVM_GETITEM := (A_IsUnicode ? 0x1000 + 75 : 0x1000 + 5), "PTR", 0, "UIntP", LVITEM, "UINT")
   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
GetSortedIndex(UnsortedIndex, hwnd)
{
   ;Create the LVITEM structure
   VarSetCapacity(LVITEM, 13*4 + 2 * A_PtrSize, 0)
   mask := 0x4   ; LVIF_PARAM := 0x4
   NumPut(mask, LVITEM, 0, "UInt")
   NumPut(UnsortedIndex, LVITEM, 7 * 4 + A_PtrSize, "PTR")
   result := DllCall("SendMessage", "PTR", hwnd, "UInt", LVM_FINDITEM := (A_IsUnicode ? 0x1000 + 83 : 0x1000 + 13), "PTR", -1, "UIntP", LVITEM, "PTR") + 1
   return result
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 24th, 2011, 10:10 pm 
Offline

Joined: October 13th, 2009, 10:09 pm
Posts: 1389
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 25th, 2011, 11:23 pm 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
Old post but I just found it. Looks useful. Thanks. :)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group