SoulBlade Posted February 23, 2008 Share Posted February 23, 2008 The following code creates GUI1 with a single button called Run1. When Run1 is pressed a new GUI2 is created, with only a button called Run2. When i press Run2, GUI2 is closed; only GUI1 remains. Now with only GUI1 openned, i need to press 2 times to exit or 2 times to press Run1 again. Does anyone know how to make GUI1 work with only 1 click after RUN2 is pressed? Thanks for your help! CODE#include <GUIConstants.au3> #include <IE.au3> $Gui=GUICreate("GUI1",514, 325) $r=GUICtrlCreateButton("Run1", 207, 265, 100, 30) GUISetState () Do $msg = GUIGetMsg() Select Case $msg=$r window2() Case $msg= $GUI_EVENT_CLOSE EndSelect Until $msg = $GUI_EVENT_CLOSE Func window2() $rb=GUICreate("GUI2", 514, 325,-1,-1) $Run = GUICtrlCreateButton("Run2", 207, 265, 100, 30) GUISetState() Do $msgrb = GUIGetMsg() Select Case $msgrb= $Run GUIDelete($rb) Case $msgrb= $GUI_EVENT_CLOSE GUIDelete($rb) EndSelect Until $msgrb = $GUI_EVENT_CLOSE GUIDelete($rb) EndFunc Link to comment Share on other sites More sharing options...
martin Posted February 23, 2008 Share Posted February 23, 2008 The following code creates GUI1 with a single button called Run1.When Run1 is pressed a new GUI2 is created, with only a button called Run2.When i press Run2, GUI2 is closed; only GUI1 remains.Now with only GUI1 openned, i need to press 2 times to exit or 2 times to press Run1 again. Does anyone know how to make GUI1 work with only 1 click after RUN2 is pressed?Thanks for your help! CODE#include <GUIConstants.au3>#include <IE.au3>$Gui=GUICreate("GUI1",514, 325)$r=GUICtrlCreateButton("Run1", 207, 265, 100, 30)GUISetState ()Do $msg = GUIGetMsg() Select Case $msg=$r window2()Case $msg= $GUI_EVENT_CLOSEEndSelectUntil $msg = $GUI_EVENT_CLOSEFunc window2()$rb=GUICreate("GUI2", 514, 325,-1,-1)$Run = GUICtrlCreateButton("Run2", 207, 265, 100, 30)GUISetState()Do $msgrb = GUIGetMsg() Select Case $msgrb= $RunGUIDelete($rb)Case $msgrb= $GUI_EVENT_CLOSEGUIDelete($rb)EndSelectUntil $msgrb = $GUI_EVENT_CLOSEGUIDelete($rb)EndFuncI don't get that problem when I run your code. One press to close or start GUI2 again. BUt why have the GUIDelete in 2 places? 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...
SoulBlade Posted February 23, 2008 Author Share Posted February 23, 2008 I don't get that problem when I run your code. One press to close or start GUI2 again. BUt why have the GUIDelete in 2 places?Thanks. Well i need do close GUI2 after pressing Run2. You're right i dont need 2 GUIDelete.However my problem still persists - after pressing Run2 i need to press the "X" icon 2 times to close GUI1.It's a small detail but is annoying me...Any more ideias? Link to comment Share on other sites More sharing options...
martin Posted February 23, 2008 Share Posted February 23, 2008 Thanks. Well i need do close GUI2 after pressing Run2. You're right i dont need 2 GUIDelete.However my problem still persists - after pressing Run2 i need to press the "X" icon 2 times to close GUI1.It's a small detail but is annoying me...Any more ideias?The only reason I can guess that you have the problem is that $GUI does not have the focus after GUI2 closes. So to see if this is correct add WinActivate($gui) after deleting GUI2. 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...
Siao Posted February 23, 2008 Share Posted February 23, 2008 When i press Run2, GUI2 is closed; only GUI1 remains.When you press $Run2, GUI2 is deleted, but the execution stays in the 2nd loop, because loop exit condition is (Until $msgrb = $GUI_EVENT_CLOSE) and clicking $Run2 obviously does not generate $GUI_EVENT_CLOSE message. While it stays in 2nd loop, it obviously does not execute conditions from your 1st loop, so GUI1 is unresponsive. instead of Case $msgrb= $Run GUIDelete($rb) Case $msgrb= $GUI_EVENT_CLOSE GUIDelete($rb) EndSelect Until $msgrb = $GUI_EVENT_CLOSE GUIDelete($rb) which doesn't make much sense to begin with, you could do Case $msgrb= $Run ExitLoop Case $msgrb= $GUI_EVENT_CLOSE ExitLoop EndSelect Until $msgrb = $GUI_EVENT_CLOSE GUIDelete($rb) Anyway, having more than one message loop in your app is not a very good decision. See GuiGetMsg() documentation about handling multiple GUIs. "be smart, drink your wine" Link to comment Share on other sites More sharing options...
SoulBlade Posted February 23, 2008 Author Share Posted February 23, 2008 (edited) You're right! That solved the problem. I'll use GuiGetMsg() in the future. Thanks for your support! Edited February 23, 2008 by SoulBlade 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