katoNkatoNK
Active Members-
Posts
89 -
Joined
-
Last visited
katoNkatoNK's Achievements
Wayfarer (2/7)
0
Reputation
-
Controls dissapear and menu item's swap menu's..
katoNkatoNK replied to katoNkatoNK's topic in AutoIt GUI Help and Support
Thanks for all the help Melba! Whatever caused the menu swapping between the UDF and dynamic arrays, i still don't know.. ..and ye i have been concentrating on the small bits first but something simple always slips by I've updated the solution (last example of mine) that is working for me, using dummy controls with dynamic items from an ini. -
Controls dissapear and menu item's swap menu's..
katoNkatoNK replied to katoNkatoNK's topic in AutoIt GUI Help and Support
Nice find ..i wouldn't be able to tell you why i didn't pick that up . lol Tested it quite a bit, and it's working! .. and about a post earlier ~ ".txt add" ( post 8 ) I meant to say, "edit the .txt and add sections" meaning manually The problem with the menu items crossing from Load ~ Delete is still happening - i haven't found it messing with any other menu's though.. (should i place dummy's in all dynamic spaces just to be sure?) This can be sorted out by creating the dummy's and swapping for menu-items? I've tried to get a nice function that swaps the items working but an extra item always gets added.. Edit: I Hope you or someone doesn't mind helping further on this problem.. Here's a possible solution..or at least my idea of what needs to happen. Updated: #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <GUIConstantsEx.au3> #include <Array.au3> #include "GUIExtender.au3" Global $cFile = @DesktopDir & "\test.txt", $iCurrent, $iNew, $iLast Global $iLoad[50][2] = [[49, ""]], $iDelete[50][2] = [[49, ""]] ; Array for each menu's control id's - amount of dummy's to start off with Global $hGUI, $mLoad, $mDelete, $hLabel[3], $hButton, $hExt, $iMsg, $sLoad, $sDelete, $Current Global $aData[3][2] = [[9, ""],["Key1", "Value1"],["Key2", "Value2"]] For $i = 1 To 20 ; Make a few sections IniWriteSection($cFile, "Section" & $i, $aData) Next Global $iSectionNames = IniReadSectionNames($cFile) $hGUI = GUICreate("Test", 500, 500) $mLoad = GUICtrlCreateMenu("Load") _SetDummyItems($iLoad) ; 49 $mDelete = GUICtrlCreateMenu("Delete") _SetDummyItems($iDelete) _GUIExtender_Init($hGUI) _GUIExtender_Section_Start(0, 300) GUICtrlCreateLabel("Section Name:", 50, 50, 100, 20) GUICtrlCreateLabel("Key 1:", 50, 100, 100, 20) GUICtrlCreateLabel("Key 2:", 50, 150, 100, 20) $hLabel[0] = GUICtrlCreateLabel("Section Name", 200, 50, 100, 20) $hLabel[1] = GUICtrlCreateLabel("Value 2", 200, 100, 100, 20) $hLabel[2] = GUICtrlCreateLabel("Value 3", 200, 150, 100, 20) $hButton = GUICtrlCreateButton("Update Section Names", 50, 200, 150, 50) _GUIExtender_Section_End() $hExt = _GUIExtender_Section_Start(300, 200) GUICtrlCreateLabel("", 0, 300, 500, 200) GUICtrlSetBkColor(-1, 0xFFF000) _GUIExtender_Section_End() _GUIExtender_Section_Action($hExt, "", "", 470, 10, 15, 15) ; Section button _SetMenuItems($iLoad, $iLoad, $iSectionNames, $mLoad) _SetMenuItems($iDelete, $iDelete, $iSectionNames, $mDelete) GUISetState(@SW_SHOW, $hGUI) While 1 $iMsg = GUIGetMsg() $Current = GUICtrlRead($hLabel[0]) Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $hButton _UpdateMenuItems() ; Gives each update a flag to prevent unneccesary deleting of controls Case Else If $iLoad[0][0] > 0 Then ; Loop for the menu item within the array count If $iMsg >= $iLoad[1][0] And $iMsg <= $iLoad[$iLoad[0][0]][0] Then For $A = 1 To $iLoad[0][0] If $iMsg = $iLoad[$A][0] Then $sLoad = $iLoad[$A][1] ExitLoop EndIf Next _Load($sLoad) ; Set each label with the section's values EndIf EndIf If $iDelete[0][0] > 0 Then ; Loop for the menu item within the array count If $iMsg >= $iDelete[1][0] And $iMsg <= $iDelete[$iDelete[0][0]][0] Then For $A = 1 To $iDelete[0][0] If $iMsg = $iDelete[$A][0] Then $sDelete = $iDelete[$A][1] ExitLoop EndIf Next ; Delete selected section - if it is loaded then clear controls If MsgBox(4, "Delete Preset", "Delete the following preset:" & @CRLF & $sDelete) = 6 Then If $sDelete = $Current Then For $i = 0 To 2 GUICtrlSetData($hLabel[$i], "") Next EndIf IniDelete($cFile, $sDelete) EndIf EndIf EndIf EndSwitch _GUIExtender_Action($iMsg) WEnd Func _SetDummyItems(ByRef $aDummyArray, $iCount = "") ; Hardcode the average amount of dummy's needed If IsInt($iCount) Then $aDummyArray[0][0] = $iCount For $i = 1 To $aDummyArray[0][0] $aDummyArray[$i][0] = GUICtrlCreateDummy() Next $aDummyArray[0][0] = 0 ; No need to delete any dummy's when entering the function to create the menu items Return 1 EndFunc Func _SetMenuItems(ByRef $aDeleteArray, ByRef $aCreateArray, $iArray = -1, $iCtrl = 0) If IsArray($aDeleteArray) Then ; Array holding the Control ID's - initial dummy array For $i = 1 To $aDeleteArray[0][0] GUICtrlDelete($aDeleteArray[$i][0]) ; delete previous amount of menu items created Next EndIf If IsArray($iArray) Then ; Item array If IsArray($aCreateArray) Then ; Array holding the Control ID's ( initial dummy array ) If $iArray[0] > $aCreateArray[0][0] Then ; Delete remaining items if there are more If $aCreateArray[0][0] = 0 Then $aCreateArray[0][0] += 1 For $A = $aCreateArray[0][0] To $iArray[0] GUICtrlDelete($aDeleteArray[$A][0]) Next ElseIf $iArray[0] < $aCreateArray[0][0] Then ; Fill ControlIDs if section names is less than what was deleted For $A = $iArray[0] + 1 To $aCreateArray[0][0] ; Add 1 to stop it from making a dummy in the last place holder of $iArray[0] $aCreateArray[$i][0] = GUICtrlCreateDummy() Next EndIf For $A = 1 To $iArray[0] ; now make the items $aCreateArray[$A][0] = GUICtrlCreateMenuItem($iArray[$A], $iCtrl) $aCreateArray[$A][1] = $iArray[$A] ;add the menu item's text for later reference Next EndIf Else For $i = 1 To $aCreateArray[0][0] ; Refill empty spaces if there were no items $aCreateArray[$i][0] = GUICtrlCreateDummy() Next $aCreateArray[0][0] = $iArray[0] Return EndIf $aCreateArray[0][0] = $iArray[0] ; Amount to delete on next update ( stabilise loop ) EndFunc Func _UpdateMenuItems() If FileExists($cFile) Then ; check for any changes in the ini content to update items $iSectionNames = IniReadSectionNames($cFile) $iNew = "" For $i = 1 To $iSectionNames[0] $iNew &= $iNew & $iSectionNames[$i] Next If $iNew <> $iLast Then _SetMenuItems($iLoad, $iLoad, $iSectionNames, $mLoad) _SetMenuItems($iDelete, $iDelete, $iSectionNames, $mDelete) EndIf $iLast = "" For $i = 1 To $iSectionNames[0] $iLast &= $iLast & $iSectionNames[$i] Next EndIf EndFunc ;==>_UpdateMenuItems Func _Load($iLoad) If FileExists($cFile) Then $iSectionNames = IniReadSectionNames($cFile) ; Update & recheck item exists If IsArray($iSectionNames) Then Local $aLoad = IniReadSection($cFile, $iLoad) If @error Then MsgBox(0, "", "No Section") Return EndIf GUICtrlSetData($hLabel[0], $iLoad) GUICtrlSetData($hLabel[1], $iLoad & " - " & $aLoad[1][1]) GUICtrlSetData($hLabel[2], $iLoad & " - " & $aLoad[2][1]) Else MsgBox(0, "", "Update Menu Items") EndIf Else MsgBox(0, "", "No File") EndIf EndFunc ;==>_Load katonk.. -
lo Cody , im fairly new to autoit so i can't offer much help but i've gotten help before on a gdi issue, winapi is used maybe it could help..
-
Controls dissapear and menu item's swap menu's..
katoNkatoNK replied to katoNkatoNK's topic in AutoIt GUI Help and Support
Ok great, much appreciated Melba!! Just so you know exactly what to look for, the issue is not the label that holds the menu item's text, but it's the static label "Adapter" & "Description" that completely dissapear, then after choosing a menu item, or opening a gui section - it gives the Coord error. P.S. I do remember coming across the error of the dynamic menu items not being in the correct hardcoded menu when i first started with my script ( delete item in loaded ) - and that was fixed by keeping each items handle array seperate from the rest - so i'm not too sure what to make of this. Edit: The full config is just deleting static controls now, when i try add/delete items even if not loaded - until it crashes and give the error.. KatoNk......... -
Controls dissapear and menu item's swap menu's..
katoNkatoNK replied to katoNkatoNK's topic in AutoIt GUI Help and Support
strange.., Thanks for taking a look.. Sorry, i'm struggling to follow amidst trying to make a working example and find a flexible solution. What of the static labels dissapearing though, i get it every now and then even when just deleting an entry - Is this caused by the menu item being removed or because the deleted item was the current item that was 'loaded'? And can this be fixed with the dummy solution? KatoNK.. -
Controls dissapear and menu item's swap menu's..
katoNkatoNK replied to katoNkatoNK's topic in AutoIt GUI Help and Support
Sorry for that, i didn't give it much thought I hope my stripping it down to the relevant piece is better than last.. #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <GUIConstantsEx.au3> #include "GUIExtender.au3" Opt('MustDeclareVars', 1) Global $cFile = @ScriptDir & "\test.txt" Global $aSectionNames = IniReadSectionNames($cFile), $iCurrent, $iNew, $iLast Global $iLoad[1][2] = [[0, 2]], $iDelete[1][2] = [[0, 2]] Global $hGUI, $iMsg Global $aData[3][2] = [[9, ""],["Adapter", ""],["Description", ""]] For $i = 1 To 20 ;make a few sections $aData[1][1] = $aData[1][0] & $i $aData[2][1] = $aData[2][0] & $i IniWriteSection($cFile, "Item" & $i, $aData) Next _hMain() Func _hMain() Local $Menu, $Load, $Delete, $View, $IP_Section Local $pTitle, $aTitle, $dTitle, $Current, $sLoad, $sDelete Local $Static1, $Section1 $hGUI = GUICreate("LazyIP", 300, 270, -1, -1) $Menu = GUICtrlCreateMenu("Menu") $Load = GUICtrlCreateMenu("Load", $Menu) $Delete = GUICtrlCreateMenu("Delete", $Menu) GUICtrlCreateMenuItem("", $Menu) $View = GUICtrlCreateMenu("View", $Menu) $IP_Section = GUICtrlCreateMenuItem("Section1", $View) _GUIExtender_Init($hGUI) $Static1 = _GUIExtender_Section_Start(0, 100) GUICtrlCreateLabel("Preset:", 22, 14) GUICtrlCreateLabel("Adapter:", 15, 32) $pTitle = GUICtrlCreateLabel("", 60, 14, 215, 20) $aTitle = GUICtrlCreateLabel("", 60, 32, 215, 20) $dTitle = GUICtrlCreateLabel("", 60, 50, 215, 18) GUICtrlCreateGroup("", 5, 0, 280, 70) GUICtrlCreateLabel("Section1", 35, 75) _GUIExtender_Section_Action($Static1 + 1, "", "", 10, 75, 15, 15) _GUIExtender_Section_End() $Section1 = _GUIExtender_Section_Start(100, 150) GUICtrlCreateLabel("", 0, 100, 300, 150) GUICtrlSetBkColor(-1, 0xFF0000) _GUIExtender_Section_End() _GUIExtender_Section_Extend(0, False) If IsArray($aSectionNames) Then _SetMenuItems($iLoad, $iLoad, $aSectionNames, $Load) _SetMenuItems($iDelete, $iDelete, $aSectionNames, $Delete) EndIf GUISetState(@SW_SHOW, $hGUI) While 1 $iMsg = GUIGetMsg(1) $Current = GUICtrlRead($pTitle) _UpdateMenuItems($iLoad, $iDelete) ;loop update flag Switch $iMsg[1] Case $hGUI Switch $iMsg[0] Case $IP_Section If BitAND(GUICtrlRead($IP_Section), $GUI_CHECKED) = $GUI_CHECKED Then _GUIExtender_Section_Extend($Section1, False) GUICtrlSetState($IP_Section, $GUI_UNCHECKED) Else _GUIExtender_Section_Extend($Section1) GUICtrlSetState($IP_Section, $GUI_CHECKED) EndIf Case $GUI_EVENT_RESTORE WinActivate($hGUI) Case $GUI_EVENT_CLOSE Exit Case Else If $iLoad[0][0] > 0 Then ;loop for iLoad's item text If $iMsg[0] >= $iLoad[1][0] And $iMsg[0] <= $iLoad[$iLoad[0][0]][0] Then For $A = 1 To $iLoad[0][0] If $iMsg[0] = $iLoad[$A][0] Then $sLoad = $iLoad[$A][1] ExitLoop EndIf Next _Load($sLoad, $pTitle, $aTitle, $dTitle) EndIf EndIf If $iDelete[0][0] > 0 Then ;loop for iDelete's item text If $iMsg[0] >= $iDelete[1][0] And $iMsg[0] <= $iDelete[$iDelete[0][0]][0] Then For $A = 1 To $iDelete[0][0] If $iMsg[0] = $iDelete[$A][0] Then $sDelete = $iDelete[$A][1] ExitLoop EndIf Next _Delete($sDelete, $Current, $pTitle, $aTitle, $dTitle) ;If Not @error Then _UpdateMenuItems($Load, $Delete) EndIf EndIf EndSwitch EndSwitch _GUIExtender_Action($iMsg[0]) Local $SectionStatus = _GUIExtender_Section_State($Section1) If $SectionStatus = 0 Then If BitAND(GUICtrlRead($IP_Section), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($IP_Section, $GUI_UNCHECKED) ElseIf $SectionStatus = 1 Then If BitAND(GUICtrlRead($IP_Section), $GUI_CHECKED) <> $GUI_CHECKED Then GUICtrlSetState($IP_Section, $GUI_CHECKED) EndIf WEnd EndFunc ;==>_hMain Func _SetMenuItems(ByRef $aDeleteArray, ByRef $aCreateArray, $iArray, $hCtrl) ;delete | add - menu items function If IsArray($aDeleteArray) Then For $A = 1 To $aDeleteArray[0][0] GUICtrlDelete($aDeleteArray[$A][0]) $aDeleteArray[$A][0] = -1 Next EndIf If IsArray($aCreateArray) And IsArray($iArray) Then ReDim $aCreateArray[$iArray[0] + 1][2] $aCreateArray[0][0] = $iArray[0] Local $iText For $A = 1 To $aCreateArray[0][0] $iText = $iArray[$A] $aCreateArray[$A][0] = GUICtrlCreateMenuItem($iText, $hCtrl) $aCreateArray[$A][1] = $iText Next EndIf Return 1 EndFunc ;==>_SetMenuItems Func _UpdateMenuItems($hHandle1, $hHandle2) ;loop $iNew and $iCurrent to keep items updated If FileExists($cFile) Then $iCurrent = IniReadSectionNames($cFile) $iNew = "" If IsArray($iCurrent) Then For $i = 1 To $iCurrent[0] $iNew = $iNew & $iCurrent[$i] Next If $iNew <> $iLast Then _SetMenuItems($iLoad, $iLoad, $iCurrent, $hHandle1) _SetMenuItems($iDelete, $iDelete, $iCurrent, $hHandle2) $iLast = "" For $i = 1 To $iCurrent[0] $iLast = $iLast & $iCurrent[$i] Next Else Return EndIf Else $iCurrent = "" _SetMenuItems($iLoad, $iLoad, $iCurrent, $hHandle1) _SetMenuItems($iDelete, $iDelete, $iCurrent, $hHandle2) EndIf EndIf EndFunc ;==>_UpdateMenuItems Func _Load($pLoad, $Preset, $Adapter, $Description) ;set the labels with the section data If FileExists($cFile) Then $aSectionNames = IniReadSectionNames($cFile) If IsArray($aSectionNames) Then Local $aLoad = IniReadSection($cFile, $pLoad) If @error Then Return SetError(3) GUICtrlSetData($Preset, $pLoad) If $aLoad[1][1] = "n/a" Or $aLoad[2][1] = "n/a" Then GUICtrlSetData($Adapter, "n/a") GUICtrlSetData($Description, "n/a") Else GUICtrlSetData($Adapter, $aLoad[1][1]) GUICtrlSetData($Description, $aLoad[2][1]) EndIf Else Return SetError(2) EndIf Else Return SetError(1) EndIf EndFunc ;==>_Load Func _Delete($pDel, $pCur, $hPreset, $hAdapter, $hDescription) ;delete from ini and clear controls If MsgBox(4, "Delete Preset", "Delete the following preset:" & @CRLF & $pDel) = 6 Then If $pDel = $pCur Then GUICtrlSetData($hPreset, "") GUICtrlSetData($hAdapter, "") GUICtrlSetData($hDescription, "") EndIf IniDelete($cFile, $pDel) EndIf EndFunc ;==>_Delete otherwise: Line 89 : menu items created Line 185 - 206 : set the menu items on gui startup. (first time) Line 432 - 475 : loop to get the menu item's text. Line 660: Function setting the menu items Line 698: Function that updates the preset name's/menu items And here is a 'solution' i thought might work, as the menu items are dynamic there's some checks if it need to refill or open more controlID's before creating.. Func _SetMenuItems(ByRef $aDeleteArray, ByRef $aCreateArray, $iArray, $CtrlID) If IsArray($aDeleteArray) Then ; Array holding the Control ID's For $i = 1 To $iArray[0][0] ;delete previous amount of menu items GUICtrlDelete($aDeleteArray[$i][0]) Next EndIf If IsArray($iArray) Then ;Section name array If $iArray[0] > $aCreateArray[0][0] Then ;delete remaining items if there are more For $A = $aCreateArray[0][0] To $iArray[0] GUICtrlDelete($aCreateArray[$A][0]) Next ElseIf $iArray[0] < $aCreateArray[0][0] Then ;fill ControlIDs when section names is less than what was deleted For $A = $aCreateArray[0][0] To $iArray[0] Step -1 $aCreateArray[$i][0] = GUICtrlCreateDummy() Next EndIf $aCreateArray[0][0] = $iArray[0] ;amount to delete on next update For $A = 1 To $aCreateArray[0][0] $aCreateArray[$A][0] = GUICtrlCreateMenuItem($iArray[$A], $CtrlID) $aCreateArray[$A][1] = $iArray[$A] ;add the menu item's text for later reference Next Else For $i = 1 To $aCreateArray[0][0] ;fill empty spaces if no section names $aCreateArray[$i][0] = GUICtrlCreateDummy() Next Return EndIf EndFunc Thank you for you time KatoNK.. P.s I don't know of a better way to create two gui's that are almost used for the same thing and whatever else was broken in my script -
Controls dissapear and menu item's swap menu's..
katoNkatoNK replied to katoNkatoNK's topic in AutoIt GUI Help and Support
Ok, ill do that, did some more testing on the example i posted and it actualy doesn't work .. if you edit the .txt add sections while the gui is open the delete function moves into the load menu(click a load item and it shows the delete message), so ye dummy's would be used to solve this. Here's my script it's dirty.. 1200 lines of it.. Note: if you're using Win7 it'll run fine, otherwise it might not because of the WMI used.. Edit: Removed full script, see examples.. -
Controls dissapear and menu item's swap menu's..
katoNkatoNK replied to katoNkatoNK's topic in AutoIt GUI Help and Support
Hi Melba23 Just to clarify in case it makes a difference, the label's control ids are static and they are changed only using guictrlsetdata() and the only place that i am doing this is in the top static section.. would the showing/hiding of the labels make that much of a difference? (in my main script the menu items are being added as shown in your reply - after all the controls of the gui) ..and I wasn't using this method (below) in my example because my script has multiple gui's so i'm already using the advanced parameter of guigetmsg(). So in order to get the text i needed without going too far, an additional element was added to the array which was read in the 'Case Else' loop. Case $aLoad[1] To $aLoad[$iCount] ; Set label to loaded element GUICtrlSetData($hLabel_1, GUICtrlRead($iMsg, 1)) Doesn't seem like my typo i found in the menu item creating hasn't made any difference. So effectively the only solution is to have a seperate function swap the control ids of the dummy's needed? it seems that only updating the menu items is an issue.. -
Controls dissapear and menu item's swap menu's..
katoNkatoNK replied to katoNkatoNK's topic in AutoIt GUI Help and Support
Hi, i've cleaned up some code to show a replicator.. but after cleaning it up it seemed to work just fine, so here's the code maybe you can pick something from it while i have another look at the full script to see if i've missed anything.. The _SetMenuItem function is slightly tweaked by me but an example from guinness, so i doubt it would be causing any problems.. (In the full script the problem was deleting labels from the gui or giving the Coordinate error, and once or twice it's triggered a menu item and kept on looping it..) #include <GUIConstantsEx.au3> #include "GUIExtender.au3" Opt('MustDeclareVars', 1) Global $cFile = @ScriptDir & "\test.txt", $aSectionNames = IniReadSectionNames($cFile), $iLoad[1][2] = [[0, 2]], $iDelete[1][2] = [[0, 2]], $iCurrent, $iNew, $iLast Global $hGUI, $Menu, $Load, $Delete, $Label, $sLoad, $sDelete, $Static1, $Section1, $Static2, $Section2, $iMsg $hGUI = GUICreate("LazyIP", 200, 250, -1, -1) $Menu = GUICtrlCreateMenu("Menu") $Load = GUICtrlCreateMenu("Load", $Menu) $Delete = GUICtrlCreateMenu("Delete", $Menu) _GUIExtender_Init($hGUI) $Static1 = _GUIExtender_Section_Start(0, 100) GUICtrlCreateLabel("Label 1:", 20, 10) GUICtrlCreateLabel("Label 2:", 20, 30) GUICtrlCreateLabel("Label 3:", 20, 50) $Label = GUICtrlCreateLabel("", 70, 50, 100, 15) GUICtrlCreateLabel("Section 1", 35, 85) _GUIExtender_Section_Action($Static1 + 1, "", "", 13, 85, 15, 15) _GUIExtender_Section_End() $Section1 = _GUIExtender_Section_Start(100, 50) GUICtrlCreateLabel("", 0, 100, 200, 50) GUICtrlSetBkColor(-1, 0xFFCCCC) GUICtrlSetState(-1, $GUI_DISABLE) _GUIExtender_Section_End() $Static2 = _GUIExtender_Section_Start(150, 20) GUICtrlCreateLabel("Section 2", 35, 150) _GUIExtender_Section_Action($Static2 + 1, "", "", 13, 150, 15, 15) _GUIExtender_Section_End() $Section2 = _GUIExtender_Section_Start(170, 50) GUICtrlCreateLabel("", 0, 170, 200, 50) GUICtrlSetBkColor(-1, 0xFFCCCC) GUICtrlSetState(-1, $GUI_DISABLE) _GUIExtender_Section_End() _GUIExtender_Section_Start(230, 30) GUICtrlCreateLabel("", 0, 230, 200, 30) _GUIExtender_Section_End() _GUIExtender_Section_Extend(0, False) If IsArray($aSectionNames) Then _SetMenuItems($iLoad, $iLoad, $aSectionNames, $Load) _SetMenuItems($iDelete, $iDelete, $aSectionNames, $Delete) Else MsgBox(0, "", "No Sections found.") EndIf GUISetState(@SW_SHOW, $hGUI) While 1 $iMsg = GUIGetMsg() Global $Current_Label = GUICtrlRead($Label) _UpdateMenuItems($Load, $Delete) Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case Else If $iLoad[0][0] > 0 Then If $iMsg >= $iLoad[1][0] And $iMsg <= $iLoad[$iLoad[0][0]][0] Then For $A = 1 To $iLoad[0][0] If $iMsg = $iLoad[$A][0] Then $sLoad = $iLoad[$A][1] ExitLoop EndIf Next _Load($sLoad) If @error Then MsgBox(0, "", "Load error.") EndIf EndIf If $iDelete[0][0] > 0 Then If $iMsg >= $iDelete[1][0] And $iMsg <= $iDelete[$iDelete[0][0]][0] Then For $A = 1 To $iDelete[0][0] If $iMsg = $iDelete[$A][0] Then $sDelete = $iDelete[$A][1] ExitLoop EndIf Next _Delete($sDelete) ;If Not @error Then _UpdateMenuItems($Load, $Delete) EndIf EndIf EndSwitch _GUIExtender_Action($iMsg) WEnd Func _SetMenuItems(ByRef $aDeleteArray, ByRef $aCreateArray, ByRef $iArray, $hCtrl) If IsArray($aDeleteArray) Then For $A = 1 To $aDeleteArray[0][0] GUICtrlDelete($aDeleteArray[$A][0]) $aDeleteArray[$A][0] = -1 Next EndIf If IsArray($aCreateArray) And IsArray($iArray) Then ReDim $aCreateArray[$iArray[0] + 1][2] $aCreateArray[0][0] = $iArray[0] For $A = 1 To $aCreateArray[0][0] Local $iText = $iArray[$A] $aCreateArray[$A][0] = GUICtrlCreateMenuItem($iText, $hCtrl) $aCreateArray[$A][1] = $iText Next EndIf Return 1 EndFunc ;==>_SetMenuItems Func _UpdateMenuItems($hHandle1, $hHandle2) If FileExists($cFile) Then $iCurrent = IniReadSectionNames($cFile) $iNew = "" If IsArray($iCurrent) Then For $i = 1 To $iCurrent[0] $iNew = $iNew & $iCurrent[$i] Next If $iNew <> $iLast Then _SetMenuItems($iLoad, $iLoad, $iCurrent, $hHandle1) _SetMenuItems($iDelete, $iDelete, $iCurrent, $hHandle2) $iLast = "" For $i = 1 To $iCurrent[0] $iLast = $iLast & $iCurrent[$i] Next Else Return EndIf Else $iCurrent = "" _SetMenuItems($iLoad, $iLoad, $iCurrent, $hHandle1) _SetMenuItems($iDelete, $iDelete, $iCurrent, $hHandle2) EndIf EndIf EndFunc ;==>_UpdateMenuItems Func _Load($Load_Item) If FileExists($cFile) Then $aSectionNames = IniReadSectionNames($cFile) If IsArray($aSectionNames) Then GUICtrlSetData($Label, $Load_Item) Else MsgBox(0, "", "No Sections found.") EndIf Else Return SetError(1) EndIf EndFunc ;==>_Load Func _Delete($Delete) If MsgBox(4, "Delete Preset", "Delete the following preset:" & @CRLF & $Delete) = 6 Then If $Delete = $Current_Label Then GUICtrlSetData($Label, "Label 3:") IniDelete($cFile, $Delete) EndIf EndFunc ;==>_Delete -
Hi Melba23 I hope you can help me once again I have the same problem as Lupo73 had before you updated the UDF, except i'm getting the same error while renewing dynamic menu items..so it has to delete the controls then recreate them. $iAdjust_Y = $aPos[1] - $iNext_Coord $iAdjust_Y = $aPos^ ERROR KatoNK..
-
Hi, i'm not too good with arrays myself, but there is many ways this can be done. Have a look at these links, the second link is probably more on the line of what you are looking for. hope it helps!
-
Thanks for the reply mono, that's kind of what i've been trying to do. Have a look at the updated example ^ The problem now seems to be the monitoring of the controls (i have an 'If' statement enabling/disabling controls in the while loop) while the gui with the one control less is active - this gui 'freezes' once shown and i can only exit on the main gui. So i added a check to the If statement as well which seems to be holding up.. If IsArray($hStatus) And IsArray ($hHandle) Then If $hStatus[0] >= 1 Then $hStatus[1] = GUICtrlRead($hHandle[1]) ;Preset Name $hStatus[2] = GUICtrlRead($hHandle[2]) ;Status ~ Checkbox of 'Use Adapter' $hStatus[3] = GUICtrlRead($hHandle[3]) ;Status ~ Installed Adapter $hStatus[4] = GUICtrlRead($hHandle[4]) ;Installed Adapter Name If $hStatus[0] = 1 Then $hStatus[5] = GUICtrlRead($hHandle[5]) ;Status ~ Use Installed Adapters current properties (Not in 'SaveAs') $hStatus[6] = GUICtrlRead($hHandle[6]) ;Status ~ Custom Adapter $hStatus[7] = GUICtrlRead($hHandle[7]) ;Custom Adapter Name If $hStatus[2] = $GUI_CHECKED Then ControlEnable("", "", $hHandle[3]) ControlEnable("", "", $hHandle[6]) If $hStatus[3] = $GUI_CHECKED Then ControlEnable("", "", $hHandle[4]) If $hStatus[0] = 1 Then ControlEnable("", "", $hHandle[5]) ControlDisable("", "", $hHandle[7]) ElseIf $hStatus[6] = $GUI_CHECKED Then ControlEnable("", "", $hHandle[7]) ControlDisable("", "", $hHandle[4]) If $hStatus[0] = 1 Then ControlDisable("", "", $hHandle[5]) EndIf ElseIf $hStatus[2] = $GUI_UNCHECKED Then ControlDisable("", "", $hHandle[3]) ControlDisable("", "", $hHandle[4]) If $hStatus[0] = 1 Then ControlDisable("", "", $hHandle[5]) ControlDisable("", "", $hHandle[6]) ControlDisable("", "", $hHandle[7]) EndIf ElseIf $hStatus[0] = -1 Then GUICtrlSetState($New, $GUI_ENABLE) GUICtrlSetState($SaveAs, $GUI_ENABLE) EndIf EndIf I know it might be confusing with all the numbers , but apart from adding the checks is this the best thing to have in a While loop?
-
Hi all. I've gotten fairly close to what i am trying to do but i am pretty sure that there is a more efficient way to create a gui from the same function. The main gui doesn't change at all, but the hGUI2/3 array is used to create the 2nd and 3rd gui after the currently active gui is deleted when '$bGUI2' or '$bGUI3' is pressed. The reason i am trying to do this is because in my main script gui3 has one less control and also used for something different than gui2. Here's a working example of how far i have managed to get..it's a bit messy. Any help is appreciated. #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $hGUI, $bGUI2, $bGUI3, $iMsg, $hGlobalStatus, $hGlobalHandle Global $hHandle2[2] = [1000], $hStatus2[2] = [-1] Global $hHandle3[2] = [1000], $hStatus3[2] = [-1] $hGUI = GUICreate("hGUI", 200, 300, -1, -1) $bGUI2 = GUICtrlCreateButton("hGUI2", 10, 10, 40, 22.5) $bGUI3 = GUICtrlCreateButton("hGUI3", 60, 10, 40, 22.5) GUISetState(@SW_SHOW, $hGUI) While 1 $iMsg = GUIGetMsg(1) Switch $iMsg[1] Case $hGUI Switch $iMsg[0] Case $bGUI2 If IsArray($hGlobalStatus) Then If $hGlobalStatus[0] = 1 Then GUIDelete($hGlobalHandle[0]) $hGlobalStatus[0] = -1 $hGlobalHandle[0] = 1000 EndIf EndIf GUICtrlSetState($bGUI3, $GUI_ENABLE) $hGlobalHandle = _hHandle($hHandle2, "GUI 2") $hStatus2[0] = 1 $hGlobalStatus = $hStatus2 GUICtrlSetState($bGUI2, $GUI_DISABLE) Case $bGUI3 If IsArray($hGlobalStatus) Then If $hGlobalStatus[0] = 1 Then GUIDelete($hGlobalHandle[0]) $hGlobalStatus[0] = -1 $hGlobalHandle[0] = 1000 EndIf EndIf GUICtrlSetState($bGUI2, $GUI_ENABLE) $hGlobalHandle = _hHandle($hHandle3, "GUI 3") $hStatus3[0] = 1 $hGlobalStatus = $hStatus3 GUICtrlSetState($bGUI3, $GUI_DISABLE) Case $GUI_EVENT_MINIMIZE If $hGlobalStatus[0] = 1 Then GUIDelete($hGlobalHandle[0]) $hGlobalStatus[0] = -1 $hGlobalHandle[0] = 1000 EndIf GUICtrlSetState($bGUI2, $GUI_ENABLE) GUICtrlSetState($bGUI3, $GUI_ENABLE) Case $GUI_EVENT_CLOSE Exit EndSwitch Case $hHandle2[0] Switch $iMsg[0] Case $hHandle2[1] MsgBox(0, $hHandle3[1], "GUI 2 - " & $hHandle3[0]) Case $GUI_EVENT_CLOSE GUIDelete($hHandle2[0]) $hStatus2[0] = -1 GUICtrlSetState($bGUI2, $GUI_ENABLE) EndSwitch Case $hHandle3[0] Switch $iMsg[0] Case $hHandle3[1] MsgBox(0, $hHandle3[1], "GUI 3 - " & $hHandle3[0]) Case $GUI_EVENT_CLOSE GUIDelete($hHandle3[0]) $hStatus3[0] = -1 GUICtrlSetState($bGUI3, $GUI_ENABLE) EndSwitch EndSwitch If IsArray($hGlobalStatus) Then If $hGlobalStatus[0] = 1 Then ControlEnable("", "", $hGlobalHandle[1]) EndIf WEnd Func _hHandle(ByRef $hGlobalHandle, $Test) $hGlobalHandle[0] = GUICreate($Test, 150, 100, -1, -1, $WS_SYSMENU) $hGlobalHandle[1] = GUICtrlCreateButton($Test, 60, 10, 40, 22.5) GUICtrlSetState(-1, $GUI_DISABLE) GUISetState(@SW_SHOW, $hGlobalHandle[0]) Return $hGlobalHandle EndFunc ;==>_hGUI3 P.S. Please keep the advanced parameter on GUIGetMsg() as i need this in my main script. Edit: I hope i explained it clear enough.. The main goal i guess is to 'toggle' the array to match the active gui so the correct case/switch statement is triggered. Edit2: Here's my attempt at combining hGUI2 & hGUI3 that works.. am i doing it correctly? #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $hGUI, $bGUI2, $bGUI3, $iMsg, $hHandle = "", $hStatus[2] = [-1], $hGUI2[2] = [1000], $hGUI3[2] = [1000] $hGUI = GUICreate("hGUI", 200, 300, -1, -1) $bGUI2 = GUICtrlCreateButton("hGUI2", 10, 10, 40, 22.5) $bGUI3 = GUICtrlCreateButton("hGUI3", 60, 10, 40, 22.5) GUISetState(@SW_SHOW, $hGUI) While 1 $iMsg = GUIGetMsg(1) Switch $iMsg[1] Case $hGUI ;main gui Switch $iMsg[0] Case $bGUI2 If IsArray($hStatus) Then If $hStatus[0] = 1 Then GUIDelete($hHandle[0]) $hStatus[0] = -1 EndIf EndIf GUICtrlSetState($bGUI3, $GUI_ENABLE) $hGUI2 = _hHandle("GUI 2") $hStatus[0] = 1 GUICtrlSetState($bGUI2, $GUI_DISABLE) $hHandle = $hGUI2 Case $bGUI3 If IsArray($hStatus) Then If $hStatus[0] = 1 Then GUIDelete($hHandle[0]) $hStatus[0] = -1 EndIf EndIf GUICtrlSetState($bGUI2, $GUI_ENABLE) $hGUI3 = _hHandle("GUI 3") $hStatus[0] = 1 GUICtrlSetState($bGUI3, $GUI_DISABLE) $hHandle = $hGUI3 Case $GUI_EVENT_MINIMIZE If $hStatus[0] = 1 Then GUIDelete($hHandle[0]) $hStatus[0] = -1 EndIf $hHandle = "" GUICtrlSetState($bGUI2, $GUI_ENABLE) GUICtrlSetState($bGUI3, $GUI_ENABLE) Case $GUI_EVENT_CLOSE Exit EndSwitch Case $hGUI2[0] ;2ng gui Switch $iMsg[0] Case $hGUI2[1] MsgBox(0, $hGUI2[1], "GUI 2 - " & $hGUI2[0]) Case $GUI_EVENT_CLOSE GUIDelete($hGUI2[0]) $hStatus[0] = -1 $hHandle = "" ;reset to default GUICtrlSetState($bGUI2, $GUI_ENABLE) EndSwitch Case $hGUI3[0] ;3rd gui Switch $iMsg[0] Case $hGUI3[1] MsgBox(0, $hGUI3[1], "GUI 3 - " & $hGUI3[0]) Case $GUI_EVENT_CLOSE GUIDelete($hGUI3[0]) $hStatus[0] = -1 $hHandle = "" ;reset to default GUICtrlSetState($bGUI3, $GUI_ENABLE) EndSwitch EndSwitch If IsArray($hStatus) Then If $hStatus[0] = 1 Then ControlEnable("", "", $hHandle[1]) EndIf WEnd Func _hHandle($Test) Local $hArray[2] $hArray[0] = GUICreate($Test, 150, 100, -1, -1, $WS_SYSMENU) $hArray[1] = GUICtrlCreateButton($Test, 60, 10, 40, 22.5) GUICtrlSetState(-1, $GUI_DISABLE) GUISetState(@SW_SHOW, $hArray[0]) Return $hArray EndFunc ;==>_hGUI3
-
Aah I remember seeing it in the UDF, but actually missed that post! Thanks Melba23 Edit: Mmm it restores the sections perfectly now! but it seems i have another problem similar to Lupo73's but with menu items. Once restored..The first sections 'arrow' disappears and becomes a menu's item - in the place of the dynamic menu items that were previously there OR the arrow becomes the dynamic menu items handles. (In the case of either of the outcomes both the menu items funcion and the section is triggerred) I hope i didn't miss anything else Edit2: It gave me this error, for the first time only now: C:\Users\mAtt\Desktop\GUIExtender.au3 (448) : ==> Subscript used with non-Array variable.: If $aPos[0] < $iGUI_Fixed Then If $aPos^ ERROR Edit3: lol.. it seems to have fixed itself after i shuffled some functions around that set menu items on the tray/gui.
-
Hi, Something else i came across.. After the gui is restored from the tray and if all sections have been retracted the controls below the first static section aren't visible. I'm sure this can be avoided? #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <GUIConstantsEx.au3> #include <Constants.au3> #include "GUIExtender.au3" Opt('MustDeclareVars', 1) Opt('TrayMenuMode', 3) Opt('TrayAutoPause', 0) Global $hGUI, $iMsg, $tMsg, $View, $tExit, $1, $2, $3 Global $sStatic1, $sStatic2, $sStatic3, $Section1, $Section2, $Section3, $sGUI1, $sGUI2, $sGUI3 $hGUI = GUICreate("hGui", 290, 610, -1, -1) $View = GUICtrlCreateMenu("View") $1 = GUICtrlCreateMenuItem("IP Settings", $View) $2 = GUICtrlCreateMenuItem("DNS Settings", $View) $3 = GUICtrlCreateMenuItem("WINS Settings", $View) _GUIExtender_Init($hGUI) $sStatic1 = _GUIExtender_Section_Start(0, 90) GUICtrlCreateGroup("", 5, 0, 285, 70) GUICtrlCreateCheckbox("IP Address", 35, 75) _GUIExtender_Section_Action($sStatic1 + 1, "", "", 13, 78, 15, 15) _GUIExtender_Section_End() $Section1 = _GUIExtender_Section_Start(90, 140) GUICtrlCreateGroup("", 5, 125, 280, 110) _GUIExtender_Section_End() $sStatic2 = _GUIExtender_Section_Start(230, 25) GUICtrlCreateCheckbox("DNS Servers", 35, 240) _GUIExtender_Section_Action($sStatic2 + 1, "", "", 13, 243, 15, 15) _GUIExtender_Section_End() $Section2 = _GUIExtender_Section_Start(255, 110) GUICtrlCreateGroup("", 5, 290, 280, 80) _GUIExtender_Section_End() $sStatic3 = _GUIExtender_Section_Start(365, 25) GUICtrlCreateCheckbox("WINS Server", 35, 375) _GUIExtender_Section_Action($sStatic3 + 1, "", "", 13, 378, 15, 15) _GUIExtender_Section_End() $Section3 = _GUIExtender_Section_Start(390, 110) GUICtrlCreateGroup("", 5, 425, 280, 80) _GUIExtender_Section_End() _GUIExtender_Section_Start(500, 95) GUIStartGroup() GUICtrlCreateGroup("", 5, 535, 280, 50) GUICtrlCreateRadio("radio1", 15, 510) GUICtrlCreateRadio("radio2:", 15, 530) _GUIExtender_Section_End() _GUIExtender_Section_Extend(0, False) $tExit = TrayCreateItem("Exit") GUISetState(@SW_SHOW, $hGUI) While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $1 If BitAND(GUICtrlRead($1), $GUI_CHECKED) = $GUI_CHECKED Then _GUIExtender_Section_Extend($Section1, False) GUICtrlSetState($1, $GUI_UNCHECKED) Else _GUIExtender_Section_Extend($Section1) GUICtrlSetState($1, $GUI_CHECKED) EndIf Case $2 If BitAND(GUICtrlRead($2), $GUI_CHECKED) = $GUI_CHECKED Then _GUIExtender_Section_Extend($Section2, False) GUICtrlSetState($2, $GUI_UNCHECKED) Else _GUIExtender_Section_Extend($Section2) GUICtrlSetState($2, $GUI_CHECKED) EndIf Case $3 If BitAND(GUICtrlRead($3), $GUI_CHECKED) = $GUI_CHECKED Then _GUIExtender_Section_Extend($Section3, False) GUICtrlSetState($3, $GUI_UNCHECKED) Else _GUIExtender_Section_Extend($Section3) GUICtrlSetState($3, $GUI_CHECKED) EndIf Case $GUI_EVENT_MINIMIZE GUISetState(@SW_HIDE) TraySetState() Case $GUI_EVENT_CLOSE Exit EndSwitch _GUIExtender_Action($iMsg) $sGUI1 = _GUIExtender_Section_State($Section1) $sGUI2 = _GUIExtender_Section_State($Section2) $sGUI3 = _GUIExtender_Section_State($Section3) If $sGUI1 = 0 Then If BitAND(GUICtrlRead($1), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($1, $GUI_UNCHECKED) ElseIf $sGUI1 = 1 Then If BitAND(GUICtrlRead($1), $GUI_CHECKED) <> $GUI_CHECKED Then GUICtrlSetState($1, $GUI_CHECKED) EndIf If $sGUI2 = 0 Then If BitAND(GUICtrlRead($2), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($2, $GUI_UNCHECKED) ElseIf $sGUI2 = 1 Then If BitAND(GUICtrlRead($2), $GUI_CHECKED) <> $GUI_CHECKED Then GUICtrlSetState($2, $GUI_CHECKED) EndIf If $sGUI3 = 0 Then If BitAND(GUICtrlRead($3), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($3, $GUI_UNCHECKED) ElseIf $sGUI3 = 1 Then If BitAND(GUICtrlRead($3), $GUI_CHECKED) <> $GUI_CHECKED Then GUICtrlSetState($3, $GUI_CHECKED) EndIf $tMsg = TrayGetMsg() Switch $tMsg Case $TRAY_EVENT_PRIMARYUP GUISetState() WinActivate($hGUI) TraySetState(2) Case $tExit Exit EndSwitch WEnd ~Left-Click the tray icon to restore.