AutoHotkey Community

It is currently May 26th, 2012, 9:56 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: June 12th, 2009, 11:06 pm 
Offline

Joined: May 3rd, 2009, 7:16 pm
Posts: 345
Location: OH, USA
This is for those people that use more than 1 ListView control and wish to control them using handles to avoid problems caused by thread interruptions. It is still incomplete but it has enough to manage a basic ListView in report mode. All of these functions use/return 1 based indices for AHK loop compatibility.

The built-in functions are much faster so I don't recommend using this library for time critical applications.

1.0 -> 1.01 Changes:
- added unicode support for LVM_GetText.
- now using "A_IsUnicode" variable to make sure we use the appropriate messages in LVM_GetText, LVM_Modify, and LVM_Insert.

0.92 -> 1.0 Changes:
- library now requires AutoHotkey_L 60+.
- changed the modify and insert functions to use a variadic parameter for data fields.
- removed the "end column" parameter from the modify and insert functions. You must now only supply the start column. This is thanks to the variadic parameter. However, due to this change, you may need to update your function calls.

0.91 -> 0.92 Changes:
- library now requires AutoHotkey_L 42+.
- added A_PtrSize variable for optional 64-bit support.
- changed LVM_SETITEM to LVM_SETITEMW for unicode support.
- now using "ptr" type on various dllcalls for pointer sized integers.

0.90 -> 0.91 Changes:
- added "LVM_GetColOrder" function.
- fixed "LVM_Insert" function not correctly adding rows to the bottom of the LV.
- fixed comments for "LVM_Modify" function.


Download

Code:
/*
  ListView function library by Solar. Version 1.01
 
  Flag reference:
   flag  constant  description
   -
   LVIS_FOCUSED         1       The item has the focus, so it is surrounded by a standard focus rectangle. Although more than one item may be selected, only one item can have the focus.
   LVIS_SELECTED        2       The item is selected. The appearance of a selected item depends on whether it has the focus and also on the system colors used for selection.
   LVIS_CUT             4       The item is marked for a cut-and-paste operation.
   LVIS_DROPHILITED     8       The item is highlighted as a drag-and-drop target.
   LVIS_ACTIVATING      0x20    Not currently supported.
   LVIS_UNCHECKED       0x1000  Undocumented.
   LVIS_CHECKED         0x2000  Undocumented.
   LVIS_OVERLAYMASK     0xF00   Use this mask to retrieve the item's overlay image index.
   LVIS_STATEIMAGEMASK  0xF000  Use this mask to retrieve the item's state image index.
   -
   LVNI_ALL            0      Searches for a subsequent item by index, the default value.
   LVNI_FOCUSED        1      The item has the LVIS_FOCUSED state flag set.
   LVNI_SELECTED       2      The item has the LVIS_SELECTED state flag set.
   LVNI_CUT            4      The item has the LVIS_CUT state flag set.
   LVNI_DROPHILITED    8      The item has the LVIS_DROPHILITED state flag set
   LVNI_STATEMASK      0xf    Microsoft Windows Vista and later: A state flag mask with value as follows: LVNI_FOCUSED | LVNI_SELECTED | LVNI_CUT | LVNI_DROPHILITED.
   LVNI_VISIBLEORDER   0x10   Searches for a subsequent item by index, the default value.
   LVNI_PREVIOUS       0x20   Microsoft Windows Vista and later: Searches for an item that is ordered before the item specified in plvii. The LVNI_PREVIOUS flag is not directional (LVNI_ABOVE will find the item positioned above, while LVNI_PREVIOUS will find the item ordered before.) The LVNI_PREVIOUS flag basically reverses the logic of the search performed by the LVM_GETNEXTITEM or LVM_GETNEXTITEMINDEX messages.
   LVNI_VISIBLEONLY    0x40   Microsoft Windows Vista and later: Search the visible items.
   LVNI_SAMEGROUPONLY  0x80   Microsoft Windows Vista and later: Search the current group.
   LVNI_ABOVE          0x100  Searches for an item that is above the specified item.
   LVNI_BELOW          0x200  Searches for an item that is below the specified item.
   LVNI_TOLEFT         0x400  Searches for an item to the left of the specified item.
   LVNI_TORIGHT        0x800  Searches for an item to the right of the specified item.
   LVNI_DIRECTIONMASK  0xf00  Microsoft Windows Vista and later: A directional flag mask with value as follows: LVNI_ABOVE | LVNI_BELOW | LVNI_TOLEFT | LVNI_TORIGHT.
*/


