Jump to content

Recommended Posts

Posted

Can anyone tell me why the buttons on the second GUI will not work in the following code? What am I missing here? :x

Thanks in advance,

cj

#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
Opt("GUICoordMode", 2)

Global $GUI1, $GUI2, $hChooseOK, $hChooseCancel, $hChooseOK2, $hChooseCancel2

GUI1()

Func GUI1()

    $GUI1 = GUICreate("Number 1", 275, 175, -1, -1, BitOR($WS_CHILD, $WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU), Default)

    $hChooseOK = GUICtrlCreateButton("Ok", -1, 25, 85, 25)
        GUICtrlSetOnEvent(-1, 'GUI2')
    $hChooseCancel = GUICtrlCreateButton("Cancel", 10, -1, 85, 25)
        GUICtrlSetOnEvent(-1, 'Close')
    GUISetOnEvent($GUI_EVENT_CLOSE, 'Close')
    GUISetState(@SW_SHOW)

    While 1
        Sleep(1000)
    WEnd
EndFunc

Func GUI2()
    GUIDelete($GUI1)
    $GUI2 = GUICreate("GUI Number 2", 275, 175, -1, -1, BitOR($WS_CHILD, $WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU), Default)

    $hChooseOK2 = GUICtrlCreateButton("Close", -1, 25, 85, 25)
        GUICtrlSetOnEvent(-1, 'Close')
    $hChooseCancel2 = GUICtrlCreateButton("Cancel", 10, -1, 85, 25)
        GUICtrlSetOnEvent(-1, 'Close')
    GUISetOnEvent($GUI_EVENT_CLOSE, 'Close')
    GUISetState(@SW_SHOW)
    While 1
        Sleep(1000)
    WEnd
EndFunc

Func Close()
    Exit
EndFunc
Posted

hi, move your sleep outside the functions.

#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
Opt("GUICoordMode", 2)

Global $GUI1, $GUI2, $hChooseOK, $hChooseCancel, $hChooseOK2, $hChooseCancel2

GUI1()

While 1
    Sleep(1000)
WEnd

Func GUI1()
    $GUI1 = GUICreate("Number 1", 275, 175, -1, -1, BitOR($WS_CHILD, $WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU), Default)
    $hChooseOK = GUICtrlCreateButton("Ok", -1, 25, 85, 25)
        GUICtrlSetOnEvent(-1, 'GUI2')
    $hChooseCancel = GUICtrlCreateButton("Cancel", 10, -1, 85, 25)
        GUICtrlSetOnEvent(-1, 'Close')
    GUISetOnEvent($GUI_EVENT_CLOSE, 'Close', $GUI1)
    GUISetState(@SW_SHOW, $GUI1)
EndFunc

Func GUI2()
    GUIDelete($GUI1)
    $GUI2 = GUICreate("GUI Number 2", 275, 175, -1, -1, BitOR($WS_CHILD, $WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU), Default)
    $hChooseOK2 = GUICtrlCreateButton("Close", -1, 25, 85, 25)
        GUICtrlSetOnEvent(-1, 'Close')
    $hChooseCancel2 = GUICtrlCreateButton("Cancel", 10, -1, 85, 25)
        GUICtrlSetOnEvent(-1, 'Close')
    GUISetOnEvent($GUI_EVENT_CLOSE, 'Close', $GUI2)
    GUISetState(@SW_SHOW, $GUI2)
EndFunc

Func Close()
    Exit
EndFunc

Cheers

Posted

Can anyone tell me why the buttons on the second GUI will not work in the following code? What am I missing here? :x

Events are queued and run from first to last. You need to return from the function like smashly showed.

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
×
×
  • Create New...