Jump to content

Comparing the returned value of TrayCreateItem(“Stop”) with value read from a file


AMonari
 Share

Recommended Posts

I've written AutoIt code with regards to system tray functionality and would like to be able to execute the AutoIt systray menu options through Java's systray options.
 
Essentially I start the systray aspect of my code as follows:
 
        ;--------------------------------------
    ; Manage the systray icon
    ;--------------------------------------
    ;0=append, 1=no default menu, 2=no automatic check, 4=menuitemID  not return
    Opt("TrayMenuMode",3)   ; 1 -> Default tray menu items (Script Paused/Exit) will not be shown.
    ; 2 -> No auto tick/untick
   
    $exititem = TrayCreateItem("Stop")
    
    $allowitem = TrayCreateItem("Allow joining")
    
    TraySetState() ; force configuration of systray item according to the opts above
    
    TraySetToolTip("HELLO WORLD")
    
    if FileExists($iconfile) Then ; use external icon if present
    TraySetIcon($iconfile)
    Else
    TraySetIcon(@ScriptName) ; else use our own .exe for the icon
    EndIf
 
I've then got a function ManageTray which I call in a while loop. This is because I've got to watch out for specific COM port messages. In the function ManageTray() I intend on comparing the value of the function TrayCreateItem() (please see above how I've utilised the function TrayCreateItem()) with a value read from a .txt file written in Java i.e. the file exititemeventcontrolid.txt. Below is the code for the function ManageTray.:
 
        Func ManageTray() ; called every time we go round the main loop
       ;$msg = TrayGetMsg()
   
       loggit("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
       
       loggit("START OF ManageTray()")
       
       $eventctrlidFilepath = "C:Usersexititemeventcontrolid.txt"
   
       $eventctrlidfile = FileOpen($eventctrlidfilepath, 0)
    
       If FileExists($eventctrlidfilepath) Then
       
     ; Check if file opened for reading OK
     If $eventctrlidfile = -1 Then
     loggit("$file = -1 hence Unable to open file.")
     ;MsgBox(0, "Error", "Unable to open file.")
     Exit
     EndIf
    
     ; Read in lines of text until the EOF is reached
     $exititemfiledata = FileReadLine($eventctrlidfile)
   
     loggit("Read lines of text until the EOF are: " & $exititemfiledata)
   
     $exititemfiledatastringlength = StringLen($exititemfiledata)
    
     ; Need to check if the file is empty
     if $exititemfiledatastringlength > 0 Then
    
    loggit("$exititemfiledatastringlength > 0")
   
    ;
    ;Create array to take in values
    Local $arreventctrlid[2]
    $arreventctrlid[0] = $exititemfiledata  
    $arreventctrlid[1] = $exititemfiledata  
    
    Local $arreventctrlidsize = UBound($arreventctrlid)
   
    If IsArray($arreventctrlid) Then 
    For $i = 0 to $arreventctrlidsize - 1
      ;MsgBox (0, "$userconfigasarray", "$userconfigasarray["&$i&"] is: "&$userconfigasarray[$i])
      
      loggit("$arreventctrlid["& $i &"] is: " & $arreventctrlid[$i])
      
      loggit("$exititem is: " & $exititem)
      
      Switch $arreventctrlid[$i]
      
    Case $exititem
    leave()
    Case $allowitem
    If BitAND(TrayItemGetState($allowitem), 1) Then ; it's checked, turn it off
    FnPrevent()
    Else
    FnAllow()
    EndIf
     
      EndSwitch
    Next
    EndIf
    ;
   
    ; if allow is still ticked and timer has expired, turn it off
    if BitAND( TrayItemGetState($allowitem), 1) and TimerDiff($tm_allow) >= $AllowWindow then
     FnPrevent()
    EndIf
    
     EndIf
   
        Else
      loggit("FILE DOES NOT EXIST")
      Exit  
    EndIf
   
       loggit("END OF ManageTray()")
       
       loggit("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
    EndFunc
 
My problem is that I'm unable to compare the value I'm reading from my file exititemeventcontrolid.txt with the value returned from the function $exititem = TrayCreateItem("Stop"). 
 
I'm attempting this comparison using the switch statement. I also attempted it using an if ... elseif ... endif statement but had no success.
 
Is there a reason as to why I could be encountering this problem. AFAIK the function TrayCreateItem("Stop") as indicated [here][1] returns the identifier (controlID) of the new tray menuitem.
 
Any ideas/assistance is appreciated.
 
 
Edited by AMonari
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...