Small

GUICtrlOnEventMode not working

5 posts in this topic

 

So i made a GUI and added an other GUI inside. when i press a button in the main GUI the following GUI will popup:

$gReconnect = GUICreate("Reconnect", 220, 164)
GUICtrlCreateLabel("Email",2,2,201,21)
$Email = GUICtrlCreateInput("", 2, 17, 201, 21)
GUICtrlCreateLabel("Password",2,42,201,21)
$Password = GUICtrlCreateInput("", 2, 57, 201, 21,$ES_PASSWORD)
GUICtrlCreateLabel("Character Name",2,82,201,21)
$Charrname = GUICtrlCreateInput("", 2, 97, 201, 21)
$grsave = GUICtrlCreateButton("Save",2,142,106,21)
$grcancel = GUICtrlCreateButton("Cancel",112,142,106,21)
$grload = GUICtrlCreateButton("Load ini file",2,120,106,21)
$grselect = GUICtrlCreateCombo("",113,120,104,15)

GUICtrlSetOnEvent($grsave, "ReconnectHandler")
GUISetOnEvent($GUI_EVENT_CLOSE, "ReconnectHandler")
GUICtrlSetOnEvent($grcancel, "ReconnectHandler")
GUICtrlSetOnEvent($grload, "ReconnectHandler")
GUICtrlSetOnEvent($grselect, "ReconnectHandler")

GUISetState(@SW_HIDE)

Func ReconnectHandler()
    Switch (@GUI_CtrlId)
        Case $grload

        Case $grselect

        Case $grcancel
            $MBCANCEL = MsgBox($MB_YESNO,"Are you sure?","Are you sure you want to cancel the input?")
            If $MBCANCEL = 6 Then
                GUIReconnect()
            EndIf                
        Case $GUI_EVENT_CLOSE
            GUIReconnect()
        Case $grsave
            MsgBox(0,"Saved!", "The settings are saved")
            GUIReconnect()
    EndSwitch
EndFunc

The problem here is when i close the GUI it works but when i try to click a button nothing happends. I dont know why but the main GUI works perfect.

