Get Icon Attributes

Get help with using AutoHotkey and its commands and hotkeys
Posts: 669
Joined: 21 Dec 2015, 02:34

Get Icon Attributes

09 Nov 2019, 14:42

Hello, when clicking on a listview item it shows the line's text and its icon index.

I'm hoping to find a way to identify the icon (in other words, when clicking on the listview item, it will also show the icon's name, or some other way to identify exactly what icon it is) - the icon index doesn't appear to be what is needed here:

Code: Select all

Gui, Add, ListView, AltSubmit gMyListView h200 w180 , Icon & Number|Description  ; Create a ListView.
ImageListID := IL_Create(10)  ; Create an ImageList to hold 10 small icons.
LV_SetImageList(ImageListID)  ; Assign the above ImageList to the current ListView.
Loop 10  ; Load the ImageList with a series of icons from the DLL.
	IL_Add(ImageListID, "shell32.dll", A_Index)  ; Omit DLL's path so that it works on all OSes.
Loop 10  ; Add rows to the ListView (for demonstration purposes, one for each icon).
	LV_Add("Icon" . A_Index, A_Index, "n/a")
LV_ModifyCol("Hdr")  ; Auto-adjust the column widths.
Gui Show

GuiClose:  ; Exit the script when the user closes the ListView's GUI window.

    If (A_GuiEvent == "Normal") {
        LV_GetText(RowText1, A_EventInfo, 1)
        LV_GetText(RowText2, A_EventInfo, 2)

        Icon := LV_GetIconIndex(hLVItems, A_EventInfo)

        Gui +OwnDialogs
        MsgBox 0x40, LV Item, First column text:  "%RowText1%"`nImage list icon index:  %Icon%

LV_GetIconIndex(hLV, Row) {
    VarSetCapacity(LVITEM, A_PtrSize == 8 ? 88 : 60, 0)
    NumPut(0x2, LVITEM, 0, "UInt") ; mask (LVIF_IMAGE)
    NumPut(Row - 1, LVITEM, 4, "Int") ; iItem
    SendMessage 0x104B, 0, &LVITEM,, ahk_id %hLV% ; LVM_GETITEMW
    Return ErrorLevel != "FAIL" ? NumGet(LVITEM, A_PtrSize == 8 ? 36 : 28, "Int") + 1 : 0

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot], RubbeH, whats_up and 33 guests