Jump to content

Have GUI Minimize to Tray instead of Taskbar


Gui
 Share

Recommended Posts

I only know how to have a GUI Minimize to tray b/c of a button. In this case, I want it minimized to tray via the standard GUI Minimize button. I know it's possible, just can't remember how it's done.

PS: It can't just be a standard GUIGetMsg() deal, b/c I want it to be able to be minimized to the tray even within a loop. Thanks!

GUI

EDIT: A possible GUI Registered Command maybe for seeing if the minimize button was pressed? I use it for normal buttons like:

;GUI Creation
GUIRegisterMsg($WM_COMMAND,'command')
GUISetState()
;GUI End

Func command($hwnd,$msg,$wparam,$lparam)
    $nNotifyCode = BitShift($wparam, 16)
    $nID = BitAND($wparam, 0x0000FFFF)
    If $nID = $start Then
        If GUICtrlRead($start) = 'Start' Then
            $running = 1
            GUICtrlSetData($start,'Stop')
        ElseIf GUICtrlRead($start) = 'Stop' Then
            $running = 0
            GUICtrlSetData($start,'Start')
        EndIf
    EndIf
EndFunc
Edited by Gui
Link to comment
Share on other sites

  • Moderators

Gui,

You can remove the button from the taskbar by using the "parent" parameter when you create your GUI. If you do not have a parent, then you can use the ever-present, but hidden, AutoIt window: :)

#include <GUIConstantsEx.au3>

; Create parent
$hGUI = GUICreate("Parent", 500, 500)
GUISetState()

; Use parent handle when creating child
$hGUI_No_TaskBar_1 = GUICreate("Child", 200, 200, 100, 100, Default, Default, $hGUI)
GUISetState()

; Or use the Autoit window
$hGUI_No_TaskBar_2 = GUICreate("AutoIt Child", 200, 200, 200, 200, Default, Default, WinGetHandle(AutoItWinGetTitle()))
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

The icon in the systray/notification area will always be present unless you use #NoTrayIcon or Opt("TrayIconHide").

I hope that helps. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Is this what you want?

#include <GuiConstants.au3>
Global $Msg, $tmsg, $WM_NOTIFY
; ============ Tray Items Start ============
; 1= prmarydown or left click
Opt("TrayMenuMode", 1)
; Set tray Icon
TraySetIcon("Shell32.dll", -87)
;only show the menu when prmarydown or left click
TraySetClick(1)
; Put some Items in the tray
$RestoreTray = TrayCreateItem("Restore")
$ExitTray = TrayCreateItem("Exit")
; ============ Gui Items Start ============
$hGui = GUICreate("Minimize Test")
GUISetState()

; Declare your varibles
Opt('MustDeclareVars', 1)

While 1
    ;Guiloop
    $Msg = GUIGetMsg()
    Switch $Msg
        Case -3
            Exit
        Case $GUI_EVENT_MINIMIZE
            _GuiMinimizeToTray($hGui)
    EndSwitch

    ; switch to get tray messages
    $tmsg = TrayGetMsg()
    Switch $tmsg
        Case $RestoreTray
            WinSetState($hGui, "", @SW_RESTORE)
        Case $ExitTray
            GUIDelete($hGui)
            ExitLoop
    EndSwitch
WEnd

Func _GuiMinimizeToTray($h_wnd)
     
    ; check if 1 = Window exists, then check to see if its 16 = Window is minimized
    If BitAND(WinGetState($h_wnd), 1) Or Not BitAND(WinGetState($h_wnd), 16) Then
        ; change the window state to hide
        WinSetState($h_wnd, "", @SW_HIDE)
    EndIf

EndFunc   ;==>_GuiMinimizeToTray

P.S Nice example Melba

Link to comment
Share on other sites

@Melba, your always the first to respond to most of my inqueries. ;p

In your example though, the GUI's don't go to tray, they are hidden.

@Newbercase, that's the simple point. One issue though, that won't work inside a giant function or loop.

Moreover, if a user clicks the square minimize button on the top of the GUI (even when in a loop/function), I want the GUI to not go to the taskbar minimized but to the tray minimized, where it can also be restored. The issue is it needs to be done inside a loop/function.

That's why I brought up the

GUIRegisterMsg($WM_COMMAND,'command')
It's my favorite b/c it works even when there's a loop/function in place. Problem is that you can't poll for the minimize button being pressed with it.

Sorry if this is confusing. I appreciate your responses guys! Hope this clarifies a little more.

Regards,

GUI

Link to comment
Share on other sites

  • Moderators

Gui,

