Jump to content

GUI doesn't reopen after open/close


Daemante2018
 Share

Recommended Posts

So I have a main GUI button that opens a secondary "About" GUI window. It opens/closes just fine, but, after opening/closing the "About" GUI once it won't reopen. I got a few commands from the Managing_Multiple_GUIs tutorial so that the second GUI doesn't exit the script. I'm not sure if I need to implement more from that tutorial to fix this issue or not.

Main:

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

$QG = GUICreate("QG", 337, 588, 284, 164, -1, BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
$File = GUICtrlCreateMenu("File")
$New = GUICtrlCreateMenuItem("New", $File)
$Open = GUICtrlCreateMenuItem("Open", $File)
$Save = GUICtrlCreateMenuItem("Save", $File)
$Exit = GUICtrlCreateMenuItem("Exit", $File)
$Help = GUICtrlCreateMenu("Help")
$About = GUICtrlCreateMenuItem("About", $Help)
GUISetFont(12, 400, 0, "MS Sans Serif")
GUISetBkColor(0xB4B4B4)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $New
        Case $Open
        Case $Save
        Case $Exit
            Exit
        Case $About
            GUISetState(@SW_DISABLE, $QG)
            _QGAbout()
            GUISetState(@SW_ENABLE, $QG)
    EndSwitch
WEnd

Secondary:

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

Func _QGAbout()

    $About = GUICreate("About", 246, 288, -1, -1, $WS_SYSMENU, BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
    $Version = GUICtrlCreateLabel("Version 1.0", 175, 266, 57, 17)
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUISetState(@SW_HIDE)
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>_QGAbout

As you can see it won't open a second time. 

Thanks in advance.

qgabout.au3

 

QG.au3

Edited by Daemante2018
Link to comment
Share on other sites

Here's one way to do it.

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

$QG = GUICreate("QG", 337, 588, 284, 164, -1, BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
$File = GUICtrlCreateMenu("File")
$New = GUICtrlCreateMenuItem("New", $File)
$Open = GUICtrlCreateMenuItem("Open", $File)
$Save = GUICtrlCreateMenuItem("Save", $File)
$Exit = GUICtrlCreateMenuItem("Exit", $File)
$Help = GUICtrlCreateMenu("Help")
$About = GUICtrlCreateMenuItem("About", $Help)
GUISetFont(12, 400, 0, "MS Sans Serif")
GUISetBkColor(0xB4B4B4)
GUISetState(@SW_SHOW, $QG)
$About1 = GUICreate("About", 246, 288, -1, -1, $WS_SYSMENU, BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
$Version = GUICtrlCreateLabel("Version 1.0", 175, 26, 57, 17)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $New
        Case $Open
        Case $Save
        Case $Exit
            Exit
        Case $About
            GUISetState(@SW_DISABLE, $QG)
            _QGAbout($About1)
            GUISetState(@SW_ENABLE, $QG)
    EndSwitch
WEnd

Func _QGAbout($AboutGUI)
    GUISetState(@SW_SHOW, $AboutGUI)
    While 1
        $nMsg = GUIGetMsg(1)
        If $nMsg[1] = $AboutGUI Then
            Switch $nMsg[0]
                Case $GUI_EVENT_CLOSE
                    GUISetState(@SW_HIDE, $AboutGUI)
                    ExitLoop
            EndSwitch
        EndIf
    WEnd
EndFunc   ;==>_QGAbout

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Having the same issue with a second GUI. It opens fine etc. but won't open twice. I'm using the code you shared earlier, but, I call my functions from a separate file. This works for the $About GUI but not the new $Save.

Case $Save
            GUISetState(@SW_DISABLE, $QuestGuide)
            _QGSave($Save)
            GUISetState(@SW_ENABLE, $QuestGuide)
Func _QGSave($SaveForm)

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #Region ### START Koda GUI section ### Form=z:\dropbox\new\scripting\projects\fluffybunny\gui forms\saveform.kxf
    $SaveForm = GUICreate("Save", 301, 99, -1, -1, -1, BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
    GUISetFont(10, 400, 0, "MS Sans Serif")
    $SaveInput = GUICtrlCreateInput("", 9, 34, 279, 24)
    GUICtrlSetCursor(-1, 5)
    $SaveName = GUICtrlCreateLabel("Choose name for you save file:", 9, 6, 187, 20)
    $Save = GUICtrlCreateButton("Save", 216, 65, 75, 25)
    $Cancel = GUICtrlCreateButton("Cancel", 128, 65, 75, 25)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    GUISetState(@SW_SHOW, $SaveForm)
    While 1
        $nMsgSave = GUIGetMsg(1)
        If $nMsgSave[1] = $SaveForm Then
            Switch $nMsgSave[0]
                Case $GUI_EVENT_CLOSE
                    GUISetState(@SW_HIDE, $SaveForm)
                    ExitLoop
            EndSwitch
        EndIf
    WEnd
EndFunc   ;==>_QGSave

If I do it exactly the same way as Brewman did it works fine for both secondary GUIs.

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

$QG = GUICreate("QG", 337, 588, 284, 164, -1, BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
$File = GUICtrlCreateMenu("File")
$New = GUICtrlCreateMenuItem("New", $File)
$Open = GUICtrlCreateMenuItem("Open", $File)
$Save = GUICtrlCreateMenuItem("Save", $File)
$Exit = GUICtrlCreateMenuItem("Exit", $File)
$Help = GUICtrlCreateMenu("Help")
$About = GUICtrlCreateMenuItem("About", $Help)
GUISetFont(12, 400, 0, "MS Sans Serif")
GUISetBkColor(0xB4B4B4)
GUISetState(@SW_SHOW, $QG)
$About1 = GUICreate("About", 246, 288, -1, -1, $WS_SYSMENU, BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
$SaveForm1 = GUICreate("Save", 301, 99, -1, -1, -1, BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $New
        Case $Open
        Case $Save
            GUISetState(@SW_DISABLE, $QG)
            _QGSave($SaveForm1)
            GUISetState(@SW_ENABLE, $QG)
        Case $Exit
            Exit
        Case $About
            GUISetState(@SW_DISABLE, $QG)
            _QGAbout($About1)
            GUISetState(@SW_ENABLE, $QG)
    EndSwitch
WEnd

Func _QGAbout($AboutGUI)
    GUISetState(@SW_SHOW, $AboutGUI)
    While 1
        $nMsg = GUIGetMsg(1)
        If $nMsg[1] = $AboutGUI Then
            Switch $nMsg[0]
                Case $GUI_EVENT_CLOSE
                    GUISetState(@SW_HIDE, $AboutGUI)
                    ExitLoop
            EndSwitch
        EndIf
    WEnd
EndFunc   ;==>_QGAbout

Func _QGSave($SaveForm)
    GUISetState(@SW_SHOW, $SaveForm)
    While 1
        $nMsgSave = GUIGetMsg(1)
        If $nMsgSave[1] = $SaveForm Then
            Switch $nMsgSave[0]
                Case $GUI_EVENT_CLOSE
                    GUISetState(@SW_HIDE, $SaveForm)
                    ExitLoop
            EndSwitch
        EndIf
    WEnd
EndFunc   ;==>_QGSave

Am I doing something wrong with calling the _$QGSave($SaveForm) function from the other file? 

Edited by Daemante2018
Link to comment
Share on other sites

Your includes are in the wrong place.

You're recreating the GUI every time you call the function, with a new handle.

There's no need to use GUICreate inside your function, the GUI already exists, and merely needs to be shown and/or hidden. Just take the function I gave you and use that.

Also, there's no need to include the UDFs that are already included in the main script, they're already loaded. Although it won't hurt anything to do it that way, unless you plan on reusing the second file in other scripts, it's needless typng.

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

 

13 minutes ago, BrewManNH said:

There's no need to use GUICreate inside your function, the GUI already exists, and merely needs to be shown and/or hidden. Just take the function I gave you and use that.

Also, there's no need to include the UDFs that are already included in the main script, they're already loaded. Although it won't hurt anything to do it that way, unless you plan on reusing the second file in other scripts, it's needless typng.

Your referring to creating the secondary GUI? 

 

13 minutes ago, BrewManNH said:

Also, there's no need to include the UDFs that are already included in the main script, they're already loaded. Although it won't hurt anything to do it that way, unless you plan on reusing the second file in other scripts, it's needless typng.

 

The only reason I use a separate file is to keep it more organized for myself, but, I just started using ISN and it has the tree that shows everything in an organized manner so I guess you are right in that it is extra typing in that case. 

 

Just to clarify, the third block of code i pasted that was using the format you suggested initially is not being used in conjunction with the second file. I edited everything to follow your format and put it in one script; which does work perfectly.

Edited by Daemante2018
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...