Jump to content
Sign in to follow this  
happy2help

GUI Show/Hide from systray

Recommended Posts

happy2help

Hi all

I need some help with the script i'm using. I use the script as is, but would like to be able to hide the GUI till i need it.

The easiest way is to use the icon in the systray, clicking on the "Show / Hide GUI" option.

Here is my current script

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=C:\Users\Public\Backup\Batch files\Icons\FOLDER.ICO
#AutoIt3Wrapper_outfile=C:\Users\Tony\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\CopyFiles.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListBoxConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>


#Region ;reading directories and putting it in a list
$sFileList = ""
$sFileList2 = ""
$sFolderList = ""
$sScripts = "B:\Scripts\"
$sToUse = "B:\Scripts\To Use\"
$aFileList = _FileListToArray($sToUse, "*", 1)
If @error = 1 Then
    MsgBox(0, "", "No Files\Folders Found.")
    Exit
EndIf
For $i = 1 To $aFileList[0]
    $sFileList &= $aFileList[$i] & "|"
Next
$aFolderList = _FileListToArray($sScripts, "*", 2)
If @error = 1 Then
    MsgBox(0, "", "No Files\Folders Found.")
    Exit
EndIf
For $i = 1 To $aFolderList[0]
    If $aFolderList[$i] <> "To Use" Then
        $sFolderList &= $aFolderList[$i] & "|"
    EndIf
Next
#EndRegion 

#Region ; create GUI
$Form1 = GUICreate("Script Copier", 360, 300, 193, 125)
$List1 = GUICtrlCreateList("", 20, 20, 120, 270)
$List2 = GUICtrlCreateList("", 150, 20, 120, 270)
$Button1 = GUICtrlCreateButton("Copy Now", 280, 20, 73, 49, 0)
$Button2 = GUICtrlCreateButton("Update ini File", 280, 100, 73, 49, 0)
GUICtrlSetData($List1, $sFileList)
GUICtrlSetData($List2, $sFolderList)
GUISetState(@SW_SHOW)
#EndRegion 

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            CopyPressed()
        Case $Button2
            UpDate()
    EndSwitch
WEnd

