johnnybravo Posted July 3, 2010 Share Posted July 3, 2010 Hello there, I just started using AutoIt so i'm kind of new into programming. I have a problem with closing a window. I searched the forums and the AutoIt Help file over and over, but i can't find out what i'm doing wrong here? My Script: #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) $mainWindow = GUICreate("my Window", 250, 150 ) $settings = GUICtrlCreateButton("Settings", 10, 100, 72.5, 30 ) GUICtrlSetOnEvent($settings, "changeSettings") GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE,"exitProgram") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func changeSettings() $settingswindow = GUICreate("Settings", 200, 100 ) GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE, WinClose("")) EndFunc Func exitProgram() Exit EndFunc Hope one of you guys is able to help me. Cheers, JohnnyB Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 3, 2010 Moderators Share Posted July 3, 2010 johnnybravo,Welcome to the AutoIt forum. Your window would not close because you need to put a function name into an GUISetOnEvent/GUICtrlSetOnEvent statement, not a command like WinClose.This shows how you should do it: #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) Global $settingswindow $mainWindow = GUICreate("my Window", 250, 150 ) $settings = GUICtrlCreateButton("Settings", 10, 100, 72.5, 30 ) GUICtrlSetOnEvent($settings, "changeSettings") GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE,"exitProgram") While 1 Sleep(10) ; In OnEvent mode you must have a short Sleep in this loop or you eat up CPU cycles <<<<<<<<< WEnd Func changeSettings() $settingswindow = GUICreate("Settings", 200, 100 ) GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE, "Close_Settings") : you needed a function name here <<<<<<<<<<<< EndFunc Func exitProgram() Exit EndFunc Func Close_Settings() GUIDelete($settingswindow) EndFuncAnother point to bear in mind is that you were trying to mix OnEvent mode with GetMessage mode. You cannot - you must use one or the other. The script above uses OnEvent mode - this one does exactly the same thing, but uses GetMessage mode:#include <GUIConstantsEx.au3> Global $settingswindow = 9999 $mainWindow = GUICreate("my Window", 250, 150 ) $settings = GUICtrlCreateButton("Settings", 10, 100, 72.5, 30 ) GUISetState(@SW_SHOW) While 1 $aMsg = GUIGetMsg(1) Switch $aMsg[1] Case $mainWindow Switch $aMsg[0] Case $GUI_EVENT_CLOSE Exit Case $settings $settingswindow = GUICreate("Settings", 200, 100 ) GUISetState(@SW_SHOW) EndSwitch Case $settingswindow Switch $aMsg[0] Case $GUI_EVENT_CLOSE GUIDelete($settingswindow) EndSwitch EndSwitch WEndTry and work out how each of them works. There are pros and cons to each method - you have to decide which is best for the particular task you are trying to do. As you seem pretty new to all this, could I strongly recommend that re-reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) - this will help you enormously. You should also look at the excellent tutorials that you will find here and here - you will find other tutorials in the Wiki (the link is at the top of the page). There are even video tutorials on YouTube if you prefer watching to reading.Enjoy AutoIt - you know where we are when you run into difficulties. M23 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 Link to comment Share on other sites More sharing options...
johnnybravo Posted July 3, 2010 Author Share Posted July 3, 2010 (edited) Hello Melba23, Thanks for your fast reply and your extensive advice. realy appreciate it! JohhnyBravo Edited July 3, 2010 by johnnybravo 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