[LIB] LV_EX - update on 2016-04-28

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: [LIB] LV_EX - update on 2016-04-28

07 Mar 2017, 13:45

What kind of data can be stored in the item's lParam? I am attempting to store a GUID and am not receiving the same string back when calling LV_EX_GetItemParam(). i.e. "a7a04166-ea26-11e6-8a43-0225b501000d"
just me
Posts: 9406
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [LIB] LV_EX - update on 2016-04-28

08 Mar 2017, 05:06

lParam will accept pointer-sized numeric values. If you want to use it for strings, store a pointer to the string.
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: [LIB] LV_EX - update on 2016-04-28

08 Mar 2017, 07:52

Ok, I figured it out. I had been storing the address to the string correctly but was neglecting to use StrGet to retrieve the actual string stored at that address after retrieving the item's lParam.

EDIT:
So in my instance, I am populating the ListView using an Object containing support ticket information. Is there a way to store the address of a particular field in that object? Unforunately, I used a temp variable for storing the GUID and then assigning the address of that temp variable to the lParam so it get's overwritten for each row that is added. The below didn't work

Code: Select all

for ticket in oIMTickets[queue] {
	currTicket := oIMTickets[queue][ticket]
	currRow := LV_Add("", currTicket["processid"], currTicket["incidentname"])
	LV_EX_SetItemParam(IMLV_LView, currRow, &currTicket["sessionid"])
	LV_EX_SetGroup(IMLV_LView, currRow, groupNum)
}
just me
Posts: 9406
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [LIB] LV_EX - update on 2016-04-28

08 Mar 2017, 10:25

Code: Select all

	LV_EX_SetItemParam(IMLV_LView, currRow, currTicket.GetAddress("sessionid"))
?
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: [LIB] LV_EX - update on 2016-04-28

08 Mar 2017, 12:48

Ah, I was looking at the documentation and only looked at Objects. Didn't realize the subitems had their own pages. Thanks!
Dravenizer
Posts: 3
Joined: 08 Apr 2017, 19:03

Re: [LIB] LV_EX - update on 2016-04-28

19 Jun 2017, 05:01

Hello! I have a listview like this one:
Col1|Col2
1234|AAA
9655|CCC
2564|AAA
4456|BBB
4556|AAA
7889|CCC
I would liek to group them by all distinct values in col2, like this: (note i want to display the full value as group header - AAA, not just alphabeticly - A )
Col1|Col2
AAA-------------
1234|AAA
2564|AAA
4556|AAA
BBB--------------
4456|BBB
CCC-------------
9655|CCC
7889|CCC
I only saw examples of grouping by row number and not by values. Can you point me to the right approach? I am guessing i should have a mechanism that loops trough the given column, extracts all distinct values and then check if which cell belongs to which value and group accordingly? Btw a function that accepts column number as parameter and automaticly clears all groupings,and then groups the listview by all values inside a column sounds super awesome and useful.
Thanks for sharing the amazing work !
just me
Posts: 9406
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [LIB] LV_EX - update on 2016-04-28

19 Jun 2017, 06:00

You cannot assign a row to a group 'by value'. You might pull the values you want to use as group headers from the contents, add the groups, and assign the related rows by row number.
DanielToward13
Posts: 74
Joined: 18 May 2017, 10:56

Re: [LIB] LV_EX - update on 2016-04-28

05 Dec 2017, 21:57

Can you give an example of LV_EX_FindString function? I could not figure out how to use it to filter the rows. Also how to update the data after adding new rows?
just me
Posts: 9406
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [LIB] LV_EX - update on 2016-04-28

06 Dec 2017, 03:51

Code: Select all

; ======================================================================================================================
; LV_EX_FindString - Searches the first column for an item containing the specified string.
; ======================================================================================================================
LV_EX_FindString(HLV, Str, Start := 0, Partial := False) {
   ; LVM_FINDITEM -> http://msdn.microsoft.com/en-us/library/bb774903(v=vs.85).aspx
   Static LVM_FINDITEM := A_IsUnicode ? 0x1053 : 0x100D ; LVM_FINDITEMW : LVM_FINDITEMA
   Static LVFISize := 40
   VarSetCapacity(LVFI, LVFISize, 0) ; LVFINDINFO
   Flags := 0x0002 ; LVFI_STRING
   If (Partial)
      Flags |= 0x0008 ; LVFI_PARTIAL
   NumPut(Flags, LVFI, 0, "UInt")
   NumPut(&Str,  LVFI, A_PtrSize, "Ptr")
   SendMessage, % LVM_FINDITEM, % (Start - 1), % &LVFI, , % "ahk_id " . HLV
   Return (ErrorLevel > 0x7FFFFFFF ? 0 : ErrorLevel + 1)
}
Parameters:
  • Str
    The string to search for.
  • Start
    The number of the row to begin the search with or 0 to start from the beginning. The specified row is itself excluded from the search.
  • Partial
    If False (default), the function searches for an exact match. Otherwise, the function will check if the item text begins with the string to return a match.
