Jump to content

My dynamic GUI buttons won't work.


Recommended Posts

Hello

I'm trying to create "simple" GUI menu with list of Internet browsers that can be opened by clicking particular button. However I've faced issue of activating the buttons. See screens below.

As you can see when browser button is clicked additional menu with paramters is created. The issue starts when I want to switch between browser buttons when I've already chosen one. I.e. when I click on Mozilla Firefox "paramters menu" appears but then when I want to switch to Google Chrome it's not reacting.

 

obraz.png.aff2574b6dda21e9ecdb5e1453ba8d37.png

 

obraz.png.d352f70b5ee2400c255b70bf8e7b36e8.png

 

The code.

I've created spearate function for "paramters menu" and made loop for Start button. I don't udnerstand why it cannot get out of the loop - I guess it causes other buttons inactive? What am I missing here? Also I don't understand the way how GUIGetMsg works. I saw it's always used in GUI AutoIT manuals and examples. How should I properly manipulate values in the brackets?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <FileConstants.au3>
#include <WinAPIFiles.au3>
#include <File.au3>
#include <AutoItConstants.au3>



Global $Address
Global $Protocol

$Menu = GUICreate("INTERNET APPS", 500, 200, -1, -1)
$ButtonFF = GUICtrlCreateButton("Mozilla FireFox", 10, 20, 200, 50)
$ButtonCH = GUICtrlCreateButton("Google Chrome", 10, 80, 200, 50)
$ButtonIE = GUICtrlCreateButton("Microsoft Edge", 10, 140, 200, 50)
GUISetState(@SW_SHOW)


While 1
   Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
         Exit
      Case $ButtonFF
         GUICtrlCreateLabel("Mozilla Firefox parameters", 250, 20, 200, 20)
         Params()

      Case $ButtonCH
         GUICtrlCreateLabel("Google Chrome parameters", 250, 20, 200, 20)
         Params()
   EndSwitch
WEnd

Func Params()
   GUICtrlCreateLabel("Enter address:", 250, 60, 200, 20)
   $InputAdd = GUICtrlCreateInput("", 250, 80, 200, 20)
   GUICtrlCreateLabel("Enter protocol:", 250, 110, 200, 20)
   $InputProt = GUICtrlCreateInput("", 250, 130, 200, 20)
   $ButtonStart = GUICtrlCreateButton("Start", 250, 170, 100, 20)
   While 1
      Switch GUIGetMsg()
         Case $GUI_EVENT_CLOSE
            Exit
         Case $ButtonStart
            $InputReadAdd = GUICtrlRead($InputAdd)
            $InputReadProt = GUICtrlRead($InputProt)
            If $InputReadAdd = "" Or $InputReadProt = "" Then
               MsgBox(1, "Error", "Address and Protocol required")
            EndIf

      EndSwitch
   WEnd
EndFunc

 

Edited by JLogan3o13
Link to post
Share on other sites

You cannot have 2 embedded loops within a single GUI.  That is your main problem.  I would not create those params over and over, if the user chooses to open multiple browsers.  I would create it at beginning with hide state.  Then show the params as needed without recreating them. 

And please use this tool, when you post code.

Edited by Nine
Link to post
Share on other sites
Func Params()
   GUICtrlCreateLabel("Enter address:", 250, 60, 200, 20)
   $InputAdd = GUICtrlCreateInput("", 250, 80, 200, 20)
   GUICtrlCreateLabel("Enter protocol:", 250, 110, 200, 20)
   $InputProt = GUICtrlCreateInput("", 250, 130, 200, 20)
   $ButtonStart = GUICtrlCreateButton("Start", 250, 170, 100, 20)
      Switch GUIGetMsg()
         Case $ButtonStart
            $InputReadAdd = GUICtrlRead($InputAdd)
            $InputReadProt = GUICtrlRead($InputProt)
            If $InputReadAdd = "" Or $InputReadProt = "" Then
               MsgBox(1, "Error", "Address and Protocol required")
            EndIf
      EndSwitch
EndFunc

As the #Nine master said, you used two while, and when you removed one, it got better.

Link to post
Share on other sites
1 hour ago, Nine said:

You cannot have 2 embedded loops within a single GUI.  That is your main problem.  I would not create those params over and over, if the user chooses to open multiple browsers.  I would create it at beginning with hide state.  Then show the params as needed without recreating them. 

And please use this tool, when you post code.

The goal si to close and exit GUI after browser starts. But still it's good to have option of free choise between buttons before launching browser.

 

I was also testing with @SH_HIDE in the beginning but won't this make the additional "unnecessary" GUIs in the background? I also didn't want to repeat function of GUI creation 3 times and simplify the code.

Edited by Ghost1982
Link to post
Share on other sites
1 hour ago, mucitbey said:
Func Params()
   GUICtrlCreateLabel("Enter address:", 250, 60, 200, 20)
   $InputAdd = GUICtrlCreateInput("", 250, 80, 200, 20)
   GUICtrlCreateLabel("Enter protocol:", 250, 110, 200, 20)
   $InputProt = GUICtrlCreateInput("", 250, 130, 200, 20)
   $ButtonStart = GUICtrlCreateButton("Start", 250, 170, 100, 20)
      Switch GUIGetMsg()
         Case $ButtonStart
            $InputReadAdd = GUICtrlRead($InputAdd)
            $InputReadProt = GUICtrlRead($InputProt)
            If $InputReadAdd = "" Or $InputReadProt = "" Then
               MsgBox(1, "Error", "Address and Protocol required")
            EndIf
      EndSwitch
EndFunc

As the #Nine master said, you used two while, and when you removed one, it got better.

Ok, but now Start button seems to be inactive after I've removed While 1. Like it's not detected.

Link to post
Share on other sites

