Ghost1982 Posted November 4, 2020 Share Posted November 4, 2020 (edited) 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. 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? expandcollapse popup#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 November 4, 2020 by JLogan3o13 Link to comment Share on other sites More sharing options...
Nine Posted November 4, 2020 Share Posted November 4, 2020 (edited) 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 November 4, 2020 by Nine “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...
mucitbey Posted November 4, 2020 Share Posted November 4, 2020 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 comment Share on other sites More sharing options...
Ghost1982 Posted November 4, 2020 Author Share Posted November 4, 2020 (edited) 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 November 4, 2020 by Ghost1982 Link to comment Share on other sites More sharing options...
Ghost1982 Posted November 4, 2020 Author Share Posted November 4, 2020 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 comment Share on other sites More sharing options...
Nine Posted November 4, 2020 Share Posted November 4, 2020 Something like that perhaps : expandcollapse popup#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 “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...
Nine Posted November 4, 2020 Share Posted November 4, 2020 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... “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...
Ghost1982 Posted November 4, 2020 Author Share Posted November 4, 2020 (edited) 4 minutes ago, Nine said: Something like that perhaps : expandcollapse popup#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 November 4, 2020 by Ghost1982 Link to comment Share on other sites More sharing options...
Nine Posted November 4, 2020 Share Posted November 4, 2020 (edited) 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 November 4, 2020 by Nine “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...
Ghost1982 Posted November 4, 2020 Author Share Posted November 4, 2020 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 comment Share on other sites More sharing options...
Nine Posted November 4, 2020 Share Posted November 4, 2020 Because I am using the variable ($nMsg) later to retrieve which button that have been pressed “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...
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