;  h = ListView handle.
LVM_GetCount(h)
{
   Return DllCall("SendMessage", "uint", h, "uint", 4100, "uint", 0, "uint", 0) ; LVM_GETITEMCOUNT
}

; h = ListView handle.
LVM_GetColOrder(h)
{
   hdrH := DllCall("SendMessage", "uint", h, "uint", 4127) ; LVM_GETHEADER
   hdrC := DllCall("SendMessage", "uint", hdrH, "uint", 4608) ; HDM_GETITEMCOUNT
   VarSetCapacity(o, hdrC * A_PtrSize)
   DllCall("SendMessage", "uint", h, "uint", 4155, "uint", hdrC, "ptr", &o) ; LVM_GETCOLUMNORDERARRAY
   Loop, % hdrC
      result .= NumGet(&o, (A_Index - 1) * A_PtrSize) + 1 . ","
   StringTrimRight, result, result, 1
   Return result
}

; h = ListView handle.
; c = 1 based indexed comma delimited list of the new column order.
LVM_SetColOrder(h, c)
{
   StringSplit, c, c, `,
   VarSetCapacity(c, c0 * A_PtrSize)
   Loop, % c0
      NumPut(c%A_Index% - 1, c, (A_Index - 1) * A_PtrSize)
   Return DllCall("SendMessage", "uint", h, "uint", 4154, "uint", c0, "ptr", &c) ; LVM_SETCOLUMNORDERARRAY
}

; h = ListView handle.
; c = 1 based column index to get width of.
LVM_GetColWidth(h, c)
{
   Return DllCall("SendMessage", "uint", h, "uint", 4125, "uint", c-1, "uint", 0) ; LVM_GETCOLUMNWIDTH
}

; h = ListView handle.
; c = 1 based column index to get width of.
; w = New width of the column in pixels. Defaults to -1. The following values are supported in report-view mode:
;   "-1" - Automatically sizes the column.
;   "-2" - Automatically sizes the column to fit the header text. If you use this value with the last column, its width is set to fill the remaining width of the list-view control.
LVM_SetColWidth(h, c, w=-1)
{
   Return DllCall("SendMessage", "uint", h, "uint", 4126, "uint", c-1, "int", w) ; LVM_SETCOLUMNWIDTH
}

; h = ListView handle.
; r = 1 based index of the starting row for the flag search. Omit or 0 to find first occurance specified flags.
; o = Combination of one or more LVNI flags. See reference above.
LVM_GetNext(h, r=0, o=0)
{
   Return DllCall("SendMessage", "uint", h, "uint", 4108, "uint", r-1, "uint", o) + 1 ; LVM_GETNEXTITEM
}

; h = ListView handle.
; r = 1 based index of the row to retrieve the text from.
; c = 1 based index of the column to retrieve the text from.
LVM_GetText(h, r, c=1)
{
   r -= 1 ; convert to 0 based index
   VarSetCapacity(t, 511, 1)
   VarSetCapacity(lvItem, A_PtrSize * 7)
   NumPut(1, lvItem, "uint") ; mask
   NumPut(r, lvItem, A_PtrSize, "int") ; iItem
   NumPut(c-1, lvItem, A_PtrSize * 2, "int") ; iSubItem
   NumPut(&t, lvItem, A_PtrSize * 5, "ptr") ; pszText
   NumPut(512, lvItem, A_PtrSize * 6) ; cchTextMax
   If (A_IsUnicode)
      DllCall("SendMessage", "uint", h, "uint", 4211, "uint", r, "ptr", &lvItem) ; LVM_GETITEMTEXTW
   Else
      DllCall("SendMessage", "uint", h, "uint", 4141, "uint", r, "ptr", &lvItem) ; LVM_GETITEMTEXTA
   Return t
}

; h = ListView handle.
; i = 1 based index of item to delete. Omit to delete all items.
LVM_Delete(h, i=0)
{
   If (i)
      DllCall("SendMessage", "uint", h, "uint", 4104, "uint", i-1, "uint", 0) ; LVM_DELETEITEM
   Else
      DllCall("SendMessage", "uint", h, "uint", 4105, "uint", 0, "uint", 0) ; LVM_DELETEALLITEMS
}

; h = ListView handle.
; r = 1 based index of the row to be modified.
; c = 1 based index of the starting column.
; o = Combination of LVIS flags (see above).
; f* = Fields to modify each column. Each field will be modified in subsequent order starting with the c param. This param is variadic. See: http://www.autohotkey.net/~Lexikos/AutoHotkey_L/docs/Functions.htm#Variadic
LVM_Modify(h, r, c=1, o=0, f*)
{
   c -= 1 ; convert to 0 based index
   VarSetCapacity(lvItem, A_PtrSize * 6, 0)
   NumPut(9, lvItem, "uint")   ; mask
   NumPut(r-1, lvItem, A_PtrSize, "int") ; iItem
   NumPut(o, lvItem, A_PtrSize * 3, "uint") ; state
   NumPut(1, lvItem, A_PtrSize * 4, "uint") ; stateMask
   For index,field in f
   {
      NumPut(c + A_Index - 1, lvItem, A_PtrSize * 2, "int") ; iSubItem
      NumPut(&field, lvItem, A_PtrSize * 5, "ptr") ; pszText
      If (A_IsUnicode)
         DllCall("SendMessage", "uint", h, "uint", 4172, "uint", 0, "ptr", &lvItem) ; LVM_SETITEMW
      Else
         DllCall("SendMessage", "uint", h, "uint", 4171, "uint", 0, "ptr", &lvItem) ; LVM_SETITEMA
   }
}

; h = ListView handle.
; r = 1 based index position of the newly inserted row. Omit or 0 to add to bottom of list.
; c = 1 based index of the starting column.
; o = Multiple of one or more of the LVIS flags listed above.
; f* = Fields to fill each column. Each field will be inserted in subsequent order starting with the c param. This param is variadic. See: http://www.autohotkey.net/~Lexikos/AutoHotkey_L/docs/Functions.htm#Variadic
LVM_Insert(h, r=0, c=1, o=0, f*)
{
   c -= 1 ; convert to 0 based index
   If (r = 0)
      r := (DllCall("SendMessage", "uint", h, "uint", 4100, "uint", 0, "uint", 0) = -1 ? 0) + 1 ; LVM_GETITEMCOUNT
   VarSetCapacity(lvItem, A_PtrSize * 6, 0)
   NumPut(9, lvItem, "uint")   ; mask
   NumPut(r-1, lvItem, A_PtrSize, "int") ; iItem
   NumPut(o, lvItem, A_PtrSize * 3, "uint")  ; state
   NumPut(1, lvItem, A_PtrSize * 4, "uint")  ; stateMask
   DllCall("SendMessage", "uint", h, "uint", 4103, "uint", 0, "uint", &lvItem)   ; LVM_INSERTITEM
   For index,field in f
   {
      NumPut(c + A_Index - 1, lvItem, A_PtrSize * 2, "int") ; iSubItem
      NumPut(&field, lvItem, A_PtrSize * 5, "ptr") ; pszText
      If (A_IsUnicode)
         DllCall("SendMessage", "uint", h, "uint", 4172, "uint", 0, "ptr", &lvItem) ; LVM_SETITEMW
      Else
         DllCall("SendMessage", "uint", h, "uint", 4171, "uint", 0, "ptr", &lvItem) ; LVM_SETITEMA
   }
}


Last edited by Solar on March 12th, 2011, 11:56 pm, edited 7 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 27th, 2009, 8:54 am 
Offline

Joined: May 3rd, 2009, 7:16 pm
Posts: 345
Location: OH, USA
Bump for new version.

I recently needed this library again so I decided to add a new function and fix a couple problems.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 27th, 2009, 1:01 pm 
Offline

Joined: September 6th, 2009, 4:22 pm
Posts: 20
Hi Solar, Could you also post a simple complete example, please?

Is this ListView handle library some that could help me with my current ListView problem here?:
http://www.autohotkey.com/forum/viewtopic.php?t=49305

For newbies like me, getting some advice from you more experienced guys, can save hours of pain/torture.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 28th, 2009, 6:07 pm 
Offline

Joined: May 3rd, 2009, 7:16 pm
Posts: 345
Location: OH, USA
I will post examples shortly. Until then, perhaps if I tried to better explain it:

I created this library to add direct control over a specific listview when using more than 1 listview control in your gui. If you haven't noticed while using the built-in functions, to function a listview control that wasn't the most recently added, you must first change the listview control to the "most recently added" before the built-in functions will work with it:

AHK Help wrote:
If the window has more than one ListView control, by default the functions operate upon the one most recently added. To change this, specify Gui, ListView, ListViewName, where ListViewName is the name of the ListView's associated variable or its ClassNN as shown by Window Spy.


The problem with this method occurs when you have thread interruptions causing the wrong listview to become the "most recently added" and writing data to the wrong control.

With my library, by passing the listview control's handle directly to each function, you can operate on your listview controls without worrying about interrupt problems.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 26th, 2009, 8:38 pm 
Offline
User avatar

Joined: July 17th, 2008, 12:58 am
Posts: 270
bump!

are there any updates or examples for this?

_________________
QuickSubs | Popcorn Movie Db
All my scripts are just in AutoHotkey v1.0.48.05


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 27th, 2009, 12:59 pm 
Offline

Joined: June 12th, 2009, 2:57 am
Posts: 4
this is nice.

I've made an custom xml editor in ahk for my webbpage and it has more than 1 listview.
My big problem was that some text / settings came in the wrong listviews with this code:
Code:
Gui, ListView, lCat
  LV_ModifyCol(1, 145)
  LV_ModifyCol(2, 0)
Gui, Listview, lProd
  lv_modifycol(4,0)
  lv_modifycol(2, "right")
  lv_modifycol(2, "AutoHdr")
  lv_modifycol(1, "AutoHdr")


I've solved that by using the line 'Gui, listview, Some_LV' before each executing line.
Code:
    Gui, ListView, lCat
    LV_ModifyCol(1, 145)
    Gui, ListView, lCat
    LV_ModifyCol(2, 0)
  Gui, Listview, lProd
  lv_modifycol(4,0)
  Gui, Listview, lProd
  lv_modifycol(2, "right")
  Gui, Listview, lProd
  lv_modifycol(2, "AutoHdr")
  Gui, Listview, lProd
  lv_modifycol(1, "AutoHdr")

I'll check out your functions and hopefully they work...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 6th, 2010, 2:53 pm 
i was searching for a library to handle more than one listview and came upon this

are there any updates for this or will there be any?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2011, 3:56 am 
Offline

Joined: May 3rd, 2009, 7:16 pm
Posts: 345
Location: OH, USA
Recently needed this script again. Decided to update it to support AutoHotkey_L. See OP for changes.

I apologize for not making an example script for anyone interested in this. The truth is that I'm just too lazy. :(


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2011, 12:44 pm 
Offline

Joined: September 15th, 2006, 10:25 am
Posts: 567
making the last two functions variadic can make it sweeter
ref: Variadic Functions

_________________
If i've seen further it is by standing on the shoulders of giants

my site | ~shajul | WYSIWYG BBCode Editor


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2011, 3:28 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
shajul wrote:
making the last two functions variadic can make it sweeter...


What's any less sweet about a variadic function call, which you can already use without the author re-inventing the wheel?

Code:
LVM_Modify(h,r,Object("o",0xF000,"f2","Lions","f3","Tigers","f5","Bears")*)

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2011, 6:19 pm 
Offline

Joined: May 3rd, 2009, 7:16 pm
Posts: 345
Location: OH, USA
shajul wrote:
making the last two functions variadic can make it sweeter
ref: Variadic Functions


I was unaware of this functionality as I have just come back to AHK (and transitioned into AHK_L) again. This is a great idea and will most likely be implemented today.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2011, 6:28 pm 
Offline

Joined: September 15th, 2006, 10:25 am
Posts: 567
sinkfaze wrote:
..

cool

_________________
If i've seen further it is by standing on the shoulders of giants

my site | ~shajul | WYSIWYG BBCode Editor


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2011, 7:14 pm 
Offline

Joined: May 3rd, 2009, 7:16 pm
Posts: 345
Location: OH, USA
Updated to 1.0. See changes in OP.

Due to the removal of the "end column", your modify and insert function calls may need to be updated to only supply the starting column. This is the reason I made it version 1.0.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2011, 10:51 am 
Offline

Joined: February 11th, 2007, 4:10 pm
Posts: 185
I want to make the insert function as fast as the build-in function. mcode may be a good idea, but I have not learned C or C++, who can help me?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2011, 4:13 pm 
Offline

Joined: October 13th, 2009, 10:09 pm
Posts: 1389
Please keep x64 compatibility in mind when using mcode.


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 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


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