Jump to content

Minimize Script To Tray


Recommended Posts

I've already added Opt("TrayAutoPause", 0), all I want now is when I hit the minimize button the program goes to the tray, and when you click the tray icon it comes back up.

Edited by FinalVersion
Link to comment
Share on other sites

Hey!

Did it...

Works for me atleast

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

#NoTrayIcon

Opt('MustDeclareVars', 1)
Opt("TrayMenuMode",1)   ; Default tray menu items (Script Paused/Exit) will not be shown.

local $guiMsg, $trayMsg, $showWindow

;Create GUI
GUICreate("My GUI") ; will create a dialog box that when displayed is centered
GUISetState(@SW_SHOW) ; will display an empty dialog box

;Create Tray Menu
$showWindow = TrayCreateItem("Show Window")


While 1
    
    If WinGetState("My GUI") = 23 Then ; 23 = 1 + 2 + 4 + 16 - Exists, Visible, Enabled, Minimized
        GUISetState(@SW_HIDE)
        Opt("TrayIconHide", 0)
    EndIf
    
    
    ; ---- GUI Shizzle
    $guiMsg = GUIGetMsg()
    Select
        Case $guiMsg = $GUI_EVENT_CLOSE
            ExitLoop    
        
    EndSelect
    
    ; ---- Tray Shizzle
    $trayMsg = TrayGetMsg()
    Select      
        Case $trayMsg = $showWindow     
            GUISetState(@SW_SHOW)
            WinSetState("My GUI", "", @SW_RESTORE)
            Opt("TrayIconHide", 1)
    EndSelect
    
        
WEnd

Let me know

Edited by Steveiwonder

They call me MrRegExpMan

Link to comment
Share on other sites

#NoTrayIcon

#Include <Constants.au3>
#Include <GUIConstantsEx.au3>
#Include <WinAPIEx.au3>
#Include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)
Opt('TrayMenuMode', 1)

Global Const $SC_MINIMIZE = 0xF020

Global $hTray = ControlGetHandle('[CLASS:Shell_TrayWnd]', '', 'TrayNotifyWnd1')
Global $hForm, $GUIMsg, $TrayMsg, $Dummy, $TrayRestoreItem, $TrayExitItem

$TrayRestoreItem = TrayCreateItem('Restore')
TrayItemSetState(-1, $TRAY_DEFAULT)
TrayCreateItem('')
$TrayExitItem = TrayCreateItem('Exit')
TraySetClick(8)

$hForm = GUICreate('My GUI')
$Dummy = GUICtrlCreateDummy()
GUIRegisterMsg($WM_SYSCOMMAND, 'WM_SYSCOMMAND')
GUISetState()

While 1
    $TrayMsg = TrayGetMsg()
    Switch $TrayMsg
        Case $TrayRestoreItem
            _WinAPI_DrawAnimatedRects($hForm, _WinAPI_GetWindowRect($hTray), _WinAPI_GetWindowRect($hForm))
            GUISetState(@SW_SHOW, $hForm)
            TraySetState(2)
        Case $TrayExitItem
            ExitLoop
    EndSwitch
    $GUIMsg = GUIGetMsg()
    Switch $GUIMsg
        Case $GUI_EVENT_CLOSE
            _WinAPI_AnimateWindow($hForm, BitOR($AW_BLEND, $AW_HIDE))
            ExitLoop
        Case $Dummy ; Minimize
            _WinAPI_DrawAnimatedRects($hForm, _WinAPI_GetWindowRect($hForm), _WinAPI_GetWindowRect($hTray))
            GUISetState(@SW_HIDE, $hForm)
            TraySetState(1)
    EndSwitch
WEnd

Func WM_SYSCOMMAND($hWnd, $iMsg, $wParam, $lParam)
    Switch $hWnd
        Case $hForm
            Switch $wParam
                Case $SC_MINIMIZE
                    GUICtrlSendToDummy($Dummy)
                    Return 0
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SYSCOMMAND

WinAPIEx.au3

Link to comment
Share on other sites

@Stevie How could I incorporate it into my current GUI? I took a shot but failed.

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include "Ini.au3"