Something like that perhaps :

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <FileConstants.au3>
#include <WinAPIFiles.au3>
#include <File.au3>
#include <AutoItConstants.au3>

Global $Address
Global $Protocol

$Menu = GUICreate("INTERNET APPS", 500, 200, -1, -1)
$ButtonFF = GUICtrlCreateButton("Mozilla FireFox", 10, 20, 200, 50)
$ButtonCH = GUICtrlCreateButton("Google Chrome", 10, 80, 200, 50)
$ButtonIE = GUICtrlCreateButton("Microsoft Edge", 10, 140, 200, 50)

$lab0 = GUICtrlCreateLabel("", 250, 20, 200, 20)
GUICtrlSetState(-1, $GUI_HIDE)
$lab1 = GUICtrlCreateLabel("Enter address:", 250, 60, 200, 20)
GUICtrlSetState(-1, $GUI_HIDE)
$InputAdd = GUICtrlCreateInput("", 250, 80, 200, 20)
GUICtrlSetState(-1, $GUI_HIDE)
$lab2 = GUICtrlCreateLabel("Enter protocol:", 250, 110, 200, 20)
GUICtrlSetState(-1, $GUI_HIDE)
$InputProt = GUICtrlCreateInput("", 250, 130, 200, 20)
GUICtrlSetState(-1, $GUI_HIDE)
$ButtonStart = GUICtrlCreateButton("Start", 250, 170, 100, 20)
GUICtrlSetState(-1, $GUI_HIDE)

GUISetState(@SW_SHOW)

While 1
  $nMsg = GUIGetMsg()
  Switch $nMsg
    Case $GUI_EVENT_CLOSE
      Exit
    Case $ButtonFF, $ButtonCH
      $browser = GUICtrlRead($nMsg)
      GUICtrlSetData($lab0, $browser & " parameters")
      For $i = $lab0 to $ButtonStart
        GUICtrlSetState($i, $GUI_SHOW)
      Next
    Case $ButtonStart
      $InputReadAdd = GUICtrlRead($InputAdd)
      $InputReadProt = GUICtrlRead($InputProt)
      If $InputReadAdd = "" Or $InputReadProt = "" Then
        MsgBox(1, "Error", "Address and Protocol required")
      Else
        ConsoleWrite ("Starting " & $browser & @CRLF)
      EndIf
  EndSwitch
WEnd

 

Link to post
Share on other sites

You could do a similar loop to hide all params, would make your code more compact, instead of repeating the same line for each one...

Link to post
Share on other sites
4 minutes ago, Nine said:

Something like that perhaps :

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <FileConstants.au3>
#include <WinAPIFiles.au3>
#include <File.au3>
#include <AutoItConstants.au3>

Global $Address
Global $Protocol

$Menu = GUICreate("INTERNET APPS", 500, 200, -1, -1)
$ButtonFF = GUICtrlCreateButton("Mozilla FireFox", 10, 20, 200, 50)
$ButtonCH = GUICtrlCreateButton("Google Chrome", 10, 80, 200, 50)
$ButtonIE = GUICtrlCreateButton("Microsoft Edge", 10, 140, 200, 50)

$lab0 = GUICtrlCreateLabel("", 250, 20, 200, 20)
GUICtrlSetState(-1, $GUI_HIDE)
$lab1 = GUICtrlCreateLabel("Enter address:", 250, 60, 200, 20)
GUICtrlSetState(-1, $GUI_HIDE)
$InputAdd = GUICtrlCreateInput("", 250, 80, 200, 20)
GUICtrlSetState(-1, $GUI_HIDE)
$lab2 = GUICtrlCreateLabel("Enter protocol:", 250, 110, 200, 20)
GUICtrlSetState(-1, $GUI_HIDE)
$InputProt = GUICtrlCreateInput("", 250, 130, 200, 20)
GUICtrlSetState(-1, $GUI_HIDE)
$ButtonStart = GUICtrlCreateButton("Start", 250, 170, 100, 20)
GUICtrlSetState(-1, $GUI_HIDE)

GUISetState(@SW_SHOW)

While 1
  $nMsg = GUIGetMsg()
  Switch $nMsg
    Case $GUI_EVENT_CLOSE
      Exit
    Case $ButtonFF, $ButtonCH
      $browser = GUICtrlRead($nMsg)
      GUICtrlSetData($lab0, $browser & " parameters")
      For $i = $lab0 to $ButtonStart
        GUICtrlSetState($i, $GUI_SHOW)
      Next
    Case $ButtonStart
      $InputReadAdd = GUICtrlRead($InputAdd)
      $InputReadProt = GUICtrlRead($InputProt)
      If $InputReadAdd = "" Or $InputReadProt = "" Then
        MsgBox(1, "Error", "Address and Protocol required")
      Else
        ConsoleWrite ("Starting " & $browser & @CRLF)
      EndIf
  EndSwitch
WEnd

 

Thansk I wil ltest it.

 

Can you explain me the role of GUIGetMsg? How should I know when to use empty bracket, 0 or 1? In my case I've used () becasue I saw it in example scripts of AutoIT and...fortunetly it worked. But then I saw also the examples with numbers within brackets

Edited by Ghost1982
Link to post
Share on other sites

Well I think help file is pretty clear on that.  But GUIGetMsg gets the messages when any event is happening.  it useless to use advance parameter when you got only one main GUI.  

Edited by Nine
Link to post
Share on other sites
17 minutes ago, Nine said:

Well I think help file is pretty clear on that.  But GUIGetMsg gets the messages when any event is happening.  it useless to use advance parameter when you got only one main GUI.  

In your way of script why it was necessary to assing GUIGetMsg  to variable instead  using "Switch GUIGetMsg" ?

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.

×
×
  • Create New...