Func CopyPressed()
    MsgBox(0, "Button Pressed", "About to copy the file you have selected", 3)
    $Value1 = GUICtrlRead($List1)
    $Value2 = GUICtrlRead($List2)
    If FileExists($sScripts & $Value2 & "\" & $Value1) Then MsgBox(0, "ERROR", $sScripts & $Value2 & "\" & $Value1 & " already exists")
    FileCopy($sToUse & $Value1, $sScripts & $Value2 & "\")
    If FileExists($sScripts & $Value2 & "\" & $Value1) Then
        $answer = MsgBox(0, $sToUse & $Value1, $sScripts & $Value2 & "\" & $Value1 & " Exists", 30)
        If $answer = -1 Then Exit
    EndIf
EndFunc   ;==>CopyPressed

Func UpDate()
    $file = FileOpen("FolderMonitor.ini", 2)
    If $file = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf
    For $i = 1 To $aFileList[0]
        $sFileList2 &= $aFileList[$i] & @CRLF
    Next
    FileWrite($file, $sFileList2)
    FileClose($file)
    MsgBox(0, "Done", "FolderMonitor.ini now Up To Date.")
EndFunc   ;==>UpDate

I have searched the help file but can't see the wood for the trees!!

Please help me or give me a scriptlet to add to mine.

Share this post


Link to post
Share on other sites
Melba23

happy2help,

Does this make it any clearer? :mellow:

#include <GUIConstantsEx.au3>

Opt("TrayOnEventMode", 1) ; Use event trapping for tray menu
Opt("TrayMenuMode", 3) ; Default tray menu items will not be shown

Global $hTray_Show_Item = TrayCreateItem("Hide")
TrayItemSetOnEvent(-1, "On_Tray_Show")
TrayCreateItem("")
Global $hTray_Exit_Item = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "On_Exit")

$hGUI = GUICreate("Test", 500, 500)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

Func On_Exit()
    Exit
EndFunc

Func On_Tray_Show()

    If TrayItemGetText($hTray_Show_Item) = "Hide" Then
        TrayItemSetText($hTray_Show_Item, "Show")
        GUISetState(@SW_HIDE, $hGUI)
    Else
        TrayItemSetText($hTray_Show_Item, "Hide")
        GUISetState(@SW_SHOW, $hGUI)
    EndIf

EndFunc   ;==>On_Tray_Show

If not, then please ask again! :(

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
happy2help

Thanks, here it is all working

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=C:\Users\Public\Backup\Batch files\Icons\FOLDER.ICO
#AutoIt3Wrapper_outfile=C:\Users\Tony\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\CopyFiles.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListBoxConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>

Opt("TrayOnEventMode", 1) ; Use event trapping for tray menu
Opt("TrayMenuMode", 3) ; Default tray menu items will not be shown

Global $hTray_Show_Item = TrayCreateItem("Show")
TrayItemSetOnEvent(-1, "On_Tray_Show")
TrayCreateItem("")
Global $hTray_Exit_Item = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "On_Exit")

#Region ;reading directories and putting it in a list
$sFileList = ""
$sFileList2 = ""
$sFolderList = ""
$sScripts = "B:\Scripts\"
$sToUse = "B:\Scripts\To Use\"
$aFileList = _FileListToArray($sToUse, "*", 1)
If @error = 1 Then
    MsgBox(0, "", "No Files\Folders Found.")
    Exit
EndIf
For $i = 1 To $aFileList[0]
    $sFileList &= $aFileList[$i] & "|"
Next
$aFolderList = _FileListToArray($sScripts, "*", 2)
If @error = 1 Then
    MsgBox(0, "", "No Files\Folders Found.")
    Exit
EndIf
For $i = 1 To $aFolderList[0]
    If $aFolderList[$i] <> "To Use" Then
        $sFolderList &= $aFolderList[$i] & "|"
    EndIf
Next
#EndRegion 

#Region ; create GUI
$Form1 = GUICreate("Script Copier", 360, 300, 193, 125)
$List1 = GUICtrlCreateList("", 20, 20, 120, 270)
$List2 = GUICtrlCreateList("", 150, 20, 120, 270)
$Button1 = GUICtrlCreateButton("Copy Now", 280, 20, 73, 49, 0)
$Button2 = GUICtrlCreateButton("Update ini File", 280, 100, 73, 49, 0)
GUICtrlSetData($List1, $sFileList)
GUICtrlSetData($List2, $sFolderList)
GUISetState(@SW_HIDE)
#EndRegion 

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            CopyPressed()
        Case $Button2
            UpDate()
    EndSwitch
WEnd

Func CopyPressed()
    MsgBox(0, "Button Pressed", "About to copy the file you have selected", 3)
    $Value1 = GUICtrlRead($List1)
    $Value2 = GUICtrlRead($List2)
    If FileExists($sScripts & $Value2 & "\" & $Value1) Then MsgBox(0, "ERROR", $sScripts & $Value2 & "\" & $Value1 & " already exists")
    FileCopy($sToUse & $Value1, $sScripts & $Value2 & "\")
    If FileExists($sScripts & $Value2 & "\" & $Value1) Then
        $answer = MsgBox(0, $sToUse & $Value1, $sScripts & $Value2 & "\" & $Value1 & " Exists", 30)
        If $answer = -1 Then Exit
    EndIf
EndFunc   ;==>CopyPressed

Func UpDate()
    $file = FileOpen("FolderMonitor.ini", 2)
    If $file = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf
    For $i = 1 To $aFileList[0]
        $sFileList2 &= $aFileList[$i] & @CRLF
    Next
    FileWrite($file, $sFileList2)
    FileClose($file)
    MsgBox(0, "Done", "FolderMonitor.ini now Up To Date.")
EndFunc   ;==>UpDate

Func On_Exit()
    Exit
EndFunc

Func On_Tray_Show()

    If TrayItemGetText($hTray_Show_Item) = "Show" Then
        TrayItemSetText($hTray_Show_Item, "Hide")
        GUISetState(@SW_SHOW, $Form1)
    Else
        TrayItemSetText($hTray_Show_Item, "Show")
        GUISetState(@SW_HIDE, $Form1)
    EndIf

EndFunc   ;==>On_Tray_Show
Edited by happy2help

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  

×