Sign in to follow this  
Followers 0
TheBreeder

OnEvent not executed when $GUI_EVENT_CLOSE

7 posts in this topic

I open 2 windows and open a third when a button is pressed. The OnEvent for $GUI_CLOSE_EVENT is no longer working when the third window is open. It works fine when the first two windows are open. But once the thirs is opend, the event is no longer executed.

<#include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

#include <Array.au3>

;Global $Form2_1, $Form3_1,

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

$Form1 = GUICreate("Form1", 633, 447, 193, 125)

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

$Button1 = GUICtrlCreateButton("Button1", 24, 24, 89, 25, 0)

GUICtrlSetOnEvent(-1, "Button1")

GUISetState()

$Form2_1 = GUICreate("Form2", 633, 447, 193, 125, BitOR($WS_OVERLAPPEDWINDOW, $WS_DLGFRAME), $WS_EX_MDICHILD, $Form1)

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSE2Clicked")

GUISetState()

While 1

Sleep(2000)

WEnd

Exit

Func _third()

$Form3_1 = GUICreate("Form3", 633, 447, 307, 143, $ws_TILEDWINDOW, $WS_EX_MDICHILD, $Form1)

GUISetState()

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSE3Clicked")

While 1

Sleep(2000)

WEnd

EndFunc ;==>_third

Func button1()

_third()

EndFunc ;==>button1

Func closeclicked()

Exit

EndFunc ;==>closeclicked

Func close2clicked()

MsgBox(0, "", "Colse2 clicked")

EndFunc ;==>close2clicked

Func close3clicked()

MsgBox(0, "", "Close 3 clicked")

EndFunc ;==>close3clicked

>


Elke vogel zingt zoals hij gebekt is !Als alleen die vogels zongen die het mooiste zingen zou het stil zijn in het bos.

Share this post


Link to post
Share on other sites



Events are queued and executed in order, so when you lock him in that loop you fuck up all chances of working on more events. You must remove the loop in _third() and let him go back to the main-loop.

Share this post


Link to post
Share on other sites

Richardr,

Remove the While...WEnd loop from your _third() function. The script will not run another function until that one ends and the eternal loop you have set up means that it never will! :evil:

Two other points:

1. You only need a Sleep(10) in While...WEnd loops in OnEvent mode - you have to wait for the Sleep to finish before the script continues, so making the Sleep longer than you have to just makes the script unresponsive.

2. If you post code, please use Code tags - it makes it much easier to read. ;) Put [autoit ] before and [/autoit ] after your posted code (but omit the trailing space - it is only there so the tags display here).

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

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

 

Share this post


Link to post
Share on other sites

1. You only need a Sleep(10) in While...WEnd loops in OnEvent mode - you have to wait for the Sleep to finish before the script continues, so making the Sleep longer than you have to just makes the script unresponsive.

You're thinking about MessageLoop Mode now ;)

To clarify, open up the example for GUISetOnEvent and set the loop to 999999 or something, and the events will still be instantenous :evil:

Share this post


Link to post
Share on other sites

AdmiralAlkex,

:evil:

In my defence, I use OnEvent mode so rarely that at my advanced age I can never remember what exactly goes on... ;)

Happy New Year! :evil:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

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

 

Share this post


Link to post
Share on other sites

Thanks for qour quick response.

Happy Newyear everybody :-)


Elke vogel zingt zoals hij gebekt is !Als alleen die vogels zongen die het mooiste zingen zou het stil zijn in het bos.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I should have looked here sooner. I bashed my head on this problem for two weeks. :D

Although, on the bright side, I threw an entire module out and rewrote from scratch in the process, and came out cleaner in the end.

The "double loops" was what was killing the script (and I only had two windows).

I will have to rethink the way I write my modules that contain GUIs.

I can't help but wonder if this is a change in AutoIt's behavior. Other events, like maximize and minimize, still work through the double loops. Only close is not working, and I don't recall any of my other scripts having this issue.

Edited by willichan

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