Jump to content

GUI minimizes automatically for no reason when second gui is closed


Kloud
 Share

Recommended Posts

So I have a GUI that has a button to open up another GUI. For some reason, if I close the second GUI then the first one is minimized. I don't know why. I don't want that to happen.
It only happens if I disable the first GUI.

Example:

#include <GuiConstants.au3>

$main = GUICreate("MyGUI", 392, 322)

$Button_1 = GUICtrlCreateButton("Input", 140, 190, 70, 30)

GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_1
            GUISetState(@SW_DISABLE, $main)
            _Input()
            GUISetState(@SW_ENABLE, $main)
            GUISetState(@SW_SHOW)
        Case Else
        ;;;
    EndSelect
WEnd
Exit

Func _Input()
    $popup = GUICreate("PopUP", 191, 85, -1, -1)

    $Input_1 = GUICtrlCreateInput("Input1", 0, 0, 180, 20)
    $Button_2 = GUICtrlCreateButton("OK", 60, 40, 60, 20)

    GUISetState()
    While 1
        $msg2 = GUIGetMsg()
        Select
            Case $msg2 = $Button_2
                ExitLoop
            Case Else
            ;;;
        EndSelect
    WEnd
    GUIDelete($popup)
EndFunc  ;==>_Input

How can I prevent the fist GUI from minimizing when the second GUI is closed?

Link to comment
Share on other sites

I'm not sure it's minimized, it seems its z-order has changed.

If you minimize all other opened windows (Browser, Scite etc...) then you will notice that your main Window appears (it was placed behind the other windows, so it wasn't minimized).

Also when you run the script, before clicking on Input button, if you minimize all the other opened windows then click on Input Button, Main GUI will be visible when you close the secondary GUI which shows it wasn't "minimized".

The same behavior appears in this link (the 2nd example with @SW_DISABLE, which looks a lot like your script). When I kept this example in my AutoIt learning folder, on April 2018 (a few days after I discovered AutoIt !) then I saved it with 1 altered line which was :

; Local $hGUI1 = GUICreate("GUI 1", 200, 200, 100, 100) ; original line

#include <WindowsConstants.au3>
...
Local $hGUI1 = GUICreate("Gui 1", 200, 200, 100, 100, -1, $WS_EX_TOPMOST)

Probably I added $WS_EX_TOPMOST to avoid the same behavior you described, maybe a side effect of @SW_DISABLE ?

Link to comment
Share on other sites

I just did a little search concerning what is discussed in this post.
In this MSDN link, we can read what follows, which seems to explain how to always fix this :

EnableWindow function
...
[in] bEnable
Type: BOOL
Indicates whether to enable or disable the window...
...
If an application is displaying a modeless dialog box and has disabled its main window, the application must enable the main window before destroying the dialog box. Otherwise, another window will receive the keyboard focus and be activated.
...

Isn't it exactly what happens in OP's code and also in the 2nd example found in this AutoIt wiki page ?

In the example found in the wiki page, the 1st GUI doesn't reappear when the 2nd GUI is closed (assuming there are other non-minimized windows, i.e. Explorer, any Browser, Scite...)

Here is a part of the original code in the wiki example :

Func gui1()
    ...
    Case $idButton2
        ; Disable the first GUI
        GUISetState(@SW_DISABLE, $hGUI1)
        gui2()
        ; Re-enable the first GUI
        GUISetState(@SW_ENABLE, $hGUI1)
EndFunc

Func gui2()
    ...
    Case $GUI_EVENT_CLOSE
        GUIDelete($hGUI2)
        ExitLoop

EndFunc

If we change this code to what follows, then the 1st GUI will always reappear when the 2nd GUI is closed (tested) :

Global $hGUI1 

Func gui1()
    ...
    Case $idButton2
        ; Disable the first GUI
        GUISetState(@SW_DISABLE, $hGUI1)
        gui2()
EndFunc

Func gui2()
    ...
    Case $GUI_EVENT_CLOSE
        ; Re-enable the first GUI (just before deleting the 2nd GUI +++)
        GUISetState(@SW_ENABLE, $hGUI1)
        GUIDelete($hGUI2)
        ExitLoop

EndFunc

It works same in OP's code (tested), by transferring the activation code of the main GUI just before closing the pop-up window :

...
GUISetState(@SW_ENABLE, $main)
GUIDelete($popup)
...

 

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