Jump to content

Gui On Event problem


Recommended Posts

Hello there,

here is a little code, which will demonstrate a strange problem,

please run this code, to know what i mean its a bit difficult for me to explain it

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

Global $win = False,$exitWin2 = False,$W2


Main()

Func Main()
    win1()
    While 1
        Sleep(100)
    WEnd
EndFunc

Func Win1()
    $Form1 = GUICreate("GUI 1", 311, 142, 360, 224)
    $Button1 = GUICtrlCreateButton("Start W2", 16, 32, 75, 25, $WS_GROUP)
    GUICtrlSetOnEvent(-1,"btnofwin1")
    GUISetState(@SW_SHOW)
EndFunc
Func BtnOfWin1()
    WinWait2()
EndFunc

Func WinWait2()
    Win2()
    While $exitWin2 = False
        ConsoleWrite("!is this a bug ????"&@CRLF)
        Sleep(100)
    WEnd
    GUIDelete($W2)
    $exitWin2 = False
    ConsoleWrite("Ok its working... its not a bug"&@CRLF)
EndFunc

Func Win2()
    $W2 = GUICreate("GUI 2", 311, 142, 360, 224)
    $Button1 = GUICtrlCreateButton("Exit", 16, 32, 75, 25, $WS_GROUP)
    GUICtrlSetOnEvent(-1,"btnofwin2")
    GUISetState(@SW_SHOW)
EndFunc
Func BtnOfWin2()
    $exitWin2 = True
EndFunc

thanks in Advance

73 108 111 118 101 65 117 116 111 105 116

Link to comment
Share on other sites

Are you having a problem with the first GUI not closing? or the 2nd?

2nd with Exit Button on the GUI.

the button is not firing the event!

Edited by Digisoul

73 108 111 118 101 65 117 116 111 105 116

Link to comment
Share on other sites

  • Moderators

DigiSoul,

It is not a bug. :nuke:

AutoIt will not interrupt a running function with another unless you use a HotKey. You are sitting in the loop in WinWait2(), so as the function is still running, BtnOfWin2() is never called. ;)

Just get back to your idle loop and look for the flag there: :P

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

Global $win = False, $exitWin2 = False, $W2

Main()

Func Main()
    win1()
    While 1
        Sleep(100)
        If $exitWin2 Then
            $exitWin2 = False
            GUIDelete($W2)
        EndIf

    WEnd
EndFunc   ;==>Main

Func Win1()
    $Form1 = GUICreate("GUI 1", 311, 142, 360, 224)
    $Button1 = GUICtrlCreateButton("Start W2", 16, 32, 75, 25, $WS_GROUP)
    GUICtrlSetOnEvent(-1, "btnofwin1")
    GUISetState(@SW_SHOW)
EndFunc   ;==>Win1

Func BtnOfWin1()
    WinWait2()
EndFunc   ;==>BtnOfWin1

Func WinWait2()
    Win2()
EndFunc   ;==>WinWait2

Func Win2()
    $W2 = GUICreate("GUI 2", 311, 142, 360, 224)
    $Button2 = GUICtrlCreateButton("Exit", 16, 32, 75, 25, $WS_GROUP)
    GUICtrlSetOnEvent(-1, "btnofwin2")
    GUISetState(@SW_SHOW)
EndFunc   ;==>Win2

Func BtnOfWin2()
    $exitWin2 = True
EndFunc   ;==>BtnOfWin2

Top Tip: Use Opt("TrayIconDebug", 1) if your script appears to hang like that. It lets you see where the script is when you put your cursor over the tray icon. :

All clear? :blink:

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

DigiSoul,

It is not a bug. :nuke:

AutoIt will not interrupt a running function with another unless you use a HotKey. You are sitting in the loop in WinWait2(), so as the function is still running, BtnOfWin2() is never called. ;)

Just get back to your idle loop and look for the flag there: :P

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

Global $win = False, $exitWin2 = False, $W2

Main()

Func Main()
    win1()
    While 1
        Sleep(100)
        If $exitWin2 Then
            $exitWin2 = False
            GUIDelete($W2)
        EndIf

    WEnd
EndFunc   ;==>Main

Func Win1()
    $Form1 = GUICreate("GUI 1", 311, 142, 360, 224)
    $Button1 = GUICtrlCreateButton("Start W2", 16, 32, 75, 25, $WS_GROUP)
    GUICtrlSetOnEvent(-1, "btnofwin1")
    GUISetState(@SW_SHOW)
EndFunc   ;==>Win1

Func BtnOfWin1()
    WinWait2()
EndFunc   ;==>BtnOfWin1

Func WinWait2()
    Win2()
EndFunc   ;==>WinWait2

Func Win2()
    $W2 = GUICreate("GUI 2", 311, 142, 360, 224)
    $Button2 = GUICtrlCreateButton("Exit", 16, 32, 75, 25, $WS_GROUP)
    GUICtrlSetOnEvent(-1, "btnofwin2")
    GUISetState(@SW_SHOW)
EndFunc   ;==>Win2

Func BtnOfWin2()
    $exitWin2 = True
EndFunc   ;==>BtnOfWin2

Top Tip: Use Opt("TrayIconDebug", 1) if your script appears to hang like that. It lets you see where the script is when you put your cursor over the tray icon. :

All clear? :blink:

M23

Thanks for clearing this concept, my situation is a little different then this basic code, i am actually trying to pause the execution in the SQLite callback, you have any idea ?

Anyways thanks for the Tip.

73 108 111 118 101 65 117 116 111 105 116

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...