Sign in to follow this  
Followers 0
Wolfteeth

How can GUI_EVENT_CLOSE works?

4 posts in this topic

#1 ·  Posted (edited)

How can GUI_EVENT_CLOSE works? I cann't click CLOSE button to close the window.

it seems the window's CLOSE button doens't work, that's so strange.....

just stupid stop at the window close event and seems not well have direct solution so far, would have anybody who can help to take a look and can have any recommendation? thanks in advance.

the list.txt file is just a simple text file, maybe multiple lines..1.2.3.4. balabala...

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 625, 445, 193, 125)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
  case Else
   _SMON()
    EndSwitch
WEnd
GUIDelete()
Func _SMON()
$file = FileOpen("list.txt", 0)
If $file = -1 Then
  MsgBox(0, "Error", "Unable to open file.")
  Exit
EndIf
TrayTip($file, "Daemon will start checking now...",1)
sleep(1000)
EndFunc
Edited by Wolfteeth

Share this post


Link to post
Share on other sites



$GUI_EVENT_CLOSE is just a variable assigned as Control ID of Close button for AutoIt GUI's

Your script implies that if Close button is pressed, then the script should exit, if any other control except close button is pressed (be it even labels and input controls), the script will execute _SMON()

By the way, are you interested in reading file's contents, if so then Use FileRead() function


----------------------------------------

:bye: Hey there, was I helpful?

----------------------------------------

My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You can close the window fine, you are just impatient. You Sleep() for one second so you are only checking one message per second. Imagine that there are 10 messages before your EVENT_CLOSE, that means a 10 second wait. You receive window messages literally all the time, like for moving your mouse, so it could be more or less.

There simply must not be any long Sleep() in the GUIGetMsg() loop. Use Timers and/or Adlib for timekeeping. Also you should FileClose() the handle from FileOpen().

Edit: timers/adlib

Edited by AdmiralAlkex

Share this post


Link to post
Share on other sites

many thanks for the above comments, yes, If I remove the line: sleep(1000), then it works, however, actually, it's just one simple test code, not the code I am doing, but my code is somehow complex and I am now have to use TrayOnEvent to close the window. my question is under same situation that TrayItemSetOnEvent works on the exit function, but $GUI_EVENT_CLOSE doesn't, so is there's any solution can apply to the CLOSE button to make it works?

P.S. the Func _SMON() actually will call SNMP udf and start listener, then read the IP from the list.txt and then get the SNMP through OID return UPS status one by one, there's no break inside the readling and it will repeat the behaviour until click CLOSE button or click Exit Menu under TRAY.

Share this post


Link to post
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
Sign in to follow this  
Followers 0