MariusN Posted October 29, 2009 Share Posted October 29, 2009 First off, sorry Admin. I have posted this in the GENERAL help section only to find out there is a special section for GUI's... Below is a Script i have a slight problem with. If i have both GUI's running, I can't seem to get the button called "$hello" to work in the first Gui. If i CLOSE the 2nd GUI for instance, the $hello-button will function. Is there a way around this? What i mean is, is it possible in AutoIt to have 2 Menus running and be able to work on both without having to close either one? tia #include <GUIConstantsEx.au3> Local $MSG, $menu2, $ok1, $menu1, $go, $hello, $main message() Func message() $main = GUICreate("First", 200, 260, 210, 350) $menu2 = GUICtrlCreateButton("Manu2", 60, 35, 80, 20) $hello = GUICtrlCreateButton("Shows Hello", 60, 130, 80, 20) GUISetState() ; will display an empty dialog box While 1 $MSG = GUIGetMsg() Select Case $MSG = $GUI_EVENT_CLOSE ExitLoop Case $MSG = $menu2 message2() Case $MSG = $hello MsgBox(0, "", "Hello") EndSelect WEnd EndFunc ;==>message Func message2() GUICreate("Second", 200, 160, 610, 350) $menu1 = GUICtrlCreateButton("Shows OK", 60, 35, 80, 20) GUISetState() While 1 $MSG = GUIGetMsg() Select Case $MSG = $GUI_EVENT_CLOSE ExitLoop Case $MSG = $menu1 MsgBox(0, "", "OK") EndSelect WEnd GUIDelete() EndFunc Link to comment Share on other sites More sharing options...
martin Posted October 29, 2009 Share Posted October 29, 2009 First off, sorry Admin. I have posted this in the GENERAL help section only to find out there is a special section for GUI's... Below is a Script i have a slight problem with. If i have both GUI's running, I can't seem to get the button called "$hello" to work in the first Gui. If i CLOSE the 2nd GUI for instance, the $hello-button will function. Is there a way around this? What i mean is, is it possible in AutoIt to have 2 Menus running and be able to work on both without having to close either one? tia #include <GUIConstantsEx.au3> Local $MSG, $menu2, $ok1, $menu1, $go, $hello, $main message() Func message() $main = GUICreate("First", 200, 260, 210, 350) $menu2 = GUICtrlCreateButton("Manu2", 60, 35, 80, 20) $hello = GUICtrlCreateButton("Shows Hello", 60, 130, 80, 20) GUISetState() ; will display an empty dialog box While 1 $MSG = GUIGetMsg() Select Case $MSG = $GUI_EVENT_CLOSE ExitLoop Case $MSG = $menu2 message2() Case $MSG = $hello MsgBox(0, "", "Hello") EndSelect WEnd EndFunc ;==>message Func message2() GUICreate("Second", 200, 160, 610, 350) $menu1 = GUICtrlCreateButton("Shows OK", 60, 35, 80, 20) GUISetState() While 1 $MSG = GUIGetMsg() Select Case $MSG = $GUI_EVENT_CLOSE ExitLoop Case $MSG = $menu1 MsgBox(0, "", "OK") EndSelect WEnd GUIDelete() EndFunc You simply need to add a case statement in your function because once you call th efunction you don't leave it untill the second gui is closed and you never check to see if a button on the first gui is pressed. So this version of your function would work Func message2() $minor = GUICreate("Second", 200, 160, 610, 350) $menu1 = GUICtrlCreateButton("Shows OK", 60, 35, 80, 20) GUISetState() While 1 $MSG = GUIGetMsg() Select Case $MSG = $GUI_EVENT_CLOSE ExitLoop Case $MSG = $menu1 MsgBox(0, "", "OK") Case $MSG = $hello MsgBox(0, "", "Hello") EndSelect WEnd GUIDelete() EndFunc ;==>message2 However it is still a little faulty. It might be better to make all the controls Global, only use the function to create the window and then exit and check the events in one message loop. You need to know which window is generating the messages because in response to GUI_EVENT_CLOSE you might close the wrong window in error. Look up the advanced parameter for GuiGetMsg, then split the loop into a section for each window, something like this $MSG = GuiGetMsg(1) switch $MSG[1];the window Case $main switch $MSG[0];the event . . EndSwitch Case $minor Switch $MSG[0] Case ... EndSwitch EndSwitch Perhaps a better approach is to use OnEvent Mode then it is simpler. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
MariusN Posted October 29, 2009 Author Share Posted October 29, 2009 Thanks Martin...Will have a look at your code and suggestions 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