My example shows how to avoid havng a taskbar button for the GUIs. If you want them to vanish and reappear, then you need to hide/show the GUI when you get a GUI_MINIMIZE/RESTORE event as Newbercase suggested. :)

that won't work inside a giant function or loop

Do you mean that you have a function which takes some time to complete before returning to the script idle loop and so your events are not acted upon? If so, then I recommend the Interrupting a running function tutorial in the Wiki. :)

If not, please explain what you are trying to do - and perhaps provide a short script (even if it fails :P) so we can see where and when the GUI should hide/show. :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I'm familiar with AutoIt inturrupting functions. And yes, the function/loop I'm using is large. I'm already using GUIGetMsg(), so I can't use OnEventMode. Also, I wanted to avoid using hotkeys. I may just need to create a button in order to allow the GUI to minimize to tray.

Thanks guys.

GUI

Link to comment
Share on other sites

You can do this with AdlibRegister() for GUIGetMsg()=

#include <GUIConstantsEx.au3>

Global $cIdTrayRestore
$cIdTrayExit = TrayCreateItem("Exit")

Opt("TrayMenuMode", 1)

$hWnd = GUICreate(@ScriptName, 640, 480)
$cIdButton = GUICtrlCreateButton("Press here to start 42 second long task", 5, 5, 250, 150)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_MINIMIZE
            $cIdTrayRestore = TrayCreateItem("Restore")
            WinSetState($hWnd, "", @SW_HIDE)
        Case $cIdButton
            AdlibRegister("_GUIGetMsg", 40) ;remember that GUIGetMsg() and TrayGetMsg() pauses the script for 10ms each, so the adlib must be way over 20ms, see their pages in the helpfile for details)
            For $iX = 1 To 42
                ConsoleWrite($iX & @CRLF)
                $iTimer = TimerInit()
                Do
                    Sleep(10)
                Until TimerDiff($iTimer) > 1000
            Next
            AdlibUnRegister("_GUIGetMsg")
    EndSwitch

    $iRet = TrayGetMsg()
    Select
        Case $iRet = $cIdTrayExit
            Exit
        Case $cIdTrayRestore <> 0 And $iRet = $cIdTrayRestore
            WinSetState($hWnd, "", @SW_RESTORE)
            TrayItemDelete($cIdTrayRestore)
            $cIdTrayRestore = 0
    EndSelect
WEnd

Func _GUIGetMsg()
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
            Case $GUI_EVENT_MINIMIZE
                $cIdTrayRestore = TrayCreateItem("Restore")
                WinSetState($hWnd, "", @SW_HIDE)
            Case 0
                ExitLoop
        EndSwitch
    WEnd

    While 1
        $iRet = TrayGetMsg()
        Select
            Case $iRet = $cIdTrayExit
                Exit
            Case $cIdTrayRestore <> 0 And $iRet = $cIdTrayRestore
                WinSetState($hWnd, "", @SW_RESTORE)
                TrayItemDelete($cIdTrayRestore)
                $cIdTrayRestore = 0
            Case $iRet = 0
                ExitLoop
        EndSelect
    WEnd
EndFunc

Easy as pie! :)

Link to comment
Share on other sites

In your Msg Loop the value of the minimize button is -4 So you just create another Case statement with that value to do whatever when it's clicked.

Here is some demo code taken from a couple of my scripts

#Include <Constants.au3>
#Include<GUIConstantsEx.au3>
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)
Opt("TrayAutoPause", 0)
Opt("TrayIconHide", 1)

Global Const $sTitle = "Test Window"
$Frm_Main = GUICreate($sTitle)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE ;; -3
            _Quit()
        Case $GUI_EVENT_MINIMIZE  ;; -4
            _GUI_ToTray()
    EndSwitch
WEnd
Func _GUI_ToTray()
    GUISetState(@SW_HIDE, $Frm_Main)
    TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "_GUI_Restore")
    TraySetOnEvent($TRAY_EVENT_SECONDARYUP, "_Quit")
    TrayTip($sTitle, "Left click to restore" & @CRLF & "Right click to Exit", 5, 1)
    ;TraySetToolTip($sTitle & @CRLF & @CRLF & "Left click to restore" & @CRLF & "Right click to Exit")
    TraySetToolTip("")
    Opt("TrayIconHide", 0)
    Return $Frm_Main
EndFunc   ;==>_GUI_ToTray

Func _GUI_Restore()
    GUISetState(@SW_SHOW, $Frm_Main)
    WinActivate($Frm_Main)
    TraySetState(2)
    Opt("TrayIconHide", 1)
EndFunc   ;==>_GUI_Restore

Func _Quit()
    Exit
EndFunc   ;==>_Quit
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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