Sunblood Posted September 30 Share Posted September 30 I am trying to create a ComboBoxEx using icons converted from jpg files on the fly. I can get the icons to show up successfully but when I interact with the dropdown the icons will randomly disappear. Icons do not ever stay once selected, and sometimes they do a strange fade-out animation that looks intentional but I can't figure out why this would be happening. Gif of the issue here (Hello to my fellow Helldivers!) Code here, also attached as a zip with included jpg files ImageList is built on line 61 and ComboBoxEx is populated on line 111 expandcollapse popup#include <GDIPlus.au3> #include <Array.au3> #include <GuiComboBoxEx.au3> #include <GUIConstants.au3> #include <GuiImageList.au3> #include <ComboConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Dim $requiredFiles[] = ["stratagems.ini"] For $i = 0 To UBound($requiredFiles) - 1 If Not FileExists($requiredFiles[$i]) Then MsgBox(0, "Missing file", "Unable to find " & $requiredFiles[$i]) Exit EndIf Next ConsoleWrite("Starting GDIPlus" & @CRLF) _GDIPlus_Startup() HotKeySet("^!d", "Debug") Global Const $iniStratagems = "stratagems.ini" Global Const $iniSettings = "settings.ini" Global Const $nullChar = "[unassigned]" ConsoleWrite("Building GUI" & @CRLF) Enum $DATA_INDEX, $DATA_PICCTRL, $DATA_STRATCTRL, $DATA_BUTTONMOVEUP, $DATA_BUTTONMOVEDOWN, $DATA_BUTTONCLEAR, $DATA_LOADOUTCHECKBOX, _ $DATA_STRATNAME, $DATA_STRATKEYS, $DATA_LOADOUTENABLED Global $dataStruct[1][20] $dataStruct[0][$DATA_INDEX] = "DATA_INDEX" $dataStruct[0][$DATA_PICCTRL] = "DATA_PICCTRL" $dataStruct[0][$DATA_STRATCTRL] = "DATA_STRATCTRL" $dataStruct[0][$DATA_BUTTONMOVEUP] = "DATA_BUTTONMOVEUP" $dataStruct[0][$DATA_BUTTONMOVEDOWN] = "DATA_BUTTONMOVEDOWN" $dataStruct[0][$DATA_BUTTONCLEAR] = "DATA_BUTTONCLEAR" $dataStruct[0][$DATA_LOADOUTCHECKBOX] = "DATA_LOADOUTCHECKBOX" $dataStruct[0][$DATA_STRATNAME] = "DATA_STRATNAME" $dataStruct[0][$DATA_STRATKEYS] = "DATA_STRATKEYS" $dataStruct[0][$DATA_LOADOUTENABLED] = "DATA_LOADOUTENABLED" $top = -56 + 8 + 16 $addY = 56 $picW = 50 $picH = 50 $COLUMN_PIC = 16 $COLUMN_STRAT = 74 $COLUMN_UPDOWN = 326 $COLUMN_LOADOUT = 428 $COLUMN_CLEAR = 450 $stratagemList = IniReadSection($iniStratagems, "Stratagems") _ArraySort($stratagemList) $initialKeys = 1 Global $guiMain = GUICreate("HD2", 490, $top + ($addY * $initialKeys) + 90) ;//Build image list here ConsoleWrite("Building strat icon imagelist" & @CRLF) $hImage = _GUIImageList_Create(32, 32) Global $iconIndex[$stratagemList[0][0]] For $i = 1 To $stratagemList[0][0] $file = StringReplace(@ScriptDir & "\icons\jpg\" & $stratagemList[$i][0] & "_Stratagem_Icon.jpg", " ", "_") If FileExists($file) Then $tempBMP = _GDIPlus_BitmapCreateFromFile($file) $tempResize = _GDIPlus_ImageResize($tempBMP,32,32) $tempHBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($tempResize) _GUIImageList_Add($hImage, $tempHBMP) _GDIPlus_BitmapDispose($tempBMP) _GDIPlus_BitmapDispose($tempResize) _WinAPI_DeleteObject($tempHBMP) $iconIndex[$i - 1] = $stratagemList[$i][0] EndIf Next ConsoleWrite("Creating and populating combo boxes"&@CRLF) For $i = 1 To $initialKeys AddEntry() Next $buttonAdd = GUICtrlCreateButton("+", $COLUMN_PIC, $top + ($i * $addY), 20, 22) $buttonDel = GUICtrlCreateButton("-", $COLUMN_PIC + 25, $top + ($i * $addY), 20, 22) $buttonSave = GUICtrlCreateButton("Apply", $COLUMN_PIC, $top + ($i * $addY + 25)) $labelStatus = GUICtrlCreateLabel(" ", $COLUMN_PIC + 40, $top + ($i * $addY + 25) + 6, 300) ResizeGui() Load() GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 GuiMessages() WEnd Func AddEntry() $index = UBound($dataStruct) _ArrayAdd($dataStruct, $index) ;Picture control $dataStruct[$index][$DATA_PICCTRL] = GUICtrlCreatePic("", $COLUMN_PIC, $top + ($index * $addY), $picW, $picH) GUICtrlSetResizing(-1, $GUI_DOCKALL) ;/// COMBOBOXEX CREATED HERE ;Stratagem name control $dataStruct[$index][$DATA_STRATCTRL] = _GUICtrlComboBoxEx_Create($guiMain, "", $COLUMN_STRAT, $top + ($index * $addY + 16),200) _GUICtrlComboBoxEx_BeginUpdate($dataStruct[$index][$DATA_STRATCTRL]) Local $int For $int = 1 To $stratagemList[0][0] _GUICtrlComboBoxEx_AddString($dataStruct[$index][$DATA_STRATCTRL], $stratagemList[$int][0],$int) Next _GUICtrlComboBoxEx_EndUpdate($dataStruct[$index][$DATA_STRATCTRL]) _GUICtrlComboBoxEx_SetImageList($dataStruct[$index][$DATA_STRATCTRL],$hImage) ;Up/Down buttons $dataStruct[$index][$DATA_BUTTONMOVEUP] = GUICtrlCreateButton("↑", $COLUMN_UPDOWN, $top + ($index * $addY + 16), 20, 22) If $index = 1 Then GUICtrlSetState(-1, $GUI_HIDE) GUICtrlSetResizing(-1, $GUI_DOCKALL) $dataStruct[$index][$DATA_BUTTONMOVEDOWN] = GUICtrlCreateButton("↓", $COLUMN_UPDOWN + 20 + 5, $top + ($index * $addY + 16), 20, 22) GUICtrlSetResizing(-1, $GUI_DOCKALL) ;Loadout checkbox $dataStruct[$index][$DATA_LOADOUTCHECKBOX] = GUICtrlCreateCheckbox(" ", $COLUMN_LOADOUT, $top + ($index * $addY + 16)) GUICtrlSetTip(-1, "Add to loadout") GUICtrlSetResizing(-1, $GUI_DOCKALL) ;Clear button $dataStruct[$index][$DATA_BUTTONCLEAR] = GUICtrlCreateButton("X", $COLUMN_CLEAR, $top + ($index * $addY + 16), 20, 22) GUICtrlSetTip(-1, "Clear entry") GUICtrlSetResizing(-1, $GUI_DOCKALL) SetUpdownVisibility() EndFunc ;==>AddEntry Func SetUpdownVisibility() Local $i For $i = 1 To UBound($dataStruct) - 1 If $i = UBound($dataStruct) - 1 Then GUICtrlSetState($dataStruct[$i][$DATA_BUTTONMOVEDOWN], $GUI_HIDE) Else GUICtrlSetState($dataStruct[$i][$DATA_BUTTONMOVEDOWN], $GUI_SHOW) EndIf Next EndFunc ;==>SetUpdownVisibility Func DeleteEntry() Local $index = UBound($dataStruct) - 1 GUICtrlDelete($dataStruct[$index][$DATA_PICCTRL]) GUICtrlDelete($dataStruct[$index][$DATA_STRATCTRL]) GUICtrlDelete($dataStruct[$index][$DATA_BUTTONMOVEUP]) GUICtrlDelete($dataStruct[$index][$DATA_BUTTONMOVEDOWN]) GUICtrlDelete($dataStruct[$index][$DATA_LOADOUTCHECKBOX]) GUICtrlDelete($dataStruct[$index][$DATA_BUTTONCLEAR]) _ArrayDelete($dataStruct, $index) SetUpdownVisibility() EndFunc ;==>DeleteEntry Func ResizeGui() Local $entries = UBound($dataStruct) Local $newSize = $top + ($addY * $entries) + 100 Local $curPos = WinGetPos($guiMain) WinMove($guiMain, "", $curPos[0], $curPos[1], $curPos[2], $newSize, 0) GUICtrlSetPos($buttonAdd, $COLUMN_PIC, $newSize - 96) GUICtrlSetPos($buttonDel, $COLUMN_PIC + 25, $newSize - 96) GUICtrlSetPos($buttonSave, $COLUMN_PIC, $newSize - 66) GUICtrlSetPos($labelStatus, $COLUMN_PIC + 40, $newSize - 60) EndFunc ;==>ResizeGui Func Debug() _ArrayDisplay($dataStruct) EndFunc ;==>Debug Func GuiMessages() $nMsg = GUIGetMsg(1) Switch $nMsg[0] Case $GUI_EVENT_CLOSE Quit() Case $buttonSave ;save the gui entries to the datastruct Save() Case $buttonAdd AddEntry() ResizeGui() Case $buttonDel DeleteEntry() ResizeGui() EndSwitch For $i = 1 To UBound($dataStruct) - 1 Switch $nMsg[0] Case $dataStruct[$i][$DATA_STRATCTRL] ConsoleWrite("Setting image for pic index " & $i & @CRLF) UpdatePic($i) Return Case $dataStruct[$i][$DATA_BUTTONMOVEDOWN] ConsoleWrite("Swapping " & $i & " and " & $i + 1 & @CRLF) SwapEntry($i, $i + 1) Return Case $dataStruct[$i][$DATA_BUTTONMOVEUP] ConsoleWrite("Swapping " & $i & " and " & $i + 1 & @CRLF) SwapEntry($i, $i - 1) Return Case $dataStruct[$i][$DATA_BUTTONCLEAR] ConsoleWrite("Clearing " & $i & @CRLF) ClearEntry($i) Return EndSwitch Next EndFunc ;==>GuiMessages Func ClearEntry($index) ;~ _GUICtrlComboBox_SelectString($dataStruct[$index][$DATA_STRATCTRL],$nullChar) GUICtrlSetState($dataStruct[$index][$DATA_PICCTRL], $GUI_HIDE) GUICtrlSetState($dataStruct[$index][$DATA_LOADOUTCHECKBOX], $GUI_UNCHECKED) EndFunc ;==>ClearEntry Func SwapEntry($index1, $index2) Local $tempData[1][30] Save() ConsoleWrite("Before swap:" & @CRLF) $dataStruct[$index1][$DATA_STRATNAME] = GUICtrlRead($dataStruct[$index1][$DATA_STRATCTRL]) ConsoleWrite("$dataStruct[$index1][$DATA_STRATNAME] = " & $dataStruct[$index1][$DATA_STRATNAME] & @CRLF) $dataStruct[$index2][$DATA_STRATNAME] = GUICtrlRead($dataStruct[$index2][$DATA_STRATCTRL]) ConsoleWrite("$dataStruct[$index2][$DATA_STRATNAME] = " & $dataStruct[$index2][$DATA_STRATNAME] & @CRLF) $tempData[0][$DATA_STRATNAME] = $dataStruct[$index1][$DATA_STRATNAME] ConsoleWrite("$tempData[0][$DATA_STRATNAME] = " & $tempData[0][$DATA_STRATNAME] & @CRLF) $dataStruct[$index1][$DATA_STRATNAME] = $dataStruct[$index2][$DATA_STRATNAME] ConsoleWrite("$dataStruct[$index1][$DATA_STRATNAME] = " & $dataStruct[$index1][$DATA_STRATNAME] & @CRLF) $dataStruct[$index2][$DATA_STRATNAME] = $tempData[0][$DATA_STRATNAME] ConsoleWrite("$dataStruct[$index2][$DATA_STRATNAME] = " & $dataStruct[$index2][$DATA_STRATNAME] & @CRLF) UpdatePic($index1) UpdatePic($index2) Save() EndFunc ;==>SwapEntry Func UpdatePic($index) Local $stratName _GUICtrlComboBoxEx_GetItemText($dataStruct[$index][$DATA_STRATCTRL],_GUICtrlComboBoxEx_GetCurSel($dataStruct[$index][$DATA_STRATCTRL]),$stratName) If $stratName = $nullChar Then ConsoleWrite("Hiding pic ctrl " & $dataStruct[$index][$DATA_PICCTRL] & @CRLF) GUICtrlSetState($dataStruct[$index][$DATA_PICCTRL], $GUI_HIDE) Else Local $img = StringReplace(@ScriptDir & "\icons\jpg\" & $stratName & "_Stratagem_Icon.jpg", " ", "_") ConsoleWrite("Setting ctrl " & $dataStruct[$index][$DATA_PICCTRL] & " to image " & $img & @CRLF) GUICtrlSetImage($dataStruct[$index][$DATA_PICCTRL], $img) GUICtrlSetState($dataStruct[$index][$DATA_PICCTRL], $GUI_SHOW) EndIf EndFunc ;==>UpdatePic Func UpdateStatus($string) GUICtrlSetData($labelStatus, $string) EndFunc ;==>UpdateStatus Func ShowGUI() WinActivate($guiMain) EndFunc ;==>ShowGUI Func Save() ;//SAVELOAD IniDelete("settings.ini", "Recent") For $i = 1 To UBound($dataStruct) - 1 Local $strat = GUICtrlRead($dataStruct[$i][$DATA_STRATCTRL]) Local $loadout = GUICtrlRead($dataStruct[$i][$DATA_LOADOUTCHECKBOX]) IniWrite("settings.ini", "Recent", "slot" & $i, $strat & "|" & $loadout) IniWrite("settings.ini", "Settings", "initialKeys", UBound($dataStruct) - 1) $dataStruct[$i][$DATA_STRATKEYS] = GetStratKeysByName($strat) $dataStruct[$i][$DATA_STRATNAME] = $strat Switch $loadout Case $GUI_CHECKED $dataStruct[$i][$DATA_LOADOUTENABLED] = True Case $GUI_UNCHECKED $dataStruct[$i][$DATA_LOADOUTENABLED] = False EndSwitch Next EndFunc ;==>Save Func Load() ;//SAVELOAD Local $recent = IniReadSection("settings.ini", "Recent") If @error Then Return For $i = 1 To $recent[0][0] Local $split = StringSplit($recent[$i][1], "|") If UBound($split) > 3 Then GUICtrlSetState($dataStruct[$i][$DATA_LOADOUTCHECKBOX], $split[3]) UpdatePic($i) If $i = UBound($dataStruct) - 1 Then Return Next EndFunc ;==>Load Func GetStratKeysByName($string) Return IniRead($iniStratagems, "Stratagems", $string, "") EndFunc Func Quit() ConsoleWrite("Exiting" & @CRLF) Exit EndFunc ;==>Quit test.zip Link to comment Share on other sites More sharing options...
Nine Posted September 30 Share Posted September 30 92 posts and still not understanding forum rules. Sadly boy sad... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Sunblood Posted October 1 Author Share Posted October 1 (edited) Yes, it is based on icons and weapons from the game but I'm not interacting with or automating it. e: "Launching, automation or script interaction with games or game servers, regardless of the game." I am not launching, automating, or using my script to interact with the game or game servers. I'm just using the icons. Edited October 1 by Sunblood Link to comment Share on other sites More sharing options...
argumentum Posted October 1 Share Posted October 1 You've got seniority over me so, am not gonna explain forum rules ( every time you type that, it auto generates a link. is not me ) I bet you're older than me too ...but I am curious on what are you upto with the GUI. Am a gamer myself ( splitgate ) And also, how to fix the code in such combo. Looks nice. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
argumentum Posted October 1 Share Posted October 1 (edited) #include <GUIConstantsEx.au3> ; BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL)) ... $dataStruct[$index][$DATA_STRATCTRL] = _GUICtrlComboBoxEx_Create($guiMain, "", $COLUMN_STRAT, $top + ($index * $addY + 16),200, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL)) ... ..that seems to help Edit: nope, it didn't Edited October 1 by argumentum oops Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Sunblood Posted October 2 Author Share Posted October 2 20 hours ago, argumentum said: You've got seniority over me so, am not gonna explain forum rules ( every time you type that, it auto generates a link. is not me ) I bet you're older than me too ...but I am curious on what are you upto with the GUI. Am a gamer myself ( splitgate ) And also, how to fix the code in such combo. Looks nice. It's like a local Stratagem Hero clone and/or loadout builder so I can practice my inputs without having to run the game. Really just wanted to experiment with dynamic GUI resizing and some of the extended GUI controls I haven't used before, but got stuck here when the icons started misbehaving. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now