Return values:
  • Returns the number of the row if a match was found, or 0 otherwise.
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: [LIB] LV_EX - update on 2016-04-28

25 Sep 2019, 12:41

I want to keep the column positions in a file, but I failed to back up and reread the string.

I got it.
User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: [LIB] LV_EX - update on 2016-04-28

06 Feb 2020, 07:30

Is it possible to set the text of an item or subItem with this library? I've looked over the code and docs several times and it doesn't seem like that functionality is included.

The closest function seems to be LV_EX_SetItemParam() ... I'm reading over the MS Docs page now (and have read up on the LVITEM structure quite a bit recently), and I'm not entirely sure how to make use of the LV_EX_SetItemParam() function.

Do I need to define my own LVITEM structure and pass it as a parameter?

Even though LV_EX_LVITEM() is an internal function, could/should I use it for this purpose?

My intent is to edit a list view directly without activating the GUI first. I'm designing some functions for a scrip that would potentially be switching between GUIs very quickly for an extended period of time, and I"m concerned that user interaction might disrupt the intent of the script, but I want to allow this kind of multi-tasking.
========================================
After reading up a bit more on AHK2, it looks like AHKv2 does this natively ... I've just found a reason to convert all my scripts (...now) :headwall: .... this is gonna hurt...
just me
Posts: 9406
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [LIB] LV_EX - update on 2016-04-28

06 Feb 2020, 08:31

This lib was designed to add some functionality to the existing LV_...() functions. Setting the text of items/subitems is built-in: LV_Modify().
User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: [LIB] LV_EX - update on 2016-04-28

06 Feb 2020, 08:47

just me wrote:
06 Feb 2020, 08:31
This lib was designed to add some functionality to the existing LV_...() functions. Setting the text of items/subitems is built-in: LV_Modify().
Right, but there's no way around using Gui, ListView, MyListView though right?

No way to use LV_ functions on control handle?
just me
Posts: 9406
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [LIB] LV_EX - update on 2016-04-28

06 Feb 2020, 11:52

Right and of course there is. Wait a moment, please.
just me
Posts: 9406
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [LIB] LV_EX - update on 2016-04-28

06 Feb 2020, 13:20

This might do it:

Code: Select all

; ======================================================================================================================
; LV_EX_SetText - Sets the text of the given item or subitem.
; Caution! No error checking!
; ======================================================================================================================
LV_EX_SetText(HLV, Text, Row, Column := 1) {
   ; LVM_SETITEMTEXTA = 0x102E, LVM_SETITEMTEXTW = 0x1074
   Static LVM_SETITEMTEXT := A_IsUnicode ? 0x1074 : 0x102E
   Static OffText := 16 + A_PtrSize
   LV_EX_LVITEM(LVITEM, 0, Row, Column)
   NumPut(&Text, LVITEM, OffText, "UPtr") ; <<<<< changed "Int" to "UPtr"
   Return DllCall("SendMessage", "Ptr", HLV, "UInt", LVM_SETITEMTEXT, "Ptr", Row - 1, "Ptr", &LVITEM, "UInt")
}
; ======================================================================================================================
; ======================================================================================================================
; Function for internal use ============================================================================================
; ======================================================================================================================
; ======================================================================================================================
LV_EX_LVITEM(ByRef LVITEM, Mask := 0, Row := 1, Col := 1) {
   Static LVITEMSize := 48 + (A_PtrSize * 3)
   VarSetCapacity(LVITEM, LVITEMSize, 0)
   NumPut(Mask, LVITEM, 0, "UInt"), NumPut(Row - 1, LVITEM, 4, "Int"), NumPut(Col - 1, LVITEM, 8, "Int")
}
Last edited by just me on 07 Feb 2020, 04:52, edited 1 time in total.
User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: [LIB] LV_EX - update on 2016-04-28

