happy2help Posted March 10, 2010 Share Posted March 10, 2010 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 expandcollapse popup#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. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 10, 2010 Moderators Share Posted March 10, 2010 happy2help, Does this make it any clearer? expandcollapse popup#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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
happy2help Posted March 10, 2010 Author Share Posted March 10, 2010 (edited) Thanks, here it is all working expandcollapse popup#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 March 10, 2010 by happy2help Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now