Jump to content

Intresting Bug by Using GUIOnEvent - (Moved)


Go to solution Solved by Melba23,

Recommended Posts

Hello people

I found an interesting bug here related to GUIOnEvent & whether to hide GUI using GUISetSate or WinSetState.

Compiled the code & run it 2x

first execution: hide the GUI by clicking X (common e.g. for features like minimize to tray)
second execution: a msgbox with the title "Singelton" signals that it was detected that the application is already running. The window with the title "Test" is displayed again.

If one hid here in the function "_GUIOnEvent_GUIClose" the window use WinSetState OnEvent is active, if GUISetState was used OnEvent is inactive.
(Use the Test button to test if onevent is active or inactive)

 

#include <Misc.au3>

AutoItSetOption("GUIOnEventMode", 1)

If Not _Singleton("Test", 1) Then
    WinSetState("Test", "", @SW_SHOW)
    MsgBox(0, "_Singleton", "", 2)
    Exit
EndIf

$hGUI = GUICreate("Test", 100, 100)
GUISetOnEvent(-3, "_GUIOnEvent_GUIClose")

GUICtrlCreateButton("Test Button", 10, 10, 80, 80)
GUICtrlSetOnEvent(-1, "_GUIOnEvent_Button_Test")


GUISetState(@SW_SHOW)




While 1
    Sleep(1000)
WEnd

Func _GUIOnEvent_Button_Test()
    MsgBox(0, "_GUIOnEvent_Button_Test", "")
EndFunc

Func _GUIOnEvent_GUIClose()
;~  WinSetState($hGUI, '', @SW_HIDE)            ;==> OnEvent still aktiv
    GUISetState(@SW_HIDE)                       ;==> OnEvent somehow inakiv
EndFunc

 

regards

 

NoNameCode

 

Link to comment
Share on other sites

Okay so it's hard to understand, let me visual it a bit:

Script Start -> GUI Build -> GUI Show -> Click Button -> CtrlOnEvent for this Button will trigger a MsgBox

Case 1:
Pressing X -> Hiding Windows use GUISetState(@SW_Hide) -> Start a Second Instans of the Script -> Singelton will notice and Return False -> Second Instanz Show the GUI with WinSetState(... @SW_Show) -> Click Button -> No Reaktion
; It seems to be that only GUISetState(@SW_Show) enables the CtrlOnEvent Routine

Case 2:

Pressing X ->  Hiding Windows use WinSetState($hGUI, '', @SW_Hide) -> Start a Second Instans of the Script -> Singelton will notice and Return False -> Second Instanz Show the GUI with WinSetState(... @SW_Show) -> Click Button -> CrlOnEvent for this Button will trigger a MsgBox

 

Is it a bug or a feature?

 

Regards

NoNameCode

Link to comment
Share on other sites

  • Moderators
  • Solution

NoNameCode,

I raised the same point some years ago and a then-Dev told me that it was a design decision to block events when using GUISetState and that only that function should be used when dealing with AutoIt-created GUIs. Furthermore, it was suggested then the use of WinSetState on AutoIt GUIs could lead to unwelcome results, although, in the typically laconic style of that then-Dev, no hard facts as to what exactly might occur were forthcoming.

So I would go for "feature".

M23

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:

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

 

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
 Share

  • Recently Browsing   0 members

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