Jump to content
Sign in to follow this  
wraithdu

Create a Gui WITH a Minimize button, WITHOUT a Toolbar button

Recommended Posts

wraithdu

My reason for figuring this out was pretty simple. I have an app that I want to run in the tray but not have a toolbar button. Now, you can use $WS_EX_TOOLWINDOW, but then the gui has no minimize button. You could also trap the $GUI_EVENT_MINIMIZE along with Opt("GUIEventOptions", 1) and hide the window, but then you can't send events to controls in OnEventMode. Control events do not fire when the window is hidden (I think this still works in MessageMode however). This was the deal breaker for me, as my script uses OnEventMode and needed to fire events for a custom context menu triggered by a hotkey.

So in the end I needed a window that would not be seen (but not hidden), with a minimize button, without a toolbar button. Here's two options. Option 1 has a toolbar button when the window is maximized / restored. Option 2 never has a toolbar button. Note that in Option 2 you could replace the Move with a WinSetTrans(0 / 255).

Option 1 -

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>

Opt("GUIOnEventMode", 1)
Opt("TrayOnEventMode", 1)
Opt("GUIEventOptions", 1)
Opt("TrayMenuMode", 1)

Global $wPos

$gui = GUICreate("My GUI")

GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Minimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Maximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "Restore")

TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN, "Restore")

GUISetState()

While 1
    Sleep(1000)
WEnd

Func Minimize()
    $wPos = WinGetPos($gui)
    GUISetState(@SW_HIDE, $gui)
    GUISetStyle(-1, $WS_EX_TOOLWINDOW, $gui)
    WinMove($gui, "", -9999, -9999)
    GUISetState(@SW_SHOW, $gui)
EndFunc

Func Maximize()
    GUISetState(@SW_HIDE, $gui)
    GUISetStyle(-1, 0, $gui)
    WinMove($gui, "", $wPos[0], $wPos[1])
    GUISetState(@SW_SHOW, $gui)
EndFunc

Func Restore()
    GUISetState(@SW_HIDE, $gui)
    GUISetStyle(-1, 0, $gui)
    WinMove($gui, "", $wPos[0], $wPos[1])
    GUISetState(@SW_SHOW, $gui)
EndFunc

Func Close()
    Exit
EndFunc

Option 2 -

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>

Opt("GUIOnEventMode", 1)
Opt("TrayOnEventMode", 1)
Opt("GUIEventOptions", 1)
Opt("TrayMenuMode", 1)

Global $wPos

$dummy = GUICreate("", -1, -1, -1, -1, -1, $WS_EX_TOOLWINDOW)
$gui = GUICreate("My GUI", -1, -1, -1, -1, -1, -1, $dummy)

GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Minimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Restore")
GUISetOnEvent($GUI_EVENT_RESTORE, "Restore")

TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN, "Restore")

GUISetState()

While 1
    Sleep(1000)
WEnd

Func Minimize()
    $wPos = WinGetPos($gui)
    WinMove($gui, "", -9999, -9999)
EndFunc

Func Restore()
    WinMove($gui, "", $wPos[0], $wPos[1])
EndFunc

Func Close()
    Exit
EndFunc
Edited by wraithdu

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  

×