eson Posted April 20, 2010 Posted April 20, 2010 Hello, I'm trying to make a simple GUI that when a button is pressed a second GUI appears. In the second GUI (that also has a button) if I click the button I see a message. That is all. I really don't know what is wrong with my very simple script. The problem is that when the second GUI appears, it is unresponsive. I click the button and nothing... The little code is below. Could you help me? expandcollapse popup#include <GUIConstants.au3> #include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> Opt("GUIOnEventMode", 1) $MainGUI = GUICreate("Main", 190, 49, 570, 115) GUISetOnEvent($GUI_EVENT_CLOSE, "End") $MainButton = GUICtrlCreateButton("Main OK", 12, 12, 75, 25) GUICtrlSetOnEvent($MainButton, "CreateSecondGUI") GUISetState(@SW_SHOW) While 1 Sleep(100) WEnd Func CreateSecondGUI() $SecondGUI = GUICreate("Second", 190, 49, 570, 215) GUISetOnEvent($GUI_EVENT_CLOSE, "End") $SecondButton = GUICtrlCreateButton("Second OK", 12, 12, 75, 25) GUICtrlSetOnEvent($SecondButton, "OK") GUISetState(@SW_SHOW) While 1 Sleep(100) WEnd EndFunc Func OK() MsgBox(0, "", "Child OK pressed") EndFunc Func End() MsgBox(0, "", "The End") Exit EndFunc
Yoriz Posted April 20, 2010 Posted April 20, 2010 Hi Your code get stuck in the loop inside Func CreateSecondGUI(), you dont need a loop there the first loop you created will take care of it, ive commented the 2nd loop out so it works as you intended. expandcollapse popup#include <GUIConstants.au3> #include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> Opt("GUIOnEventMode", 1) $MainGUI = GUICreate("Main", 190, 49, 570, 115) GUISetOnEvent($GUI_EVENT_CLOSE, "End") $MainButton = GUICtrlCreateButton("Main OK", 12, 12, 75, 25) GUICtrlSetOnEvent($MainButton, "CreateSecondGUI") GUISetState(@SW_SHOW) While 1 Sleep(100) WEnd Func CreateSecondGUI() $SecondGUI = GUICreate("Second", 190, 49, 570, 215) GUISetOnEvent($GUI_EVENT_CLOSE, "End") $SecondButton = GUICtrlCreateButton("Second OK", 12, 12, 75, 25) GUICtrlSetOnEvent($SecondButton, "OK") GUISetState(@SW_SHOW) ;~ While 1 ;~ Sleep(100) ;~ WEnd EndFunc Func OK() MsgBox(0, "", "Child OK pressed") EndFunc Func End() MsgBox(0, "", "The End") Exit EndFunc GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
eson Posted April 20, 2010 Author Posted April 20, 2010 Thank you Yoriz, I see that removing the second loop it works. But I really don't understand why!! If I understand well, the command GUICtrlSetOnEvent($SecondButton, "OK") means that the 'OK' function should be called when the SecondButton is pressed. So, why the message on the 'OK' function never appears? Why while in the loop (the commented second loop) the function 'OK' is not activated when I press the SecondButton? What the first loop has that the second don't? Why while in the first loop the 'OK' function is called and while in the second loop it is not? I think that because of the command GUICtrlSetOnEvent($SecondButton, "OK") the ‘OK’ function should be called whenever I press the SecondButton and return to the point it was after the function finish. I see that in my example script I'm stucked in the second loop because there is no way to escape the loop. But I think that at least the function 'OK' should be activated (while in the second loop) when I press the SecondButton. Could you help me understand this? Thank you.
Yoriz Posted April 20, 2010 Posted April 20, 2010 (edited) I think it is because the next event cant be triggered until it ends the function the the first event triggered, so its stuck in the second loop. if you move the CreateSecondGUI function out of the triggered function like below it will do as your expecting. But doing this is probably bad pratice, as far as i know you only need the one loop when using oneventmode. expandcollapse popupOpt("GUIOnEventMode", 1) $MainGUI = GUICreate("Main", 190, 49, 570, 115) GUISetOnEvent($GUI_EVENT_CLOSE, "End") $MainButton = GUICtrlCreateButton("Main OK", 12, 12, 75, 25) GUICtrlSetOnEvent($MainButton, "_SetTrue") GUISetState(@SW_SHOW) Global $fCreatesecondGUI = False Func _SetTrue() $fCreatesecondGUI = True EndFunc While 1 If $fCreatesecondGUI Then CreateSecondGUI() Sleep(100) WEnd Func CreateSecondGUI() $fCreatesecondGUI = False $SecondGUI = GUICreate("Second", 190, 49, 570, 215) GUISetOnEvent($GUI_EVENT_CLOSE, "End") $SecondButton = GUICtrlCreateButton("Second OK", 12, 12, 75, 25) GUICtrlSetOnEvent($SecondButton, "OK") GUISetState(@SW_SHOW) While 1 Sleep(100) WEnd EndFunc Func OK() MsgBox(0, "", "Child OK pressed") EndFunc Func End() MsgBox(0, "", "The End") Exit EndFunc Edited April 20, 2010 by Yoriz GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
eson Posted April 21, 2010 Author Posted April 21, 2010 Thank you again Yoriz! You are right, while the function called by the first GUI don't finish (returns), the second GUI never trigger a function! This is not documented and it is not intuitive, at last for me. I think that if you create a GUI with a control that trigger a function, is shoul be that way! The control must call the function. I dont see the reason why the function is not called. I mean, I see the fact (the trigger dont work because the GUI was created iside a function trigged by a previous GUI) but I think it is not suposed to be that way. Maybe someone from AutoIt could help with that. Thank you again! Now I know what was wrong and will work with the facts.
Realm Posted April 26, 2010 Posted April 26, 2010 Hi Your code get stuck in the loop inside Func CreateSecondGUI(), you dont need a loop there the first loop you created will take care of it, ive commented the 2nd loop out so it works as you intended. expandcollapse popup#include <GUIConstants.au3> #include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> Opt("GUIOnEventMode", 1) $MainGUI = GUICreate("Main", 190, 49, 570, 115) GUISetOnEvent($GUI_EVENT_CLOSE, "End") $MainButton = GUICtrlCreateButton("Main OK", 12, 12, 75, 25) GUICtrlSetOnEvent($MainButton, "CreateSecondGUI") GUISetState(@SW_SHOW) While 1 Sleep(100) WEnd Func CreateSecondGUI() $SecondGUI = GUICreate("Second", 190, 49, 570, 215) GUISetOnEvent($GUI_EVENT_CLOSE, "End") $SecondButton = GUICtrlCreateButton("Second OK", 12, 12, 75, 25) GUICtrlSetOnEvent($SecondButton, "OK") GUISetState(@SW_SHOW) ;~ While 1 ;~ Sleep(100) ;~ WEnd EndFunc Func OK() MsgBox(0, "", "Child OK pressed") EndFunc Func End() MsgBox(0, "", "The End") Exit EndFunc This is great, I was just looking for a solution to my script that this almost answers. However while I was testing this script, I noticed that when you close the second gui, it also closes all the other windows, how could this be coded, to only close the second gui when you click the X(close) on it, while keeping the main(first) gui running? My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.
Moderators Melba23 Posted April 26, 2010 Moderators Posted April 26, 2010 Realm,Change the End function to check which GUI sent the GUI_EVENT_CLOSE message: Func End() Switch @GUI_WINHANDLE Case $MainGUI MsgBox(0, "", "The End") Exit Case $SecondGUI GUIDelete($SecondGUI) EndSwitch EndFunc ;==>EndM23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Realm Posted April 26, 2010 Posted April 26, 2010 Realm, Change the End function to check which GUI sent the GUI_EVENT_CLOSE message: Func End() Switch @GUI_WINHANDLE Case $MainGUI MsgBox(0, "", "The End") Exit Case $SecondGUI GUIDelete($SecondGUI) EndSwitch EndFunc ;==>End M23 That is perfect, Thank you very much for your fast reply! My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.
Realm Posted June 23, 2010 Posted June 23, 2010 I was playing with this on another script. However I cam accross another problem. When I close or use the 2nd Gui it will not focus back to the MainGui. The button will not work. I noticed this on my new script, where it has 4 buttons. 1)Run Program 2)Options, which opens a config panel aka 2nd GUI 3)Pause 4)Exit. After running program, The Pause and Exit buttons do not work. And if I click Options, set the configuration and save it, than I go back to Main GUI, and the Start Program button will not work. How can I bring the focus back to the MainGUI or maybe set the buttons to something like a Hotkey? My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.
GEOSoft Posted June 24, 2010 Posted June 24, 2010 Realm, See GUISwitch() George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
Realm Posted June 24, 2010 Posted June 24, 2010 (edited) Thanks GEOSoft for a quick reply. Thanks that will fix part of the probelm. However Part b of my problem, is that after I press Run Program, and it does, I can't get the focus back to the MainGUI. The Program runs through a series of functions, and even RunWaits other programs, but is an ever continuous loop, where sometimes I need to pause, or completely exit the application. I have included Hotkey's for these functions in the script, however I would like for the buttons to work as well. The only ways I see this working with GUISwitch, is adding that to every function, but would'nt that stop the scripts from it's loop? Edit: Sorry I just now realized, that I did not completely clarify this problem in my previous post. Edited June 24, 2010 by Realm My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.
GEOSoft Posted June 24, 2010 Posted June 24, 2010 You just create a _Return() function that does all the cleanup including GUISwitch(Frm1) George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
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