Jump to content

Need help with my GUI


ZoomRee
 Share

Recommended Posts

I tried to make a GUI which opens a second one and i found this code in the wiki which works perfectly fine

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

Global $g_hGUI2 = 9999, $g_idButton3 ; Predeclare the variables with dummy values to prevent firing the Case statements, only for GUI this time

gui1()

Func gui1()
    Local $hGUI1 = GUICreate("Gui 1", 200, 200, 100, 100)
    Local $idButton1 = GUICtrlCreateButton("Msgbox 1", 10, 10, 80, 30)
    Local $idButton2 = GUICtrlCreateButton("Show Gui 2", 10, 60, 80, 30)
    GUISetState()

    Local $aMsg 
    While 1
        $aMsg = GUIGetMsg(1) ; Use advanced parameter to get array
        Switch $aMsg[1] ; check which GUI sent the message
            Case $hGUI1
                Switch $aMsg[0] ; Now check for the messages for $hGUI1
                    Case $GUI_EVENT_CLOSE ; If we get the CLOSE message from this GUI - we exit <<<<<<<<<<<<<<<
                        ExitLoop
                    Case $idButton1
                        MsgBox($MB_OK, "MsgBox 1", "Test from Gui 1")
                    Case $idButton2
                        GUICtrlSetState($idButton2, $GUI_DISABLE)
                        gui2()
                EndSwitch
            Case $g_hGUI2
                Switch $aMsg[0] ; Now check for the messages for $g_hGUI2
                    Case $GUI_EVENT_CLOSE ; If we get the CLOSE message from this GUI - we just delete the GUI <<<<<<<<<<<<<<<
                        GUIDelete($g_hGUI2)
                        GUICtrlSetState($idButton2, $GUI_ENABLE)
                    Case $g_idButton3
                        MsgBox($MB_OK, "MsgBox", "Test from Gui 2")
                EndSwitch
        EndSwitch
    WEnd
EndFunc   ;==>gui1

Func gui2()
    $g_hGUI2 = GUICreate("Gui 2", 200, 200, 350, 350)
    Local $g_idButton3 = GUICtrlCreateButton("MsgBox 2", 10, 10, 80, 30)
    GUISetState()
EndFunc   ;==>gui2

So i started doing my own GUI and implemented a Function in the second GUI that opens from the MenuItems.
My problem now is that everything i click in the second gui that opens from the first one doesnt react/doesnt do anything although i see no difference from the example in the wiki.
My code :

#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <File.au3>
#include <GuiComboBox.au3>
#include <WinAPIFiles.au3>
#include <MsgBoxConstants.au3>

Global $vguiaswitcher = 9999, $button3

guimain()

Func guimain()
$vguimain = GUICreate("Test", 300, 330)
$menutools = GUICtrlCreateMenu("Tools")
$menuitemswitch = GUICtrlCreateMenuItem("Switch", $menutools)
GUISetState()

Local $amsg
While 1
$amsg = GUIGetMsg(1)
    Switch $amsg[1] ; checks which GUI sent the message
            Case $vguimain
                Switch $amsg[0]
                        Case $GUI_EVENT_CLOSE
                        ExitLoop
                        Case $menuitemswitch
                        GUICtrlSetState($menutools, $GUI_DISABLE)
                        guiaswitcher()
                EndSwitch
            Case $vguiaswitcher
                Switch $amsg[0]
                        Case $GUI_EVENT_CLOSE
                        GUIDelete($vguiaswitcher)
                        GUICtrlSetState($menutools, $GUI_ENABLE)
                        Case $button3
                        MsgBox($MB_OK, "MsgBox", "Test from Gui 2")      
                EndSwitch
    EndSwitch   
WEnd
EndFunc

Func guiaswitcher()
    $vguiaswitch = GUICreate("Auto-Switcher", 300, 330)
    Local $button3 = GUICtrlCreateButton("test",170,100,100,20)
    GUISetState()
EndFunc

The Includes are needed for future stuff.
Many thanks.

Edited by Melba23
Added code tags
Link to comment
Share on other sites

Link to comment
Share on other sites

You could just separate the two guis, for example:

#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <File.au3>
#include <GuiComboBox.au3>
#include <WinAPIFiles.au3>
#include <MsgBoxConstants.au3>

guimain()

Func guimain()
    Local $hGuiMain = GUICreate("Test", 300, 330)
    Local $idMenuTools = GUICtrlCreateMenu("Tools")
    Local $idMenuItemSwitch = GUICtrlCreateMenuItem("Switch", $idMenuTools)
    GUICtrlCreateInput("Test", 10, 10, 100, 20)
    GUISetState(@SW_SHOW, $hGuiMain)
    While 1
        $nMsg1 = GUIGetMsg()
        Switch $nMsg1 ; checks which GUI sent the message
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idMenuItemSwitch
                GUISetState(@SW_DISABLE, $hGuiMain)
                guiaswitcher()
                GUISetState(@SW_ENABLE, $hGuiMain)
        EndSwitch
    WEnd
EndFunc

Func guiaswitcher()
    Local $hGuiSwitch = GUICreate("Auto-Switcher", 300, 330)
    Local $button3 = GUICtrlCreateButton("test",170,100,100,20)
    GUISetState(@SW_SHOW, $hGuiSwitch)
    While 1
        $nMsg2 = GUIGetMsg($hGuiSwitch)
        Switch $nMsg2
            Case $GUI_EVENT_CLOSE
                GUIDelete($hGuiSwitch)
                ExitLoop
            Case $button3
                MsgBox($MB_OK, "MsgBox", "Test from Gui 2")
        EndSwitch
    WEnd
EndFunc

However if you want to use the method above you would need to rename guiaswitcher to guiaswitch, you would also need to remove the Local from $button3 because it should be global as below:

#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <File.au3>
#include <GuiComboBox.au3>
#include <WinAPIFiles.au3>
#include <MsgBoxConstants.au3>

Global $g_hGuiSwitch = 9999, $g_idButton

_GuiMain()

Func _GuiMain()
    Local $hGuiMain = GUICreate("Test", 300, 330)
    Local $idMenuTools = GUICtrlCreateMenu("Tools")
    Local $idMenuItemSwitch = GUICtrlCreateMenuItem("Switch", $idMenuTools)
    GUISetState(@SW_SHOW, $hGuiMain)
    While 1
        $aMsg = GUIGetMsg(1)
        Switch $aMsg[1] ; checks which GUI sent the message
            Case $hGuiMain
                Switch $aMsg[0]
                    Case $GUI_EVENT_CLOSE
                        ExitLoop
                    Case $idMenuItemSwitch
                        GUICtrlSetState($idMenuTools, $GUI_DISABLE)
                        _GuiSwitcher()
                    EndSwitch
                Case $g_hGuiSwitch
                    Switch $aMsg[0]
                        Case $GUI_EVENT_CLOSE
                            GUIDelete($g_hGuiSwitch)
                            GUICtrlSetState($idMenuTools, $GUI_ENABLE)
                        Case $g_idButton
                            MsgBox($MB_OK, "MsgBox", "Test from Gui 2")
                    EndSwitch
        EndSwitch
    WEnd
EndFunc

Func _GuiSwitcher()
    $g_hGuiSwitch = GUICreate("Auto-Switcher", 300, 330)
    $g_idButton = GUICtrlCreateButton("test",170,100,100,20)
    GUISetState(@SW_SHOW, $g_hGuiSwitch)
EndFunc

 

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