Jump to content

Cannot exit gui nor stop a portion of code


Recommended Posts

Hey all. I've recently started learning AutoIt, and creating a GUI was the first on the list of things to learn. However, I'm stuck: when I click start on my GUI, the portion of code that happens when that event is processed proceeds as normal, but I cannot exit the window nor can I stop the portion of code. I can't debug the code myself because it seems fine to me. Can someone help please? Thanks.

#include <GUIConstantsEx.au3>
$kevinGUI = GUICreate("AutoIt GUI Example", 335, 100) ;creates GUI box with dimensions (x,y)
GUISetState(@SW_SHOW) ;displays the actual GUI box.
GUICtrlCreateLabel("Buff 1", 8, 10) ;create a text label
$buff1 = GUICtrlCreateInput("", 35, 8, 120) ;creates an input box at position (x,y) and width z
GUICtrlCreateLabel("Time", 8, 44)
$buffDuration1 = GUICtrlCreateInput("", 35, 40, 120)
$startButton = GUICtrlCreateButton("Start", 190, 8, 60) ;creates button at position (x,y) and width z
$stopButton = GUICtrlCreateButton("Stop", 260, 8, 60) ;creates stop button at position (x,y) and width z
$buff1Timer = TimerInit()
While 1
   $getEvent = GUIGetMsg() ;continuously checks to see if new events take place
case $getEvent = $startButton ;if event is start button has been clicked
$sendBuff1 = GUICtrlRead($buff1) ;save whatever was typed inside buff1 to variable sendBuff1
$sendBuffDuration1 = GUICtrlRead($buffDuration1) * 1000 ;save whatever was typed inside buffDuration1 to variable sendBuffDuration1
While 1
   $buff1TimePassed = TimerDiff($buff1Timer)
If $buff1TimePassed > ($sendBuffDuration1) Then
  $buff1Timer = TimerInit()
   case $getEvent = $stopButton
   case $getEvent = $GUI_EVENT_CLOSE ;if event is clicking on [x] button in window
ExitLoop ;exit any loops
GUIDelete($kevinGUI) ;close the window
Link to comment
Share on other sites

  • Moderators


Welcome to the AutoIt forums. :)

The reason you find your GUI unresponsive is because once the inner loop (lines 26-34) is entered you have no way of exiting, and so you never check for events after the loop has started. What you need to do is check for events inside that loop. :)

And as this is essentially a spam script, please make sure you read the Forum rules (there is also a link at bottom right of each page) - before you post again. ;)


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...