[listview_library] V1 → AHK_H V2 Topic is solved

Ask for help, how to use AHK_H, etc.
lsh
Posts: 10
Joined: 14 Sep 2017, 07:02

[listview_library] V1 → AHK_H V2

26 Nov 2017, 06:29

I try to change it from v1 to AHK_H v2.
But, I don't get a good result.
How do I get LVM_Insert, LVM_Modify, LVM_GetText, and LVM_GetColOrder to achieve accurate results?

Code: Select all

#singleinstance force
#Persistent
Gui := GuiCreate()
Lv := Gui.Add("ListView", "x5 y12 r10 w200 grid  NoSortHdr", "a|b")
hLv := Lv.Hwnd
Gui.Show("xCenter yCenter w215 h250")
Gui.OnEvent("Close", "Gui_Close")
loop 5
Lv.Add(,A_Index,"a" A_Index)
LVM_Insert(hLV, 1,1,0,,"a","b")
LVM_Modify(hLV,1,1,0,,A_Sec,"modify!!")
LVM_Delete(hLV,3)

MsgBox(LVM_GetText(hLV,1,1))
MsgBox(LVM_GetColOrder(hLV))
return

EXIT:
Gui.Destroy()
ExitApp()
return

Gui_Close()
{
    gosub("EXIT")
}

LVM_Insert(hLV, row:=0, col:=1, options:=0, f*) {
	col := col!=0 ? col-1 : 0
	row := row ? row-1 : DllCall("SendMessage", "uint", hLV, "uint", 4100, "uint", 0, "uint", 0)
	VarSetCapacity(lvItem, A_PtrSize * 6, 0)
	NumPut(9      , lvItem, A_PtrSize * 0 "uint")   ; mask
	NumPut(row    , lvItem, A_PtrSize * 1, "int") 	; iItem
	NumPut(options, lvItem, A_PtrSize * 3, "uint")  ; state
	NumPut(1      , lvItem, A_PtrSize * 4, "uint")  ; stateMask
	DllCall("SendMessage", "uint", hLV, "uint", 4103, "uint", 0, "uint", &lvItem) ; LVM_INSERTITEM
	For index,field in f
		{
		NumPut(col + A_Index - 1, lvItem, A_PtrSize * 2, "int") ; iSubItem
		NumPut(&field           , lvItem, A_PtrSize * 5, "ptr") ; pszText
		DllCall("SendMessage", "uint", hLV, "uint", A_IsUnicode ? 4172 : 4171, "uint", 0, "ptr", &lvItem) ; LVM_SETITEMW
		}
	}

LVM_Modify(hLV, row, col:=1, o:=0, f*) {
	col -= 1 ; convert to 0 based index
	VarSetCapacity(lvItem, A_PtrSize * 6, 0)
	NumPut(9, lvItem, "uint")   ; mask
	NumPut(row-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(col + A_Index - 1, lvItem, A_PtrSize * 2, "int") ; iSubItem
		NumPut(&field, lvItem, A_PtrSize * 5, "ptr") ; pszText
		DllCall("SendMessage", "uint", hLV, "uint", A_IsUnicode ? 4172 : 4171, "uint", 0, "ptr", &lvItem) ; LVM_SETITEMW
		}
	}

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

LVM_SetColOrder(hLV, col) {
    col := StrSplit(col, ",")
	VarSetCapacity(col, c0 * A_PtrSize)
	Loop c0
		NumPut(col%A_Index% - 1, col, (A_Index - 1) * A_PtrSize)
	Return DllCall("SendMessage", "uint", hLV, "uint", 4154, "uint", c0, "ptr", &c) ; LVM_SETCOLUMNORDERARRAY
	}


LVM_GetText(hLV, row, col:=1) {
	row -= 1 	; convert to 0 based index
	VarSetCapacity(t, 511, 1)
	VarSetCapacity(lvItem, A_PtrSize * 7)
	NumPut(1    , lvItem, A_PtrSize * 0 "uint") ; mask
	NumPut(row  , lvItem, A_PtrSize * 1, "int") ; iItem
	NumPut(col-1, lvItem, A_PtrSize * 2, "int") ; iSubItem
	NumPut(&t   , lvItem, A_PtrSize * 5, "ptr") ; pszText
	NumPut(512  , lvItem, A_PtrSize * 6)        ; cchTextMax
	DllCall("SendMessage", "uint", hLV, "uint", A_IsUnicode ? 4211 : 4141, "uint", row, "ptr", &lvItem) ;LVM_GETITEMTEXTW : LVM_GETITEMTEXTA
	Return t
	}

LVM_Delete(hLV, row:=0) {
	row!=0 ? DllCall("SendMessage", "uint", hLV, "uint", 4104, "uint", row-1, "uint", 0) : DllCall("SendMessage", "uint", hLV, "uint", 4105, "uint", 0, "uint", 0) ; LVM_DELETEITEM : LVM_DELETEALLITEMS
	}
HotKeyIt
Posts: 1713
Joined: 29 Sep 2013, 18:35
Contact:

Re: [listview_library] V1 → AHK_H V2  Topic is solved

26 Nov 2017, 07:24

Here you go. Try always to use Struct, makes things much easier ;)

Code: Select all