06 Feb 2020, 13:28

@just me, sir,

you are amazing!

EDIT: I was actually looking at the LVITEM structure and about to try and write that function (but of course not as fast!) ... thanks again!
just me
Posts: 9406
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [LIB] LV_EX - update on 2016-04-28

07 Feb 2020, 04:54

@TheArkive, had to fix the type for NumPut(), sorry.
User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: [LIB] LV_EX - update on 2016-04-28

07 Feb 2020, 05:54

@just me no worries ;) ... I'm not in a hurry
rakesha002
Posts: 46
Joined: 04 Dec 2017, 00:11

Re: [LIB] LV_EX - update on 2016-04-28

03 Dec 2020, 00:27

just me wrote:
06 Feb 2020, 13:20
This might do it:

Code: Select all

; ======================================================================================================================
; LV_EX_SetText - Sets the text of the given item or subitem.
; Caution! No error checking!
; ======================================================================================================================
LV_EX_SetText(HLV, Text, Row, Column := 1) {
   ; LVM_SETITEMTEXTA = 0x102E, LVM_SETITEMTEXTW = 0x1074
   Static LVM_SETITEMTEXT := A_IsUnicode ? 0x1074 : 0x102E
   Static OffText := 16 + A_PtrSize
   LV_EX_LVITEM(LVITEM, 0, Row, Column)
   NumPut(&Text, LVITEM, OffText, "UPtr") ; <<<<< changed "Int" to "UPtr"
   Return DllCall("SendMessage", "Ptr", HLV, "UInt", LVM_SETITEMTEXT, "Ptr", Row - 1, "Ptr", &LVITEM, "UInt")
}
; ======================================================================================================================
; ======================================================================================================================
; Function for internal use ============================================================================================
; ======================================================================================================================
; ======================================================================================================================
LV_EX_LVITEM(ByRef LVITEM, Mask := 0, Row := 1, Col := 1) {
   Static LVITEMSize := 48 + (A_PtrSize * 3)
   VarSetCapacity(LVITEM, LVITEMSize, 0)
   NumPut(Mask, LVITEM, 0, "UInt"), NumPut(Row - 1, LVITEM, 4, "Int"), NumPut(Col - 1, LVITEM, 8, "Int")
}
Hello,

i'm using autohotkey for everything in Windows PC now a days, but still not as good as you guys, i still consider my self a noob
i know this is an old thread, but instead of raising a new one i thought ill ask here, thanks in advance
(win 7 sp0, Ahk_L 1.1.33.02)

I need LV_EX_SetText and LV_EX_GetItemParam these functions,
both doesn't seems to work for me, while using these two functions (debugging),
1.many times LV_EX_GetItemParam returns 0, but one time it returns 1.
2.many times LV_EX_SetText returns 0, but one time it actually sets listview with a blank value.
3. some times the gui (which is another process) is crashing with below error,
"
Critical Error: Invalid memory read/write.

Line#
360: LV_SortArrow(MLVh, A_EventInfo, SortOr)
361: if (A_EventInfo = 3)
362: SortOrder(SortOrder)
363: }
364: if (A_GuiEvent == "A" || A_GuiEvent == "DoubleClick")
364: {
365: Gosub,Explore
---> 366: Return
367: }
368: Return
371: if (A_GuiEvent = "Normal")
371: {
372: TV_GetText(SelectedItemText, A_EventInfo)
373: if (SelectedItemText = "Copy Path")
373: {

The program is now unstable and will exit.
"

Code: Select all

#Include <LV_EX>
ControlGet, JLVHwnd, Hwnd,, SysListView321, Explorer ahk_class AutoHotkeyGUI
a := LV_EX_GetItemParam(JLVHwnd, 2)
a1 := LV_EX_SetText(JLVHwnd, "Text", 2, 2)
ListVars
windows are visible not hidden, and i tried creating a simple gui, but same things happens
just me
Posts: 9406
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [LIB] LV_EX - update on 2016-04-28

03 Dec 2020, 04:16

3. some times the gui (which is another process) ...
LV_EX functions are not designed to work with controls in other processes. All functions using structures like LVITEM need to allocate memory in the address space of the other process to work properly.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 88 guests