Jump to content

_GUICtrlListView_AddArray won't work with imagelist bitmap

Recommended Posts

Hi everyone again!

I have a problem I just can't find the solution of :(

Context: I've made a program that goes into chrome and captures one table as an array and adds it to the gui, all good so far.

The problem comes when i'm trying to use the table items background color as a bitmap in the listview. (doens't need to be this way but it seemed the easiest way to me).

As I use the function '_GUICtrlListView_AddArray' to add the table to the gui, when I try to put the little colored squares it just put them all with the first color in the array BUT if I use '_GUICtrlListView_AddItem' function it works alternating the colors just fine. Idk if I'm doing something wrong or it just wont work this way.


Thanks in advance and sorry for my noobness :( 

;~ #include <array.au3> (already included in guilistview)
#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
;~ #include <GuiListBox.au3>
;~ #include <WindowsConstants.au3>
#include <GuiImageList.au3>

Global $array_table[10][6] = _
[['asd00','asd10','asd20','asd30','asd40','asd50'] _
,['asd01','asd11','asd21','asd31','asd41','asd51'] _
,['asd02','asd12','asd22','asd32','asd42','asd52'] _
,['asd03','asd13','asd23','asd33','asd43','asd53'] _
,['asd04','asd14','asd24','asd34','asd44','asd54'] _
,['asd05','asd15','asd25','asd35','asd45','asd55'] _
,['asd06','asd16','asd26','asd36','asd46','asd56'] _
,['asd07','asd17','asd27','asd37','asd47','asd57'] _
,['asd08','asd18','asd28','asd38','asd48','asd58'] _

#Region Gui
Global $gui = GUICreate("color", 1320, 720, @DesktopWidth / 9, @DesktopHeight / 6, -1)
Global $boton_go = GUICtrlCreateButton("Go", 10, 510, 75, 25)
Global $idButton_Salir = GUICtrlCreateButton("Salir", 10, 600, 75, 25)

Global $idListview = GUICtrlCreateListView(" Hub  | Equipo  | Comentario Interfaz |     Alarma | Tiempo | Grafico", 10, 10, 1300, 490, -1, $LVS_EX_FULLROWSELECT)     ;$LVS_EX_GRIDLINES ,$LVS_SORTDESCENDING)  Hub  | Equipo  | Comentario Interfaz | Alarma | Tiempo | Grafico

#EndRegion Gui

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
        Case $idButton_Salir
        Case $boton_go

Func GOOO()

$hImage = _GUIImageList_Create()

Local $array_colore[10] = ["0xFF9B9B", "0xFF9B9B", "0x74DC96","0xFF9B9B", "0x74DC96", "0x74DC96","0xFF9B9B", "0x74DC96", "0x74DC96","0xFF9B9B"]


    For $i = 0 To UBound($array_colore)-1
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($idListview), $array_colore[$i], 16, 16))

_GUICtrlListView_SetImageList($idListview, $hImage, 1)

    _GUICtrlListView_AddArray($idListview, $array_table) ;--------####### doesn't work

    ; Add items                                         ;------##### does work
;~     _GUICtrlListView_AddItem($idListview, "Item 1", 0)
;~     _GUICtrlListView_AddItem($idListview, "Item 2", 1)
;~     _GUICtrlListView_AddItem($idListview, "Item 3", 2)
;~  _GUICtrlListView_AddItem($idListview, "Item 4", 3)
;~  _GUICtrlListView_AddItem($idListview, "Item 5", 4)

EndFunc   ;==>GOOO


gui color.png

Link to post
Share on other sites
17 hours ago, Nine said:

_GUICtrlListView_AddArray cannot set image list.  So you will need to use _GUICtrlListView_SetItemImage in a loop afterward to set for each item.

I've managed to make it work thanks to your help:

for $i = 0 to _GUICtrlListView_GetItemCount($idListview)
        _GUICtrlListView_SetItemImage($idListview, $i, $i)

just with that 3 lines of code... Don't know why it doesn't work in the other way.