#singleinstance force
#Persistent
global _LVITEM:="
(Q
  UINT   mask;
  int    iItem;
  int    iSubItem;
  UINT   state;
  UINT   stateMask;
  LPTSTR pszText;
  int    cchTextMax;
  int    iImage;
  LPARAM lParam;
  int    iIndent;
" ((SubStr(A_OsVersion,1,InStr(A_OsVersion,".",1,1,2)-1)>5.1)?"int    iGroupId;
  UINT   cColumns;
  PUINT  puColumns;":"") "
" ((SubStr(A_OsVersion,1,InStr(A_OsVersion,".",1,1,2)-1)>6.0)?"int    *piColFmt;
  int    iGroup;":"") "
)"
Gui := GuiCreate()
Lv := Gui.Add("ListView", "x5 y12 r10 w200 grid  NoSortHdr", "a|b")
hLv := Lv.Hwnd
Gui.Show("xCenter yCenter w215 h250")
Gui.OnEvent("Close", "Gui_Close")
loop 5
  Lv.Add(,A_Index,"a" A_Index)
LVM_Insert(hLV, 1,1,0,,"a","b")
LVM_Modify(hLV,1,1,0,,A_Sec,"modify!!")
LVM_Delete(hLV,3)

MsgBox(LVM_GetText(hLV,1,1))
MsgBox(LVM_GetColOrder(hLV))
return

EXIT:
Gui.Destroy()
ExitApp
return

Gui_Close()
{
    gosub("EXIT")
}

LVM_Insert(hLV, row:=0, col:=1, options:=0, f*) {
	col := col!=0 ? col-1 : 0
	row := row ? row-1 : SendMessage_(hLV, 4100)
    lvItem:=Struct(_LVITEM,{mask:9,iItem:row,state:options,stateMask:1})
	SendMessage_(hLV, 4103, 0, lvItem[]) ; LVM_INSERTITEM
	For index,field in f {
          lvItem.iSubItem:= col + A_Index -1
          lvItem.pszText[""]:=&(field "")
          SendMessage_(hLV, 4172, 0, lvItem[]) ; LVM_SETITEMW
		}
	}

LVM_Modify(hLV, row, col:=1, o:=0, f*) {
	col -= 1 ; convert to 0 based index
	lvItem:=Struct(_LVITEM,{mask:9,iItem:row-1,state:o,stateMask:1})
	For index,field in f {
          lvItem.iSubItem:= col + A_Index -1
          lvItem.pszText[""]:=&(field "")
          SendMessage_(hLV, 4172, 0, lvItem[]) ; LVM_SETITEMW
		}
	}

LVM_GetColOrder(hLV) {
	hdrH := SendMessage_(hLV, 4127) ; LVM_GETHEADER
	hdrC := SendMessage_(hdrH, 4608) ; HDM_GETITEMCOUNT
	VarSetCapacity(o, hdrC * A_PtrSize)
	SendMessage_(hLV, 4155, hdrC, &o) ; LVM_GETCOLUMNORDERARRAY
	Loop hdrC
		result .= NumGet(&o, (A_Index - 1) * A_PtrSize) + 1 . ","
	result := SubStr(result, 1, -1*(1))
	Return result
	}

LVM_SetColOrder(hLV, col) {
    col := StrSplit(col, ",")
	VarSetCapacity(col, c0 * A_PtrSize)
	Loop c0
		NumPut(col%A_Index% - 1, col, (A_Index - 1) * A_PtrSize)
	Return SendMessage_(hLV, 4154, c0, &c) ; LVM_SETCOLUMNORDERARRAY
	}


LVM_GetText(hLV, row, col:=1) {
    lvItem:=Struct(_LVITEM,{mask:1,iSubItem:col-1,cchTextMax:512})
    lvItem.SetCapacity("pszText",1026)
	SendMessage_(hLV, 4211, 0, lvItem[]) ;LVM_GETITEMTEXTW : LVM_GETITEMTEXTA
	Return lvItem.pszText
	}

LVM_Delete(hLV, row:=0) {
	return row!=0 ? SendMessage_(hLV, 4104, row-1) : SendMessage_(hLV, 4105) ; LVM_DELETEITEM : LVM_DELETEALLITEMS
	}
EDIT:
Fixed LVM_GetText
EDIT2:
Changed to use SetCapacity on pszText instead of using a Variable.
EDIT3:
Fixed to convert digits to text when inserting or modifying data
lsh
Posts: 10
Joined: 14 Sep 2017, 07:02

Re: [listview_library] V1 → AHK_H V2

26 Nov 2017, 10:28

The result of "MsgBox(LVM_GetText(hLV,1,1))" should be "A_Sec",
but "āāāāāāāāāāāāāāāāā" comes out. Can I get the result of "A_Sec"?
lsh
Posts: 10
Joined: 14 Sep 2017, 07:02

Re: [listview_library] V1 → AHK_H V2

05 Dec 2017, 23:49

loop 10
LVM_Insert(hLv,1,1,0,,,a_index,a_index)
------------------------------------------------------------------------------------------------------------------------
When adding 'a_index' to the listview,
Additional text appears to be broken.
Is there any way we can solve it?
------------------------------------------------------------------------------------------------------------------------
Test on : win10 x64
Ahk ver : 2.0-a081-H019

Return to “Ask For Help”

Who is online

Users browsing this forum: No registered users and 3 guests