-
-
Save DavidBevi/024ccbaeaa5c1f7494e46b0fd18de4c4 to your computer and use it in GitHub Desktop.
ListView: Icons in more than first column example #ahkv2 #function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ; This is the short version, refer to the one in LV_SetImageToAnyCol_Demo.ahk | |
| ; for the extended version (better documentation, same function) | |
| ;FUNCTION-DEFINITION-----------------------------------------------------------------; | |
| /** | |
| * @example LV_SetImageToAnyCol(MyListView, 1, 2, 3) ;Row 1, Col 2, Img 3 | |
| * @important Requires `+LV0x2` style applied to the ListView. | |
| * @tip Use either the ListView (`Gui.Control`) or its HWND (`Integer`). | |
| * | |
| * => On success returns `1`, otherwise `0`. | |
| */ | |
| LV_SetImageToAnyCol(LV, Row, Col, Img) { | |
| Img_Attributes := Buffer(60, 0) | |
| For el in [[0x2, 0], [Row-1, 4], [Col-1, 8], [Img-1, 36]] | |
| NumPut("Int", el[1], Img_Attributes, el[2]) | |
| Return DllCall("SendMessageA", "Ptr",Type(LV)="Integer"?LV:LV.Hwnd, | |
| "Int",0x1006, "Int",0, "Ptr",Img_Attributes) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;CREDITS----------------------------------------------------------------------------------; | |
| ; This is a port of LV_SetSI.ahk by hoppfrosch https://gist.github.com/hoppfrosch/11242617 | |
| ; The original code is for AHKv1, this is for AHKv2, therefore I recommend including... | |
| #Requires AutoHotkey v2 ; ...in your script, if you want to share it. | |
| ;FUNCTION-DEFINITION----------------------------------------------------------------------; | |
| /** | |
| * @description | |
| * Sets any image in your ImageList in any column of your ListView | |
| * (requires `+LV0x2` style applied to the ListView). | |
| * @example LV_SetImageToAnyCol(MyListView, 1, 2, 3) ;row 1, col 2, img 3 | |
| * @param {(Gui.Control or Integer)} control -The ListView you want to edit, or its HWND. | |
| * @param {(Integer)} row | |
| * @param {(Integer)} column | |
| * @param {(Integer)} img_index - The index of the image in the ImageList. | |
| * @return {(Integer)} - On success returns `1`, otherwise `0`. | |
| */ | |
| LV_SetImageToAnyCol(control, row, column, img_index) { | |
| ; (1) Pack img_attributes in a Buffer | |
| img_attributes := Buffer(60, 0) | |
| For el in [[0x2,0], [row-1,4], [column-1,8], [img_index-1,36]] { | |
| NumPut("Int", el[1], img_attributes, el[2]) | |
| } | |
| ; (2) Send img_attributes to ListView | |
| Return DllCall("SendMessageA", ; Different from "SendMessage" | |
| "Ptr", Type(control)="Integer"? control: control.Hwnd, ; HWND of the target ListView | |
| "Int", 0x1006, ; =LVM_SETITEM =Message code for setting an item in the ListView | |
| "Int", 0, ; Must be 0 | |
| "Ptr", img_attributes ; Pointer to a Buffer with img_attributes | |
| ) | |
| } | |
| ;DEMO------------------------------------------------------------------------------------; | |
| ; Create the GUI | |
| DemoGui:= Gui("+Resize -DPIScale","Test") | |
| ; | |
| ; Create the ListView | |
| DemoListView := DemoGui.Add("ListView", "w400 h500 +LV0x2", ["Item","Icon with label","Icon 2 without label"]) | |
| ; | |
| ; Create the ImageList, fill it with 100 icons | |
| DemoImageList := IL_Create(100) | |
| Loop 100 { | |
| IL_Add(DemoImageList, "shell32.dll", A_Index) | |
| } | |
| ; | |
| ; Associate the ImageList to the ListView | |
| DemoListView.SetImageList(DemoImageList, 1) | |
| ; | |
| ; Add 20 elements to the ListView | |
| Loop 20 { | |
| DemoListView.Add("Icon" A_Index, "Example " A_Index, "Label") | |
| LV_SetImageToAnyCol(DemoListView, A_Index, 2, A_Index+20) | |
| LV_SetImageToAnyCol(DemoListView, A_Index, 3, A_Index+40) | |
| } | |
| ; | |
| ; [Optional] Enlarge columns | |
| Loop 3 { | |
| DemoListView.ModifyCol(A_Index,120) | |
| } | |
| ; | |
| ; Show GUI | |
| DemoGui.Show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
many thanks, idk why AHK don't add more function for Gui system lmao almost coding more become waste of time once you want more.