Jump to content

Tray menu exit not working


Recommended Posts

Sorry to be a bother. This code seems to be working as I want to except that the exit option on the tray menu doesn't do anything.

#NoTrayIcon
#include <File.au3>
#include <MsgBoxConstants.au3>
#include <TrayConstants.au3> ; Required for the $TRAY_ICONSTATE_SHOW constant.
#include <funcs.au3>

Global $aFileArray
Global $mFile = "c:\print\print.txt"
_FileWriteLog(@ScriptDir & "\Example.log", "Program Started, lets rock!")
Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode.


    Local $idExit = TrayCreateItem("Exit")
    Global $isOpen = 0
    TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu.

    While 1

      Switch TrayGetMsg()
         Case $idExit ; Exit the loop.
         Exit
      EndSwitch
      Local $checkFile = _FileInUse($mFile)
      If $checkFile == 1 Then
         $isOpen = 1

         sleep(1000)
      Elseif $checkfile == 0 Then
         $isOpen = 0

         sleep(1000)
      EndIf
      If $isOpen == 0 Then

            If Not FileExists($mFile) Then
               ;file no exist do nothing
            Else
               ;check if file is in use one more Time
               Local $checkAgain = _FileInUse($mFile)
               if $checkAgain == 1 Then
                  ; file still open lets sleep for a bit and go again
                  Sleep(10000)
               Else
                  ;print the file
                  If FileExists("c:\print\print.txt") Then
                     If Not _FileReadToArray("c:\print\print.txt", $aFileArray) Then
                        _FileWriteLog(@ScriptDir & "\Example.log", "Read print.txt failed with error code" & @error & ". Program halted.")
                        Exit
                     Else
                        _FileWriteLog(@ScriptDir & "\Example.log", "Read print.txt successful, moving on")
                     EndIf
                     Global $aStart
                     If Not $aStart = _ArrayFindAll($aFileArray , "SEVEN UP" , '' , '' , '' , 1) Then
                        _FileWriteLog(@ScriptDir & "\Example.log", "Failed to find Sevenup name. Error " & @error & ". Program halted.")
                        Exit
                     Else
                        _FileWriteLog(@ScriptDir & "\Example.log", "Find Sevenup name, succesful, moving on")
                        $aStart = _ArrayFindAll($aFileArray , "SEVEN UP" , '' , '' , '' , 1)
                     EndIf
                     for $i = 0 to ubound($aStart) - 1
                        If $i = ubound($aStart) - 1 Then
                             _FileWriteFromArray("c:\print\OUTPUT_" & $i & ".txt" , $aFileArray , $aStart[$i] , $aFileArray[0])
                             _FileWriteLog(@ScriptDir & "\Example.log", "Split file " & $i & " created")
                             ;_FileWriteLine_top("c:\print\OUTPUT_" & $i & ".txt", @CRLF)
                             _FilePrint("c:\print\OUTPUT_" & $i & ".txt")
                             _FileWriteLog(@ScriptDir & "\Example.log", "Split file " & $i & " printed")
                              Sleep(500)
                              FileDelete("c:\print\OUTPUT_" & $i & ".txt")
                              _FileWriteLog(@ScriptDir & "\Example.log", "Split file " & $i & " deleted")
                        Else
                             $next = $i + 1
                             _FileWriteFromArray("c:\print\OUTPUT_" & $i & ".txt" , $aFileArray , $aStart[$i] , $aStart[$next] - 1)
                             _FileWriteLog(@ScriptDir & "\Example.log", "Split file " & $i & " created")
                            ; _FileWriteLine_top("c:\print\OUTPUT_" & $i & ".txt", @CR)
                             _FilePrint("c:\print\OUTPUT_" & $i & ".txt")
                             _FileWriteLog(@ScriptDir & "\Example.log", "Split file " & $i & " printed")
                              Sleep(500)
                              FileDelete("c:\print\OUTPUT_" & $i & ".txt")
                              _FileWriteLog(@ScriptDir & "\Example.log", "Split file " & $i & " deleted")
                        EndIf
                     next
                     FileDelete("c:\print\print.txt")
                  EndIf
               EndIf
            EndIf


      Elseif $isOpen == 1 Then

            If Not FileExists($mFile) Then
               ;do nothing
            Else
               Local $check = _FileInUse($mFile)
               If $check == 1 Then
                  ; file in use drop out and check again
               Elseif $check == 0 Then
                  ; file is free, check $isOpen to 0
                  $isOpen = 0
               EndIf
            EndIf
      Endif
WEnd

Thanks for your help. I appreciate it.

Link to comment
Share on other sites

The default tray items take precedence...specifically the 'pause on click' one...

Opt("TrayMenuMode", 1)
Global $idExit = TrayCreateItem("Exit")
TraySetState()
AdlibRegister("ExitScript",10)
While True
    Sleep(10)
Wend

Func ExitScript()
    If TrayGetMsg()=$idExit Then
        AdlibUnRegister("ExitScript")
        Exit
    EndIf
EndFunc
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
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...