Jump to content

How can I create a sizable GUI without a Close box?


CYCho
 Share

Recommended Posts

I have the following code:

#include <GuiConstants.au3>

$hMain = GUICreate("Main", 400, 100, -1, 200)
$idButton = GUICtrlCreateButton("Hide Child GUI", 100, 20, 200, 25)
GUISetState()
$hChild = GUICreate("Child", 200, 200, -1, 400, $WS_SIZEBOX, -1, $hMain)
GUISetState()

While 1
    $aMsg = GUIGetMsg(1)
    If $aMsg[1] = $hMain And $aMsg[0] = $GUI_EVENT_CLOSE Then
        GUIDelete($hMain)
        GUIDelete($hChild)
        ExitLoop
    ElseIf ($aMsg[1] = $hMain And $aMsg[0] = $idButton) Then
        If GUICtrlRead($idButton) = "Hide Child GUI" Then
            GUISetState(@SW_HIDE, $hChild)
            GUICtrlSetData($idButton, "Show Child GUI")
        Else
            GUISetState(@SW_SHOW, $hChild)
            GUICtrlSetData($idButton, "Hide Child GUI")
        EndIf
    ElseIf $aMsg[1] = $hChild And $aMsg[0] = $GUI_EVENT_CLOSE Then
        GUISetState(@SW_HIDE, $hChild)
        GUICtrlSetData($idButton, "Show Child GUI")
    EndIf
WEnd

My problem is that when I click "Close" box of the child gui, the main window is minimized, not always but more often than not. If anyone had a similar problem and found a solution, I would appreciate it very much if you could share your experience. If there is no solution, I would like to know what combination of styles I should use to create a sizable gui without a close box, so that I can hide or show the child gui with a button in the main gui. Thank you in advance.

Link to comment
Share on other sites

I can't recreate your issue with the main form randomly minimizing when closing the child window. 

 

30 minutes ago, CYCho said:

I would like to know what combination of styles I should use to create a sizable gui without a close box

Below is an example of a child window that can be resized, without a close box.

#include <GuiConstants.au3>

$hMain    = GUICreate("Main", 400, 100, -1, 200)
$idButton = GUICtrlCreateButton("Show Child GUI", 100, 20, 200, 25)
;~ $hChild   = GUICreate("Child", 200, 200, -1, 400, $WS_SIZEBOX, -1, $hMain)
$hChild   = GUICreate("Child", 200, 200, -1, 400, BitOR($WS_SIZEBOX,$WS_THICKFRAME,$WS_SYSMENU,$WS_POPUP), -1, $hMain)
GUISetState(@SW_SHOW, $hMain)

While 1
    $aMsg = GUIGetMsg(1)

    Switch $aMsg[1] ;Form

        Case $hMain
            Switch $aMsg[0] ;Event
                Case $GUI_EVENT_CLOSE
                    GUIDelete($hMain)
                    GUIDelete($hChild)
                    ExitLoop
                Case $idButton
                    If GUICtrlRead($idButton) = "Hide Child GUI" Then
                        GUISetState(@SW_HIDE, $hChild)
                        GUICtrlSetData($idButton, "Show Child GUI")
                    Else
                        GUISetState(@SW_SHOW, $hChild)
                        GUICtrlSetData($idButton, "Hide Child GUI")
                    EndIf
            EndSwitch

        Case $hChild
            Switch $aMsg[0] ;Event
                Case $GUI_EVENT_CLOSE
                    GUISetState(@SW_HIDE, $hChild)
                    GUICtrlSetData($idButton, "Show Child GUI")
            EndSwitch

    EndSwitch
WEnd

The example uses your original logic.  It just uses "switch/case" statements instead of "if" statements.

Edited by TheXman
Link to comment
Share on other sites

Link to comment
Share on other sites

Thank you for your prompt attention. I don't blame you for not being able to recreate the problem. It happens only once in a while even to me, and is more prone to happen at the initial stage of execution. I am on 64-bit Windows 10.
@TheXman your code creates a gui without the title box itself. I would like to keep the title box. The "X" box is harmless if I don't give it a function, but I would rather not have it if I cannot use it.

Link to comment
Share on other sites

Sorry, low-level GUIs & Graphics are not within my areas of expertise.  I know how to create a non-resizable form without a close box, but that doesn't help you.  Hopefully someone more knowledgeable on the subject will step in with some advice.  :)

 

Edited by TheXman
Link to comment
Share on other sites

The problem was solved by assigning a function call to the "Close" box. Basically it is the same thing and I don't know why one works and the other doesn't.

Edit: No, it doesn't work.  It is all the same. I will adopt @pixelsearch's approach below and gray out the "X" box.

#include <GuiConstants.au3>

$hMain = GUICreate("Main", 400, 100, -1, 200)
$idButton = GUICtrlCreateButton("Hide Child GUI", 100, 20, 200, 25)
GUISetState()
$hChild = GUICreate("Child", 200, 200, -1, 400, $WS_SIZEBOX, -1, $hMain)
GUISetState()

While 1
    $aMsg = GUIGetMsg(1)
    Switch $aMsg[1]
        Case $hMain
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($hMain)
                    GUIDelete($hChild)
                    ExitLoop
                Case $idButton
                    MyChild()
            EndSwitch
        Case $hChild
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    MyChild()
            EndSwitch
    EndSwitch
WEnd