$frmMain = GUICreate("Application QuickStart", 451, 331, 192, 124)
$Settings = GUICtrlCreateGroup("Settings", 8, 8, 433, 169)
$lblPath = GUICtrlCreateLabel("Path to Executable:", 24, 32, 97, 17)
$txtPath = GUICtrlCreateInput("", 24, 56, 201, 21)
$lblExe = GUICtrlCreateLabel("Executable:", 296, 32, 60, 17)
$lblParams = GUICtrlCreateLabel("Parameters:", 24, 96, 60, 17)
$txtParams = GUICtrlCreateInput("", 24, 120, 201, 21)
$txtExe = GUICtrlCreateInput("", 296, 56, 113, 21)
$lblState = GUICtrlCreateLabel("Window State:", 296, 96, 74, 17)
$CState = GUICtrlCreateCombo("", 296, 120, 113, 25)
$btnLaunch = GUICtrlCreateButton("Launch", 80, 144, 129, 25, $WS_GROUP)
$btnReset = GUICtrlCreateButton("Reset", 240, 144, 129, 25, $WS_GROUP)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$lstCore = GUICtrlCreateList("", 8, 184, 433, 138)
GUICtrlSetFont(-1, $FSize, 400, 0, $Font)
GUICtrlSetColor(-1, 0x00FF00)
GUICtrlSetBkColor(-1, 0x000000)
GUISetState(@SW_SHOW)

GUICtrlSetData($txtPath, $DefaultPath)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $btnLaunch
            Launch()
            GUICtrlSetData($txtPath, $DefaultPath)
        Case $btnReset
            Reset()
            Cout("Reset Form Data!", $lstCore)
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Link to comment
Share on other sites

Sorry for late reply, have been asleep all day (working nights)

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include "Ini.au3"

#NoTrayIcon
Opt("TrayMenuMode",1)   ; Default tray menu items (Script Paused/Exit) will not be shown.



Local $trayMsg, $showWindow
;Tray stuff
$showWindow = TrayCreateItem("Show Window")


;GUI Stuff
$guiWinTitle = "Application QuickStart"
$frmMain = GUICreate($guiWinTitle, 451, 331, 192, 124)
$Settings = GUICtrlCreateGroup("Settings", 8, 8, 433, 169)
$lblPath = GUICtrlCreateLabel("Path to Executable:", 24, 32, 97, 17)
$txtPath = GUICtrlCreateInput("", 24, 56, 201, 21)
$lblExe = GUICtrlCreateLabel("Executable:", 296, 32, 60, 17)
$lblParams = GUICtrlCreateLabel("Parameters:", 24, 96, 60, 17)
$txtParams = GUICtrlCreateInput("", 24, 120, 201, 21)
$txtExe = GUICtrlCreateInput("", 296, 56, 113, 21)
$lblState = GUICtrlCreateLabel("Window State:", 296, 96, 74, 17)
$CState = GUICtrlCreateCombo("", 296, 120, 113, 25)
$btnLaunch = GUICtrlCreateButton("Launch", 80, 144, 129, 25, $WS_GROUP)
$btnReset = GUICtrlCreateButton("Reset", 240, 144, 129, 25, $WS_GROUP)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$lstCore = GUICtrlCreateList("", 8, 184, 433, 138)
GUICtrlSetFont(-1, $FSize, 400, 0, $Font)
GUICtrlSetColor(-1, 0x00FF00)
GUICtrlSetBkColor(-1, 0x000000)
GUISetState(@SW_SHOW)

GUICtrlSetData($txtPath, $DefaultPath)
While 1
    
    If WinGetState($guiWinTitle) = 23 Then ; 23 = 1 + 2 + 4 + 16 - Exists, Visible, Enabled, Minimized
        GUISetState(@SW_HIDE)
        Opt("TrayIconHide", 0)
    EndIf
    
    $trayMsg = TrayGetMsg()
    Select      
        Case $trayMsg = $showWindow     
            GUISetState(@SW_SHOW)
            WinSetState($guiWinTitle, "", @SW_RESTORE)
            Opt("TrayIconHide", 1)
    EndSelect

    
    
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $btnLaunch
            Launch()
            GUICtrlSetData($txtPath, $DefaultPath)
        Case $btnReset
            Reset()
            Cout("Reset Form Data!", $lstCore)
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Worked for me.

They call me MrRegExpMan

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