t0nZ Posted January 22, 2018 Share Posted January 22, 2018 (edited) Hello to all, my problem is to have in the same gui buttons (static and dinamically generated ones) and an edit control. The gui also adjust its height in function of button number. Below you see an ugly interface and the long buttons at the bottom are dinamically generated reading from a txt file. Because I have "static" buttons and dynamically generated ones it's not workin' well your method, also the EDIT area is updated (is a live log) and this is detected as GUI events, and this makes the guigetmsg() "dirty". Have you any ideas to make it work in better way ? I only think about creating two different GUIs to not interfere one with the other one. My code is this expandcollapse popupWhile 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GOLLOG("<<<< STOP <<<<") Exit #cs ; test 1 Case $iStart To $iEnd ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< gollog(GUICtrlRead($nMsg) & ' ' & 'was pressed' & @CRLF) $iValueToWorkWith = $nMsg - $iStart ; Adjust as required gollog($iValueToWorkWith) ;ExitLoop #ce Case $buttonarray[1] To $buttonarray[UBound($buttonarray) - 1] $UMDguimsg = GUICtrlRead($nMsg) If $UMDguimsg <> 0 Then GOLLOG("ButtonText=[" & $UMDguimsg & "] was clicked") EndIf Case $Bcerca If BitAND(GUICtrlRead($idradio1), $GUI_CHECKED) = $GUI_CHECKED Then Multisearch("username-machinedescription") If BitAND(GUICtrlRead($idradio2), $GUI_CHECKED) = $GUI_CHECKED Then Multisearch("machinename-username") ;Multisearch("username-machinedescription") Case $Block lock() Case $Busergroups usergroups() Case $Bvnc VNC() Case $Icercato If BitAND(GUICtrlRead($idradio1), $GUI_CHECKED) = $GUI_CHECKED Then Multisearch("username-machinedescription") If BitAND(GUICtrlRead($idradio2), $GUI_CHECKED) = $GUI_CHECKED Then Multisearch("machinename-username") #cs Multisearch("username-machinedescription") Case Else msgbox(64,"test",GUIGetMsg()) $UMDguimsg = GUICtrlRead(GUIGetMsg()) If $UMDguimsg <> $salvaUMDguimsg Then MsgBox(64, "test2", $UMDguimsg) $salvaUMDguimsg = $UMDguimsg #CE EndIf EndSwitch WEnd Thank you , cheers, Edited January 22, 2018 by t0nZ introduce better the problem Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted January 22, 2018 Moderators Share Posted January 22, 2018 @t0nZ you should have listened to your instincts. Reopening a thread after 4 years is not the way to ask for help. Even if you are having the same problem, you are more likely to receive help starting your own thread rather than hijacking someone else's. Also, as AutoIt has grown and changed in 4 years, what worked then may not work now (or there may be better ways of accomplishing the same thing), another reason to let sleeping threads lie. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
t0nZ Posted January 22, 2018 Author Share Posted January 22, 2018 Excuse me. I'll go to open a new thread. Sorry. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted January 22, 2018 Moderators Share Posted January 22, 2018 I've already split this into a new thread @t0nZ no need to open another. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
rudi Posted January 22, 2018 Share Posted January 22, 2018 (edited) Hello, some general aspects to create a dynamic GUI: size and position the GUI and its controls using variables calculate fixed element's height to add them to the required GUI size position controls using relative positioning use an 2D-array to handle control content and control handles dim $a2MyControls[4][2]=[[3], _ ; change "[4][2] = [[3], _" --> to "[24][2]=[[23], _" to see the difference ["Text for control 1","Handle Control one will go here"], _ ["Ctrl 2 Text","handle Ctrl 2"] , _ ["TXT 3"]] $w=300 $Ctrl_h=20 ; Control height: 20 for the control $FixButtonsHeight=30 ; space for the buttons "Go" and Cancel" including space above and below $h=$FixButtonsHeight + $a2MyControls[0][0]* ($Ctrl_h+5) + 20 ; 5 for the "rim" between controls is asumed, plus 20 on top and at bottom $GuiTitle="Dynamic GUI" $MyGui=GUICreate($GuiTitle,$w,$h) $a2MyControls[1][1] = GUICtrlCreateInput($a2MyControls[1][0],10,10,$w-20,$Ctrl_h) Opt("GUICoordMode",2) ; cell relative from now on for $i = 2 to $a2MyControls[0][0] ; 2nd element to end of array $a2MyControls[$i][1]=GUICtrlCreateInput($a2MyControls[$i][0],-1,5) Next ; switch back to absolute control addressing Opt("GUICoordMode",1) $BtnGo=GUICtrlCreateButton("Go",10, $h - $FixButtonsHeight,$w/2-15,$Ctrl_h) $BtnCancel=GUICtrlCreateButton("Cancel",$w/2+5, $h - $FixButtonsHeight,$w/2-15,$Ctrl_h) GUISetState(@SW_SHOW) MsgBox(0,"done","") Edited January 22, 2018 by rudi Earthshine 1 Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
t0nZ Posted January 29, 2018 Author Share Posted January 29, 2018 (edited) Hi @rudi, your solution is very interesting. But it doesn't solve my real problem. I have slightly modified your example, adding a guictrlEDIT (also dynamic managed) but my problem is near the end , the line GUICtrlSetData($edit1, $iValueToWorkWith & " pressed" & @CRLF, 1) writes in the edit control the user input, but writing in the same edit triggers another input, how can I avoid this ??? Maybe I don't have to use the edit control ? Alternatives ? expandcollapse popup; test from autoit forum ; https://www.autoitscript.com/forum/topic/192076-dynamic-creation-of-controls/?do=findComment&comment=1378085 #include <GUIConstantsEx.au3> dim $a2MyControls[4][2]=[[3], _ ; change "[4][2] = [[3], _" --> to "[24][2]=[[23], _" to see the difference ["Text for control 1","Handle Control one will go here"], _ ["Ctrl 2 Text","handle Ctrl 2"] , _ ["TXT 3"]] $w=300 $Ctrl_h=20 ; Control height: 20 for the control $edit_h=80 $space_Between_Controls = 5 $FixButtonsHeight= $Ctrl_h + $edit_h + ($space_Between_Controls *2 ); space for the buttons "Go" and Cancel" including space above and below $h=$FixButtonsHeight + $a2MyControls[0][0]* ($Ctrl_h+($space_Between_Controls*2)) ; 5 for the "rim" between controls is asumed, plus 20 on top and at bottom $GuiTitle="Dynamic GUI" $MyGui=GUICreate($GuiTitle,$w,$h) $iStart = GUICtrlCreateDummy() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $a2MyControls[1][1] = GUICtrlCreateInput($a2MyControls[1][0],10,10,$w-20,$Ctrl_h) Opt("GUICoordMode",2) ; cell relative from now on for $i = 2 to $a2MyControls[0][0] ; 2nd element to end of array $a2MyControls[$i][1]=GUICtrlCreateInput($a2MyControls[$i][0],-1,5) Next ; switch back to absolute control addressing Opt("GUICoordMode",1) $BtnGo=GUICtrlCreateButton("Go",10, $h - $FixButtonsHeight,$w/2-15,$Ctrl_h) $BtnCancel=GUICtrlCreateButton("Cancel",$w/2+5, $h - $FixButtonsHeight,$w/2-15,$Ctrl_h) $edit1 = GUICtrlCreateEdit("Edit 1",10, ($h - $FixButtonsHeight) + 25 ,$w-20,$edit_h) $iEnd = GUICtrlCreateDummy() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUISetState(@SW_SHOW) ;NSC added While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ConsoleWrite($nMsg & @CRLF) Exit Case $iStart To $iEnd ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ConsoleWrite(GUICtrlRead($nMsg) & ' ' & 'was pressed' & @CRLF) $iValueToWorkWith = $nMsg - $iStart ; Adjust as required GUICtrlSetData($edit1, $iValueToWorkWith & " pressed" & @CRLF, 1) ConsoleWrite('The value to use in the rest of our script now is: ' & $iValueToWorkWith & @CRLF) ;GUIDelete($myGUI) ;ExitLoop EndSwitch WEnd ;MsgBox(0,"done","") Cheers. Edited January 29, 2018 by t0nZ tagged Rudi Link to comment Share on other sites More sharing options...
Subz Posted January 29, 2018 Share Posted January 29, 2018 Place your $edit1 outside of the $iStart and $iEnd, otherwise its going to return both the control id you're using and also the $edit1 control (since you're writing to this id). t0nZ 1 Link to comment Share on other sites More sharing options...
t0nZ Posted January 30, 2018 Author Share Posted January 30, 2018 Thanks @Subz so much ! It was so simple ! This is the updated example script. expandcollapse popup;Example dynamic resizing GUI with dynamic input creation and dynamic buttons creation plus edit control to be used as live logging with no interference ;test from autoit forum ;https://www.autoitscript.com/forum/topic/192076-dynamic-creation-of-controls/?do=findComment&comment=1378085 #include <GUIConstantsEx.au3> dim $a2MyControls[4][2]=[[3], _ ; change "[4][2] = [[3], _" --> to "[24][2]=[[23], _" to see the difference ["Text for control 1","Handle Control one will go here"], _ ["Ctrl 2 Text","handle Ctrl 2"] , _ ["TXT 3 - try to write and press enter"]] $w=300 $Ctrl_h=20 ; Control (button in example) height: 20 for the control $edit_h=180 ; Edit control height $space_Between_Controls = 5 $FixButtonsHeight= $Ctrl_h + $edit_h + ($space_Between_Controls *2 ); space for the buttons "Go" and Cancel" including space above and below $h=$FixButtonsHeight + $a2MyControls[0][0]* ($Ctrl_h+($space_Between_Controls*2)) ; 5 for the "rim" between controls is asumed, plus 20 on top and at bottom $GuiTitle="Dynamic GUI" $MyGui=GUICreate($GuiTitle,$w,$h) $iStart = GUICtrlCreateDummy() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $a2MyControls[1][1] = GUICtrlCreateInput($a2MyControls[1][0],10,10,$w-20,$Ctrl_h) Opt("GUICoordMode",2) ; cell relative from now on for $i = 2 to $a2MyControls[0][0] ; 2nd element to end of array $a2MyControls[$i][1]=GUICtrlCreateInput($a2MyControls[$i][0],-1,5) Next ; switch back to absolute control addressing Opt("GUICoordMode",1) $BtnGo=GUICtrlCreateButton("Go 4",10, $h - $FixButtonsHeight,$w/2-15,$Ctrl_h) $BtnCancel=GUICtrlCreateButton("Cancel 5",$w/2+5, $h - $FixButtonsHeight,$w/2-15,$Ctrl_h) $iEnd = GUICtrlCreateDummy() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $edit1 = GUICtrlCreateEdit("Edit 6" & @CRLF,10, ($h - $FixButtonsHeight) + 25 ,$w-20,$edit_h) ; moved after $iEnd to not interfere with $nMsg detection GUISetState(@SW_SHOW) ;t0nZ added While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ConsoleWrite($nMsg & @CRLF) Exit Case $iStart To $iEnd ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ConsoleWrite(GUICtrlRead($nMsg) & ' ' & 'was pressed' & @CRLF) $iValueToWorkWith = $nMsg - $iStart ; Adjust as required GUICtrlSetData($edit1, $iValueToWorkWith & " pressed" & @CRLF, 1) ConsoleWrite('The value to use in the rest of our script now is: ' & $iValueToWorkWith & @CRLF) EndSwitch WEnd Earthshine 1 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