Thanks 9


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By elsemieni
      Hey hello.
      I came here with maybe too specific questions about uncommon things, but as people says, I don't lose anything trying to asking here 
      There's long time that I have a little "experimental" idea: Use windows desktop and it icon system like old videogame consoles (where "sprites" are used to draw things on screen, can be manipulated/animated to make interesting things happen). Some of that inspiration came from another experiments from demoscene.
      Researching the possibilities of doing something like that (maybe not so intense) I found that the Windows Desktop uses a GuiListView to show and arrange icons (and of course, AutoIt provides UDF's for that  ). So, I'm used that UDF to create dummy icons (not putting files on Desktop, just modifiying the "GUI layer" of desktop for put non-working icons), setting custom values like coordinates, name and Icon (from a list of loaded icons in the GuiListView).  As you can see in next image works well in Windows XP... even in Windows 95 (that's not the case from Windows Vista to 10, but I already posted another question here about that... anyways, for now I'm working that with a isolated XP machine... sigh).

      Another video doing an animation with that:
      How I make that custom icons? Here:
      $hWnd = ControlGetHandle("Program Manager", "", "[CLASS:SysListView32; INSTANCE:1]") $newItem = _GUICtrlListView_AddItem ( $hWnd, "TEST", 32 ) ; with an icon of index 32 _GUICtrlListView_SetItemPosition ( $hWnd, $newItem, 300, 300 ) ; set some example property. Put in X=300 Y=300 Okay, so the next phase was changing the icons with custom ones. And here starts the issues. As AutoIT help says, icons from GuiListView came from a loaded GUIImageList, which, seeing past images I conclude that it's already preloaded with some sort of most used icons (something like an icon cache?). But If I modify it (or create another GUIImageList and then put into the GuiListView) the icons became corrupted and replaced with blank ones. (can be reverted deleting IconCache.db, just like when windows shows wrong icons in desktop).
      How I change icons? Here
      $hImage = _GUIImageList_Create(48, 48, 5) ; create an image list for 48x48 icons $newIcon = _GUIImageList_AddIcon($imageList, @SystemDir & "\shell32.dll", 110) ; just adding a new icon in the image list _GUICtrlListView_SetImageList($hWnd, $hImage, 0) ; $hwnd is the desktop hwnd Another option as workaround for setting icons was getting the desktop GUIImageList, and modifiyng it directly. I otbtain a GUIImageList handle, but ... without any images inside! (That's strange beacuse, when I set desktop item icons without altering the GUIImageList, it applies correctly). And finally if I try to add new ones, it returns -1 with @error setted.
      How I'm trying to get  desktop GUIImageList? Here.
      $imageList = _GUICtrlListView_GetImageList ( $hWnd, 0 ) MsgBox(0,_GUIImageList_GetImageCount ( $imageList ), $imageList) ; getting image count and GUIImageList handle $newIcon = _GUIImageList_AddIcon($imageList, @SystemDir & "\shell32.dll", 110) ; adding icons without success So, what is the question? There's something wrong I'm doing while trying to set the new icon set on desktop? Or desktop icons work in different way than the rest of the GuiListView's? Or there's something really stupid that I can't saw before that corrupts the icons? 
      Also... if there's not known solution for that, do you have some idea for doing a workaround for that? Or another crazy idea? (Maybe putting real files instead dummy icons could be a solution ... a very slow one). Or even maybe (maybe not, I sure about that xD) do you want to help with this "experiment".
      Thanks in advance, have a good day  
    • By PINTO1927
      Hello guys, I'm working on this script:
      $search = GUICtrlCreateButton("Search", 10, 10, 90, 30) $find = GUICtrlCreateInput("", 710, 10, 200, 25) GUICtrlSetState($find, $GUI_DISABLE) $ok_find = GUICtrlCreateButton("Find", 925, 10, 65, 25) GUICtrlSetState($ok_find, $GUI_DISABLE)  
      Case $search GUICtrlSetState($ok_trova, $GUI_ENABLE) GUICtrlSetState($trova, $GUI_ENABLE) _GUICtrlListView_SimpleSort($list, $g_bSortSense, 0, False) _GUICtrlListView_DeleteAllItems($list) $File_txt = _FileListToArray("\\PATH\", "*.ini", $FLTA_FILES, True) Local $aLines, $File_txt For $i = 1 To $File_txt[0] _FileReadtoArray($File_txt[$i], $aLines) For $j = 1 To $aLines[0] GUICtrlCreateListViewItem($aLines[$j], $list) Next Next For $i2 = 0 To _GUICtrlListView_GetColumnCount($list) _GUICtrlListView_SetColumnWidth($list, $i2, $LVSCW_AUTOSIZE_USEHEADER) Next Case $ok_find $iI = _GUICtrlListView_FindInText($list, GUICtrlRead($input_find)) MsgBox($MB_SYSTEMMODAL, "Information", "Target Item Index: " & $iI) _GUICtrlListView_EnsureVisible($list, $iI) through a inputbox I would search for the desired word and highlight it in the GuiCtrlListView.
      Can you help me?
    • By Fossil Rock
      I'm having a little difficulty getting beyond this error with the script below:

      C:\.....\Include\GuiListView.au3 (543) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: DllStructSetData($tBuffer, "Text", $aItems[$iI][0]) DllStructSetData($tBuffer, "Text", ^ ERROR
      Can someone point me in the right direction? Sample Lua script in spoiler.

      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <WindowsConstants.au3> #include <String.au3> #include <Array.au3> #include <File.au3> #include <GuiListView.au3> ;Opt('GuiOnEventMode', 1) ; prevents application from exiting ?? $Form1_1 = GUICreate("Script Parser", 1001, 801, -1, -1) $Button1 = GUICtrlCreateButton("Open File", 16, 24, 91, 25) $Button2 = GUICtrlCreateButton("Parse File", 125, 24, 91, 25) $Button3 = GUICtrlCreateButton("{undefined}", 234, 24, 91, 25) $Button4 = GUICtrlCreateButton("{undefined}", 343, 24, 91, 25) $Button5 = GUICtrlCreateButton("{undefined}", 452, 24, 91, 25) $Button6 = GUICtrlCreateButton("{undefined}", 561, 24, 91, 25) $Button7 = GUICtrlCreateButton("{undefined}", 670, 24, 91, 25) $Button8 = GUICtrlCreateButton("Save Output", 779, 24, 91, 25) $Button9 = GUICtrlCreateButton("Exit", 888, 24, 91, 25) $List1 = GUICtrlCreateList("", 8, 128, 177, 564, -1, $WS_EX_STATICEDGE) GUICtrlSetData(-1, "") GUICtrlSetFont(-1, 10, 400, 0, "Courier New") $Edit1 = GUICtrlCreateEdit("", 200, 128, 793, 633, -1, $WS_EX_STATICEDGE) GUICtrlSetData(-1, "") GUICtrlSetFont(-1, 10, 400, 0, "Courier New") $Label1 = GUICtrlCreateLabel("{empty}", 10, 700, 200, 27) GUICtrlSetFont(-1, 14, 400, 0, "Calibri") GUISetState(@SW_SHOW) GetFunctions() ; Assign to button 2 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func OpenFile() EndFunc Func GetFunctions() Local $aFileName = FileOpenDialog("Select a file", @ScriptDir & "\", "(*.lua)", 0) Local $aArray = FileRead($aFileName) Local $aFunctions = _StringBetween($aArray, "Function ", "(") _ArrayDisplay($aFunctions) _GUICtrlListView_AddArray($List1,$aFunctions) ; ERROR EndFunc Func _ListViewEvent() For $i = 0 To $List1[0] If @GUI_CtrlId = $List1[$i] Then ExitLoop Next GUICtrlSetData($Label1, GUICtrlRead($List1[$i])) EndFunc Func _Exit() Exit EndFunc

    • By Andon
      Is it possible to set the background color of the chcecked (not selected) item (_GUICtrlListView, $LVS_EX_CHECKBOXES) ?
  • Create New...