Sign in to follow this  
Followers 0

Create a GUI with only the Close button.

15 posts in this topic

Posted (edited)

Have you ever wondered how do I create a GUI like the one shown below?! Then look no further with these Examples. I was playing around with $WS_DLGFRAME and figured that if I BitOR'd it with $WS_SIZEBOX it would create a GUI without the minimize and maximize, but what if I didn't want the re-sizing? After some playing around I realised that replacing $WS_SIZEBOX with $WS_SYSMENU would accomplish this instead of using WM_COMMAND to intercept SC_SIZE from the GUI.

Then ?do=embed' frameborder='0' data-embedContent> pointed out it could be done via a different approach, so I updated using his way :huh2:

Examples below are for both re-sizing and non re-sizing as well as 2 Examples that don't appear in the TaskBar, this is due to using the hidden window [AutoItWinGetTitle()] as the parent handle.

Any suggestions, then please post below. Thanks.

Posted Image

Examples:

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

Example1() ; Without Re-Sizing.
Example2() ; With Re-Sizing.
Example3() ; Without Re-Sizing & No TaskBar.
Example4() ; With Re-Sizing & No TaskBar.

Func Example1() ; Without Re-Sizing.
    Local $hGUI = GUICreate('GUI With Only Close', 250, 250, -1, -1, BitXOR($GUI_SS_DEFAULT_GUI, $WS_MINIMIZEBOX))
    GUISetState(@SW_SHOW, $hGUI)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

        EndSwitch
    WEnd
    GUIDelete($hGUI)
EndFunc   ;==>Example1

Func Example2() ; With Re-Sizing.
    Local $hGUI = GUICreate('GUI With Only Close', 250, 250, -1, -1, BitXOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_MINIMIZEBOX))
    GUISetState(@SW_SHOW, $hGUI)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

        EndSwitch
    WEnd
    GUIDelete($hGUI)
EndFunc   ;==>Example2

Func Example3() ; Without Re-Sizing & No TaskBar.
    Local $hGUI = GUICreate('GUI With Only Close', 250, 250, -1, -1, BitXOR($GUI_SS_DEFAULT_GUI, $WS_MINIMIZEBOX), -1, WinGetHandle(AutoItWinGetTitle()))
    GUISetState(@SW_SHOW, $hGUI)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

        EndSwitch
    WEnd
    GUIDelete($hGUI)
EndFunc   ;==>Example3

Func Example4() ; With Re-Sizing & No TaskBar.
    Local $hGUI = GUICreate('GUI With Only Close', 250, 250, -1, -1, BitXOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_MINIMIZEBOX), -1, WinGetHandle(AutoItWinGetTitle()))
    GUISetState(@SW_SHOW, $hGUI)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

        EndSwitch
    WEnd
    GUIDelete($hGUI)
EndFunc   ;==>Example4

Old way I was doing it:

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

Example5() ; Old Way Of Doing It!

Func Example5() ; Old Way Of Doing It!
    Local $hGUI = GUICreate('GUI With Only Close', 250, 250, -1, -1, BitOR($WS_SIZEBOX, $WS_DLGFRAME))

    GUIRegisterMsg($WM_SYSCOMMAND, 'WM_SYSCOMMAND')
    GUISetState(@SW_SHOW, $hGUI)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

        EndSwitch
    WEnd
    GUIDelete($hGUI)
EndFunc   ;==>Example5

Func WM_SYSCOMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $ilParam
    Local Const $SC_MAXIMIZE = 0xF030, $SC_MINIMIZE = 0xF020, $SC_RESTORE = 0xF120, $SC_SIZE = 0xF000 ; $SC_MOVE = 0xF010
    Switch BitAND($iwParam, 0xFFF0)
        Case $SC_MAXIMIZE, $SC_MINIMIZE, $SC_RESTORE, $SC_SIZE
            Return -1

    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SYSCOMMAND

?do=embed' frameborder='0' data-embedContent>

Edited by guinness
Jefrey and IgImAx like this

Share this post


Link to post
Share on other sites



Posted

If you look into the help file, and check the style parameter, you will see that there is default styles set:

$WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU

So you just need to remove the $WS_MINIMIZEBOX and you get the wanted result :huh2:

Share this post


Link to post
Share on other sites

Posted (edited)

Thanks for the tip! But both ways are right aren't they? OR not? I only posted because some users will ask this question and now I have a reference post.

Edited by guinness
realtebo likes this

Share this post


Link to post
Share on other sites

Posted (edited)

GUICreate("GUI With Only Close", 250, 250, -1, -1, BitXOR($GUI_SS_DEFAULT_GUI, $WS_MINIMIZEBOX)) ;I think this one is better
    ;Or
    GUICreate("GUI With Only Close", 250, 250, -1, -1, BitAND($GUI_SS_DEFAULT_GUI, BitNOT($WS_MINIMIZEBOX)))
    ;Or
    GUICreate("GUI With Only Close", 250, 250, -1, -1, $GUI_SS_DEFAULT_GUI - $WS_MINIMIZEBOX)

:huh2:

Edited by MrCreatoR

Share this post


Link to post
Share on other sites

Posted (edited)

Well, I learnt something today, Thanks. Updated OP.

Edited by guinness

Share this post


Link to post
Share on other sites

Posted (edited)

Some wisdom Melba32 told me was to make it not resizable

Just add this at the top

Const $SC_MOVE = 0xF010

Cant say whether its better or worse than your example?

Chimaera

Edited by Chimaera

Share this post


Link to post
Share on other sites

Posted (edited)

Cant say whether its better or worse than your example?

It is moveable. Did you try the Examples? Edited by guinness

Share this post


Link to post
Share on other sites

Posted (edited)

Sorry i should have said not resizable dunno where my head is today

My apologies

Chimaera

ps edited my earlier post

Edited by Chimaera

Share this post


Link to post
Share on other sites

Posted

I've updated the syntax of the examples. Now the handle of the GUI is assigned to a variable and explicitly used in GUIDelete, rather than relying on the 'previously used' default. Any problems then please post below. Thanks.

Share this post


Link to post
Share on other sites

Posted

very very good

Share this post


Link to post
Share on other sites

Posted

Thanks.

Share this post


Link to post
Share on other sites

Posted

Good job, good stuff, wouldn't it be nice if those examples were present in the help file? along with the most useful udfs and snippets?

Share this post


Link to post
Share on other sites

Posted (edited)

Good job, good stuff, wouldn't it be nice if those examples were present in the help file? along with the most useful udfs and snippets?

Honestly, no. That's not the purpose of the help file I'm afraid, the Forum and help file work in conjunction with one another. Edited by guinness

Share this post


Link to post
Share on other sites

Posted

Yes, they work with each other, but i think sometimes there are bits of code that get "lost" in the forum, like this one you posted, someday you'll probably see someone asking how to create this kind of frame. So if it was present in the help file, maybe not in the function itself of creating windows, but as a "related" function, those who are interested, would check there, instead of scrolling thru dozens of posts to find this one, seems more efficient to me.

Share this post


Link to post
Share on other sites

Posted

The question remains where though. If you have suggestions please post in the help file section under the Developer section, though bare in mind read the first post.

Share this post


Link to post
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
Sign in to follow this  
Followers 0