Func MyChild()
    If GUICtrlRead($idButton) = "Hide Child GUI" Then
        GUISetState(@SW_HIDE, $hChild)
        GUICtrlSetData($idButton, "Show Child GUI")
    Else
        GUISetState(@SW_SHOW, $hChild)
        GUICtrlSetData($idButton, "Hide Child GUI")
    EndIf
EndFunc

 

Edited by CYCho
Link to comment
Share on other sites

Hi CYCho
If you create your child window like this :

#include <GUIMenu.au3>

...

$hChild = GUICreate("Child", 200, 200, -1, 400, $WS_SIZEBOX, -1, $hMain)
$hMenu = _GUICtrlMenu_GetSystemMenu($hChild)
_GUICtrlMenu_EnableMenuItem($hMenu, $SC_CLOSE, $MF_GRAYED, False)
GUISetState()

...

Then its close button will be grayed & non active.

Edited by pixelsearch
fixed #2
Link to comment
Share on other sites

On 3/13/2021 at 1:15 AM, CYCho said:

My problem is that when I click "Close" box of the child gui, the main window is minimized

I think I found the reason. My mouse was the culprit. When I clicked on the child window's Close button, sometimes a double click was triggered: the first click closed the child window and  the second click fell on the same spot of the background where the child window was located. I changed my mouse and the problem is gone.

Edited by CYCho
Link to comment
Share on other sites

3 hours ago, CYCho said:

I changed my mouse and the problem is gone.

Hi C. Y. Cho :)
Thanks for keeping us updated.
I just tested your last version 3.0.1.3 (dated march 14, 2021) great job !

Basically I don't think it's a mouse issue. Even if you click once on the child close button, wait 1 second and click again "on the same spot of the background where the child window was located" then this is what will happen :

1) If this second click is done on the desktop, the main GUI will still be visible

2) If this second click is done on a Window placed behind your main GUI (this is your case) then this Window will steal the focus and your main GUI will disappear. In this 2nd case, your main GUI isn't "minimized" or "hidden" and WinGetState shows it clearly (just tested) :

$WIN_STATE_EXISTS (1) = Window exists
$WIN_STATE_VISIBLE (2) = Window is visible
$WIN_STATE_ENABLED (4) = Window is enabled
$WIN_STATE_ACTIVE (8) = Window is active
$WIN_STATE_MINIMIZED (16) = Window is minimized
$WIN_STATE_MAXIMIZED (32) = Window is maximized

Retrieving your main GUI state gives these results :
* 23 if you force it to minimize (16 + 4 + 2 + 1)
* 15 when it's active (8 + 4 + 2 + 1)
*  7 when the other Window you clicked on stole the focus and your main Gui vanished (4 + 2 + 1)
*  5 when you "really" hide it with a code like WinSetState($winMain, "", @SW_HIDE) (4 + 1)

A solution to fix this is to set $WS_TOPMOST style to main GUI at line 89 (version 3.0.1.3) :

; $winMain = GUICreate("zPlayer by C. Y. Cho", $mainWidth, $mainHeight, $listLeft+$listWidth, $listHeight/2)

$winMain = GUICreate("zPlayer by C. Y. Cho", $mainWidth, $mainHeight, $listLeft+$listWidth, $listHeight/2, -1, 0x0008) ; $WS_TOPMOST = 0x0008

But it all depends on you in case it bothers you to have the main GUI always on top, which means you'll have to minimize it with its button when needed.

By the way, I detect a minor issue with the playlist window title :

* Its title is "Playing in Sequential Mode..." when we 1st run the program (no .ini file yet)
* Then we click on "Play in Shuffled Mode" in main gui...
* ...which correctly changes the playlist window title to "Playing in Shuffled Mode..."
* Now comes the problem : if we click on "Play in Sequential" in main gui...
* ...then the playlist window title doesn't change and keeps saying "Playing in Shuffled Mode..."

To fix this, adding a new line #888 solves it (tested) :

1985077686_1lineadded.png.f8bb3ca1fc7aeaa4c644613e1bfebc02.png

Also I just read your resume in this link and bravo for what you did : so you retired from active duty in 2002 and "came from a sales career with no experience in programming, it was not an easy task."
Impressive result, especially you had no experience in programming :thumbsup:

Edited by pixelsearch
Link to comment
Share on other sites

What an impressive and loving review! I know my code will look very much amateurish to experts like you. But i console myself thnking what the heck it works for me. I am still asking questions and reflect the solutions to my zPlayer, and I thank all the kndly forum members who willingly and patiently taught an ignorant novice. I have been taking this as my lifetime project hoping that it will keep me safe from, or at least delaty, dementia. Soon I'll be 78 and I am proud of myself for having a zeal to stay up into late hours of the evening looking at the code. You are the first to give a detailed review and even make suggestions for improvement. Many many thanks!  I will reflect your suggestions in my next update in a couple of days time.

Edited by CYCho
Link to comment
Share on other sites

@pixelsearch, Thank you for detailed analysis of the problem. By trial and error, I found that the problem does not occur if GUISetState(@SW_SHOW, $hMain) comes after GUISetState(@SW_SHOW, $hChild), even though I still cannot explain why. My practical solution for zPlayer will probably be the following 2 lines just before Main().
 

GUISetState(@SW_HIDE, $winMain)
GUISetState(@SW_SHOW, $winMain)

Edit: I had to add one more line: WinSetTitle($winMain, "", "zPlayer by C. Y. Cho")

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