Jump to content

Two GUIs but only one responds


Go to solution Solved by TryingToCode,

Recommended Posts

Posted

I'm struggling with 2 GUIs where one opens the other.ย  The first GUI successfully opens the second but then I can't get the second GUI to respond to any events or button presses.ย  Please could someone help identify what am I missing?

Here is some example code to illustrate my problem.

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

Example()

Func Example()
    Global $hFirstGUI = GUICreate("First GUI", 330, 120)
    GUISetOnEvent($GUI_EVENT_CLOSE, "CloseGUI")
    Local $idNewGUI = GUICtrlCreateButton("New GUI", 10, 90, 85, 25)
    GUICtrlSetOnEvent(-1, "NewGUI")
    Local $idOK = GUICtrlCreateButton("OK", 240, 90, 85, 25)
    GUICtrlSetOnEvent(-1, "CloseGUI")
    GUISetState(@SW_SHOW, $hFirstGUI)
    While 1
      Sleep(100)
    WEnd
EndFunc

Func CloseGUI()
   GUIDelete($hFirstGUI)
   Exit
EndFunc

Func NewGUI()
    GUIDelete($hFirstGUI)
    Global $hSecondGUI = GUICreate("Second GUI")
    GUISetOnEvent($GUI_EVENT_CLOSE, "CloseGUI2",$hSecondGUI)
    Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25)
    GUICtrlSetOnEvent($idOK, "CloseGUI2")
    GUISetState(@SW_SHOW, $hSecondGUI)
    While 1
        Sleep(100)
    WEnd
 EndFunc

 Func CloseGUI2()
   GUIDelete($hSecondGUI)
   Exit
EndFunc

I'm using Opt("GUIOnEventMode", 1) because this is required elsewhere in my code.

Posted

Hi @TryingToCode,

this should be helpful:ย managing-multiple-guis ๐Ÿ˜€ .

Best regards
Sven

Stay innovative!

Spoiler

๐ŸŒย Au3Forums

๐ŸŽฒ AutoIt (en) Cheat Sheet

๐Ÿ“Š AutoIt limits/defaults

๐Ÿ’Ž Code Katas: [...] (comming soon)

๐ŸŽญ Collection of GitHub users with AutoIt projects

๐Ÿžย False-Positives

๐Ÿ”ฎย Me on GitHub

๐Ÿ’ฌย Opinion about new forum sub category

๐Ÿ“‘ย UDF wiki list

โœ‚ย VSCode-AutoItSnippets

๐Ÿ“‘ย WebDriver FAQs

๐Ÿ‘จโ€๐Ÿซย WebDriver Tutorial (coming soon)

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
  • Recently Browsing   0 members

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