EDIT: Yes i added OPT("GUIOnEventMode, 1)

Share this post


Link to post
Share on other sites



Small,

Without sight of the whole script there is not much we can do to help - but this small script of mine incorporating your functions seems to work without problem:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Opt("GUIOnEventMode", 1)

$hGUI = GUICreate("Test", 500, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

GUICtrlCreateButton("Show", 10, 10, 80, 30)
GUICtrlSetOnEvent(-1, "_ShowGUI")

GUICtrlCreateButton("Test", 10, 50, 80, 30)
GUICtrlSetOnEvent(-1, "_Test")

GUISetState()

$gReconnect = GUICreate("Reconnect", 220, 164)
GUISetOnEvent($GUI_EVENT_CLOSE, "ReconnectHandler")

$grsave = GUICtrlCreateButton("Save",2,142,106,21)
$grcancel = GUICtrlCreateButton("Cancel",112,142,106,21)
$grload = GUICtrlCreateButton("Load ini file",2,120,106,21)
$grselect = GUICtrlCreateCombo("",113,120,104,15)

GUICtrlSetOnEvent($grsave, "ReconnectHandler")
GUICtrlSetOnEvent($grcancel, "ReconnectHandler")
GUICtrlSetOnEvent($grload, "ReconnectHandler")
GUICtrlSetOnEvent($grselect, "ReconnectHandler")

GUISetState(@SW_HIDE)


While 1
    Sleep(10)
WEnd

Func _ShowGUI()

    GUISetState(@SW_SHOW, $gReconnect)

EndFunc


Func ReconnectHandler()
    Switch (@GUI_CtrlId)
        Case $grload
            MsgBox($MB_SYSTEMMODAL, "Load", "Pressed")

        Case $grselect
            MsgBox($MB_SYSTEMMODAL, "Select", "Pressed")

        Case $grcancel
            MsgBox($MB_SYSTEMMODAL, "Cancel", "Pressed")

        Case $GUI_EVENT_CLOSE
            MsgBox($MB_SYSTEMMODAL, "[X]", "Pressed")
            GUISetState(@SW_HIDE, $gReconnect)

        Case $grsave
            MsgBox($MB_SYSTEMMODAL, "Save", "Pressed")
    EndSwitch
EndFunc

Func _Exit()
    Exit
EndFunc

Func _Test()
    MsgBox($MB_SYSTEMMODAL, "Test", "Pressed")
EndFunc

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

#3 ·  Posted (edited)

#include <Array.au3>
#include <GuiStatusBar.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ScrollBarsConstants.au3>
#include <Misc.au3>
#include <EditConstants.au3>
#include <GuiEdit.au3>

Opt("GUIOnEventMode",1)

$GUIreconnect = False

#Region
$Form1_1 = GUICreate("Turtle by Small Version 2.3", 222, 280, 227, 334)
$cCharrname = GUICtrlCreateCombo("", 5, 24, 212, 25, $CBS_DROPDOWN)
;~ GUICtrlSetData(-1,GetLoggedCharNames())
$Status = GUICtrlCreateLabel("Character name", 5, 5, 79, 17)
$Log = GUICtrlCreateEdit("", 2, 120, 218, 100, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN, $WS_VSCROLL))

$bStart = GUICtrlCreateButton("Start", 2, 232, 218, 25)

$mMenu = GUICtrlCreateMenu("Menu")
$mStop = GUICtrlCreateMenuItem("Stop", $mMenu)
$mRender = GUICtrlCreateMenuItem("Rendering", $mMenu)
$mReconnect = GUICtrlCreateMenuItem("Reconnect", $mMenu)

GUICtrlSetOnEvent($bStart, "GUIHandler")
GUISetOnEvent($GUI_EVENT_CLOSE, "GUIHandler")
GUICtrlSetOnEvent($mStop, "GUIHandler")
GUICtrlSetOnEvent($mRender, "GUIHandler")
GUICtrlSetOnEvent($mReconnect, "GUIHandler")

GUISetState(@SW_SHOW)

$gReconnect = GUICreate("Reconnect", 220, 164)
GUICtrlCreateLabel("Email",2,2,201,21)
$Email = GUICtrlCreateInput("", 2, 17, 201, 21)
GUICtrlCreateLabel("Password",2,42,201,21)
$Password = GUICtrlCreateInput("", 2, 57, 201, 21,$ES_PASSWORD)
GUICtrlCreateLabel("Character Name",2,82,201,21)
$Charrname = GUICtrlCreateInput("", 2, 97, 201, 21)
$grsave = GUICtrlCreateButton("Save",2,142,106,21)
$grcancel = GUICtrlCreateButton("Cancel",112,142,106,21)
$grload = GUICtrlCreateButton("Load ini file",2,120,106,21)
$grselect = GUICtrlCreateCombo("",113,120,104,15)
GUICtrlSetOnEvent($grsave, "ReconnectHandler")
GUISetOnEvent($GUI_EVENT_CLOSE, "ReconnectHandler")
GUICtrlSetOnEvent($grcancel, "ReconnectHandler")
GUICtrlSetOnEvent($grload, "ReconnectHandler")
GUICtrlSetOnEvent($grselect, "ReconnectHandler")

GUISetState(@SW_HIDE)

Func ReconnectHandler()
    Switch (@GUI_CtrlId)
        Case $grload
            MsgBox(0,"Load","Load was pressed")
        Case $grselect
            MsgBox(0,"Select","Select was pressed")
        Case $grcancel
            GUIReconnect()
        Case $GUI_EVENT_CLOSE
            GUIReconnect()
        Case $grsave
            MsgBox(0,"Save","Save was pressed"&@CRLF&"The GUI will now close")
            GUIReconnect()
    EndSwitch
EndFunc

Func GUIHandler()
    Switch (@GUI_CtrlId)
        Case $bStart
            MsgBox(0,"Start", "Start Button Was Pressed")
        Case $mStop, $GUI_EVENT_CLOSE
            Exit
        Case $mRender

        Case $mReconnect
            GUIReconnect()
    EndSwitch
EndFunc   ;==>GUIHandler

Func GUIReconnect()
    If $GUIreconnect = True Then
        WinSetState($gReconnect,"Reconnect", @SW_HIDE)
        $GUIreconnect = False
    Else
        WinSetState($gReconnect,"Reconnect", @SW_SHOW)
        $GUIreconnect = True
    EndIf
EndFunc
#EndRegion

While 1
    sleep(100)
WEnd

This is the GUI that I use. The main GUI works perfect but the otherone doesn't

Edited by Small

Share this post


Link to post
Share on other sites

Small,

The problem is the GUIReconnect function - you need to use GUISetState rather then WinSetState:

#include <Array.au3>
#include <GuiStatusBar.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ScrollBarsConstants.au3>
#include <Misc.au3>
#include <EditConstants.au3>
#include <GuiEdit.au3>

Opt("GUIOnEventMode", 1)

$GUIreconnect = False

$Form1_1 = GUICreate("Turtle by Small Version 2.3", 222, 280, 227, 334)
GUISetOnEvent($GUI_EVENT_CLOSE, "GUIHandler")

$mMenu = GUICtrlCreateMenu("Menu")
$mStop = GUICtrlCreateMenuItem("Stop", $mMenu)
$mRender = GUICtrlCreateMenuItem("Rendering", $mMenu)
$mReconnect = GUICtrlCreateMenuItem("Reconnect", $mMenu)

$cCharrname = GUICtrlCreateCombo("", 5, 24, 212, 25, $CBS_DROPDOWN)
$Status = GUICtrlCreateLabel("Character name", 5, 5, 79, 17)

$Log = GUICtrlCreateEdit("", 2, 120, 218, 100, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN, $WS_VSCROLL))

$bStart = GUICtrlCreateButton("Start", 2, 232, 218, 25)

GUICtrlSetOnEvent($bStart, "GUIHandler")
GUICtrlSetOnEvent($mStop, "GUIHandler")
GUICtrlSetOnEvent($mRender, "GUIHandler")
GUICtrlSetOnEvent($mReconnect, "GUIHandler")

GUISetState(@SW_SHOW, $Form1_1)

$gReconnect = GUICreate("Reconnect", 220, 164)
GUISetOnEvent($GUI_EVENT_CLOSE, "ReconnectHandler")

GUICtrlCreateLabel("Email", 2, 2, 201, 21)
$Email = GUICtrlCreateInput("", 2, 17, 201, 21)
GUICtrlCreateLabel("Password", 2, 42, 201, 21)
$Password = GUICtrlCreateInput("", 2, 57, 201, 21, $ES_PASSWORD)
GUICtrlCreateLabel("Character Name", 2, 82, 201, 21)
$Charrname = GUICtrlCreateInput("", 2, 97, 201, 21)

$grsave = GUICtrlCreateButton("Save", 2, 142, 106, 21)
$grcancel = GUICtrlCreateButton("Cancel", 112, 142, 106, 21)
$grload = GUICtrlCreateButton("Load ini file", 2, 120, 106, 21)
$grselect = GUICtrlCreateCombo("", 113, 120, 104, 15)

GUICtrlSetOnEvent($grsave, "ReconnectHandler")
GUICtrlSetOnEvent($grcancel, "ReconnectHandler")
GUICtrlSetOnEvent($grload, "ReconnectHandler")
GUICtrlSetOnEvent($grselect, "ReconnectHandler")

GUISetState(@SW_HIDE, $gReconnect)

While 1
    Sleep(10)
WEnd

Func ReconnectHandler()

    ConsoleWrite(@GUI_WinHandle  & @CRLF)

    Switch @GUI_CtrlId
        Case $grload
            MsgBox($MB_SYSTEMMODAL, "Load", "Load was pressed")

        Case $grselect
            MsgBox($MB_SYSTEMMODAL, "Select", "Select was pressed")
        Case $grcancel
            MsgBox($MB_SYSTEMMODAL, "Cancel", "Cancel was pressed")
            GUIReconnect()
        Case $GUI_EVENT_CLOSE
            MsgBox($MB_SYSTEMMODAL, "[X]", "[X] was pressed")
            GUIReconnect()
        Case $grsave
            MsgBox($MB_SYSTEMMODAL, "Save", "Save was pressed" & @CRLF & "The GUI will now close")
            GUIReconnect()
    EndSwitch
EndFunc   ;==>ReconnectHandler

Func GUIHandler()
    Switch (@GUI_CtrlId)
        Case $bStart
            MsgBox($MB_SYSTEMMODAL, "Start", "Start Button Was Pressed")
        Case $mStop, $GUI_EVENT_CLOSE
            Exit
        Case $mRender

        Case $mReconnect
            GUIReconnect()
    EndSwitch
EndFunc   ;==>GUIHandler

Func GUIReconnect()
    If $GUIreconnect = True Then
        GUISetState(@SW_HIDE, $gReconnect)
        $GUIreconnect = False
    Else
        GUISetState(@SW_SHOW, $gReconnect)
        $GUIreconnect = True
    EndIf
EndFunc   ;==>GUIReconnect

That works for me - does it for you?

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

#5 ·  Posted (edited)

Yeah it does now. I can bash my head into a wall rightnow.....

 

Thanks M23

Edited by Small

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