Sign in to follow this  
Followers 0
Doxie

Whats wrong with Traymenu

3 posts in this topic

#1 ·  Posted (edited)

Hi guys,

It was a couple of years :P since i posted here...

I got a problem with a new code, and wonder if someone could help me.

If WinExists("ToDo") Then
Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(16,"Warning","ToDo Already started",10)
Select
   Case $iMsgBoxAnswer = -1;Timeout

   Case Else              ;OK

EndSelect
Exit    
EndIf

    #include <GUIConstants.au3>
;------------------------------------------------------------
;#NoTrayIcon

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

;$opentodo    = TrayCreateItem("Open ToDo (F7)")
;TrayCreateItem("")
;$aboutitem   = TrayCreateItem("About ToDo")
;TrayCreateItem("")
;$exititem     = TrayCreateItem("Exit")

;TraySetState()
;While 1
;   $msg = TrayGetMsg()
;   Select
;       Case $msg = 0
;           ContinueLoop
;       Case $msg = $aboutitem
;           Msgbox(64,"About:","ToDo Ver 2.0" & @LF & "Copyright 2005")
;       Case $msg = $opentodo
;           WinSetState("ToDo", "", @SW_SHOW)
;       Case $msg = $exititem
;           ExitLoop
;   EndSelect
;WEnd
;Exit
;------------------------------------------------------------
$PostIt = GUICreate("ToDo", 405, 378, 295, 183)
GUISetIcon("C:\wdlogo.ico")
$Input = GUICtrlCreateInput("", 50, 0, 300, 21, -1, $WS_EX_CLIENTEDGE)
$Add = GUICtrlCreateButton("Add", 0, 24, 75, 25)
GUICtrlSetTip(-1, "Add new Todo")
$Edit = GUICtrlCreateButton("Edit", 80, 24, 75, 25)
GUICtrlSetTip(-1, "Edit Todo")
$Oppd = GUICtrlCreateButton("Update", 160, 24, 75, 25)
GUICtrlSetTip(-1, "Update Todo")
$ViewComment = GUICtrlCreateButton("View Comments", 240, 24, 83, 25)
GUICtrlSetTip(-1, "View all comments of current Todo")
$Finito = GUICtrlCreateButton("Finito", 328, 24, 75, 25)
GUICtrlSetTip(-1, "Remove Todo")
$ListView = GUICtrlCreateListView("ID|TODO                                           ", 8, 56, 385, 233)
;GUISetBkColor (0x00E0FFFF); will change background color
$AddComment = GUICtrlCreateButton("Add Comment", 240, 344, 73, 25)
GUICtrlSetTip(-1, "Add comment to Todo")
$Aspy = GUICtrlCreateButton("User online", 8, 344, 73, 25)
GUICtrlSetTip(-1, "Check if user is online")
$wait = GUICtrlCreateButton("10 min", 88, 344, 73, 25)
GUICtrlSetTip(-1, "Remind me in 10 minutes")
$tellme = GUICtrlCreateButton("Schedule", 168, 344, 65, 25)
GUICtrlSetTip(-1, "Setup reminder")
$Checkbox1 = GUICtrlCreateCheckbox("Dont add comment", 8, 312, 129, 17)
GUICtrlSetTip(-1, "Use below action, stand alone")
$closed = GUICtrlCreateButton("View Closed", 320, 344, 81, 25)
GUISetState(@SW_SHOW)

I marked out the code i have problem with, but also posted some other code, so you can see where i added the tray code.

The problem is that when i use the above code, i cant use my own buttons.

The tray menu is working great, and it launch the GUI, but no "options" is working.

Anyone able to give me an idea?

Thanks in advance

Edit:

Its like when the menu is running it pause the rest of the script.

Because when i exit the program once, i "unlock" it, and can work with my own buttons.

Second time i close it, it really close.

Edited by Doxie

Were ever i lay my script is my home...

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Give this a try and see what you think event driven, on the todo I only set the event for the close view just to give you the idea of what you can do.

If WinExists("ToDo") Then
   Dim $iMsgBoxAnswer
   $iMsgBoxAnswer = MsgBox(16, "Warning", "ToDo Already started", 10)
   Select
      Case $iMsgBoxAnswer = -1;Timeout
         
      Case Else          ;OK
         
   EndSelect
   Exit
EndIf

#include <GUIConstants.au3>
#include <Constants.au3>
;------------------------------------------------------------
#NoTrayIcon

opt("GUIOnEventMode", 1)
opt("TrayMenuMode", 1); Default tray menu items (Script Paused/Exit) will not be shown.
opt("TrayOnEventMode", 1)

$opentodo = TrayCreateItem("Open ToDo (F7)")
TrayItemSetOnEvent($opentodo, "_ToDo")
TrayCreateItem("")
$aboutitem = TrayCreateItem("About ToDo")
TrayItemSetOnEvent($aboutitem, "_About")
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")
TrayItemSetOnEvent($exititem, "_Exit")
TraySetState()

;------------------------------------------------------------
$PostIt = GUICreate("ToDo", 405, 378, 295, 183)
GUISetIcon("C:\wdlogo.ico")
$Input = GUICtrlCreateInput("", 50, 0, 300, 21, -1, $WS_EX_CLIENTEDGE)
$Add = GUICtrlCreateButton("Add", 0, 24, 75, 25)
GUICtrlSetTip(-1, "Add new Todo")
$Edit = GUICtrlCreateButton("Edit", 80, 24, 75, 25)
GUICtrlSetTip(-1, "Edit Todo")
$Oppd = GUICtrlCreateButton("Update", 160, 24, 75, 25)
GUICtrlSetTip(-1, "Update Todo")
$ViewComment = GUICtrlCreateButton("View Comments", 240, 24, 83, 25)
GUICtrlSetTip(-1, "View all comments of current Todo")
$Finito = GUICtrlCreateButton("Finito", 328, 24, 75, 25)
GUICtrlSetTip(-1, "Remove Todo")
$ListView = GUICtrlCreateListView("ID|TODO                                           ", 8, 56, 385, 233)
;GUISetBkColor (0x00E0FFFF); will change background color
$AddComment = GUICtrlCreateButton("Add Comment", 240, 344, 73, 25)
GUICtrlSetTip(-1, "Add comment to Todo")
$Aspy = GUICtrlCreateButton("User online", 8, 344, 73, 25)
GUICtrlSetTip(-1, "Check if user is online")
$wait = GUICtrlCreateButton("10 min", 88, 344, 73, 25)
GUICtrlSetTip(-1, "Remind me in 10 minutes")
$tellme = GUICtrlCreateButton("Schedule", 168, 344, 65, 25)
GUICtrlSetTip(-1, "Setup reminder")
$Checkbox1 = GUICtrlCreateCheckbox("Dont add comment", 8, 312, 129, 17)
GUICtrlSetTip(-1, "Use below action, stand alone")
$closed = GUICtrlCreateButton("View Closed", 320, 344, 81, 25)
GUICtrlSetOnEvent($closed, "_CloseToDo")

While 1
   Sleep(100)
WEnd

Func _About()
   MsgBox(64, "About:", "ToDo Ver 2.0" & @LF & "Copyright 2005")
EndFunc  ;==>_About

Func _Exit()
   Exit
EndFunc  ;==>_Exit

Func _ToDo()
    TrayItemSetState($opentodo,$TRAY_DISABLE)
   GUISetState(@SW_SHOW)
EndFunc  ;==>_ToDo

Func _CloseToDo()
   GUISetState(@SW_HIDE)
    TrayItemSetState($opentodo,$TRAY_ENABLE)
EndFunc  ;==>_CloseToDo
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Still not working.

I post the complete code here, so you can check for yourself.

You need to use Beta to compile it, and some options might not

work, since its connected to our servers. But you will get the idea :P

If WinExists("ToDo") Then
   Dim $iMsgBoxAnswer
   $iMsgBoxAnswer = MsgBox(16, "Warning", "ToDo Already started", 10)
   Select
      Case $iMsgBoxAnswer = -1;Timeout
         
      Case Else         ;OK
         
   EndSelect
   Exit
EndIf

#include <GUIConstants.au3>
#include <Constants.au3>
;------------------------------------------------------------
#NoTrayIcon

opt("GUIOnEventMode", 1)
opt("TrayMenuMode", 1); Default tray menu items (Script Paused/Exit) will not be shown.
opt("TrayOnEventMode", 1)

$opentodo = TrayCreateItem("Open ToDo (F7)")
TrayItemSetOnEvent($opentodo, "_ToDo")
TrayCreateItem("")
$aboutitem = TrayCreateItem("About ToDo")
TrayItemSetOnEvent($aboutitem, "_About")
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")
TrayItemSetOnEvent($exititem, "_Exit")
TraySetState()

;------------------------------------------------------------
$PostIt = GUICreate("ToDo", 405, 378, 295, 183)
GUISetIcon("C:\wdlogo.ico")
$Input = GUICtrlCreateInput("", 50, 0, 300, 21, -1, $WS_EX_CLIENTEDGE)
$Add = GUICtrlCreateButton("Add", 0, 24, 75, 25)
GUICtrlSetTip(-1, "Add new Todo")
$Edit = GUICtrlCreateButton("Edit", 80, 24, 75, 25)
GUICtrlSetTip(-1, "Edit Todo")
$Oppd = GUICtrlCreateButton("Update", 160, 24, 75, 25)
GUICtrlSetTip(-1, "Update Todo")
$ViewComment = GUICtrlCreateButton("View Comments", 240, 24, 83, 25)
GUICtrlSetTip(-1, "View all comments of current Todo")
$Finito = GUICtrlCreateButton("Finito", 328, 24, 75, 25)
GUICtrlSetTip(-1, "Remove Todo")
$ListView = GUICtrlCreateListView("ID|TODO                                           ", 8, 56, 385, 233)
;GUISetBkColor (0x00E0FFFF); will change background color
$AddComment = GUICtrlCreateButton("Add Comment", 240, 344, 73, 25)
GUICtrlSetTip(-1, "Add comment to Todo")
$Aspy = GUICtrlCreateButton("User online", 8, 344, 73, 25)
GUICtrlSetTip(-1, "Check if user is online")
$wait = GUICtrlCreateButton("10 min", 88, 344, 73, 25)
GUICtrlSetTip(-1, "Remind me in 10 minutes")
$tellme = GUICtrlCreateButton("Schedule", 168, 344, 65, 25)
GUICtrlSetTip(-1, "Setup reminder")
$Checkbox1 = GUICtrlCreateCheckbox("Dont add comment", 8, 312, 129, 17)
GUICtrlSetTip(-1, "Use below action, stand alone")
$closed = GUICtrlCreateButton("View Closed", 320, 344, 81, 25)
GUICtrlSetOnEvent($closed, "_CloseToDo")

While 1
   Sleep(100)
WEnd

Func _About()
   MsgBox(64, "About:", "ToDo Ver 2.0" & @LF & "Copyright 2005")
EndFunc ;==>_About

Func _Exit()
   Exit
EndFunc ;==>_Exit

Func _ToDo()
    TrayItemSetState($opentodo,$TRAY_DISABLE)
   GUISetState(@SW_SHOW)
EndFunc ;==>_ToDo

Func _CloseToDo()
   GUISetState(@SW_HIDE)
    TrayItemSetState($opentodo,$TRAY_ENABLE)
EndFunc ;==>_CloseToDo


If NOT (FileExists ( "todo.ini" )) Then
$file3 = FileOpen("todo.ini", 2)

; Check if file opened for writing OK
If $file3 = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

FileWriteLine($file3, "")
FileClose($file3)
EndIf


;$file = FileOpen("todo.ini", 0)

; Check if file opened for reading OK
;If $file = -1 Then
;   MsgBox(0, "Error", "Unable to open file.")
;   Exit
;EndIf
;
; Read in lines of text until the EOF is reached
;While 1
;   $line = FileReadLine($file)
;   If @error = -1 Then ExitLoop
   ;MsgBox(0, "Line read:", $line)
;   If NOT ($line == "") Then
;   GuiCtrlCreateListViewItem($line, $listView)
;   EndIf
;Wend

;FileClose($file)
$ids = IniReadSectionNames ( "todo.ini")
If NOT @error Then 


For $i = 1 to $ids[0]
    GuiCtrlCreateListViewItem($ids[$i] & "|" & IniRead ( "todo.ini", $ids[$i], "todo", "ERROR" ), $listView)
Next

EndIf
oppd()
HotKeySet ( "{F5}" ,"oppd" )
HotKeySet ( "{F6}" ,"hidden" )
HotKeySet ( "{F7}" ,"maxi" )



Func hidden()
         TrayTip ( "Hidden", "ToDo has been minimized, press F7 to open again", 2, 1 )

         WinSetState("ToDo", "", @SW_HIDE)
EndFunc
Func maxi()
         WinSetState("ToDo", "", @SW_SHOW)

EndFunc

GuiSetState()
While 1
$msg = GUIGetMsg()

   Select
   
    ;Check if user clicked on the close button
      Case $msg = $GUI_EVENT_CLOSE
       ;Destroy the GUI including the controls
        ;Save()
        ;Exit the script
         Exit

;Check if user clicked on the mini button
      Case $msg = $GUI_EVENT_MINIMIZE
       ;Destroy the GUI including the controls
        ;Save()
        ;Exit the script
     hidden()

         
    ;Check if user clicked on the "OK" button
      Case $msg = $add
         $edittext =GUICtrlRead ( $input )
    If NOT ($edittext == "") Then
    $id =rand()
    add ($edittext,$id)
         GuiCtrlCreateListViewItem($id & "|" & $edittext, $listView)
     GuiCtrlSetData($input, "")
    EndIf


;Check if user clicked on the "OK" button
      Case $msg = $closed
    FileCopy ( "rapport.xls", "closed.xls" , 1 )
    Run ( "C:\Program Files\Microsoft Office\OFFICE11\excel.exe closed.xls" )



    ;Check if user clicked on the "CANCEL" button
      Case $msg = $edit
    $edittext =GUICtrlRead ( $listView )
    $edittext2 = GUICtrlRead ( $edittext )
    If NOT ($edittext = 0) Then
    $minusid = StringSplit ( $edittext2, "|")

            $answer = InputBox("Edit", "Her kan du endre:", $minusid[2])

    $answer = $minusid[1] &"|"& $answer 

    If @error == 1 Then
    Else
    GUICtrlDelete($edittext)
              remove ($edittext2)
    add($answer, $minusid[1])
    GuiCtrlCreateListViewItem($answer, $listView)
    EndIf
    Else
    MsgBox(64, "Edit", "Chose a todo to edit")
    EndIf


;Check if user clicked on the "Add Comment" button
      Case $msg = $AddComment
    $edittext =GUICtrlRead ( $listView )
    $edittext2 = GUICtrlRead ( $edittext )
    If NOT ($edittext = 0) Then
    $minusid = StringSplit ( $edittext2, "|")
    $comment = InputBox("Comment", "Add Comment:", "")
    AddComment($comment, $minusid[1])
    Else
    MsgBox(64, "Edit", "Chose a todo to add commment")
    EndIf




;Check if user clicked on the "Comments" button
      Case $msg = $ViewComment
    $edittext =GUICtrlRead ( $listView )
    $edittext2 = GUICtrlRead ( $edittext )
    If NOT ($edittext = 0) Then
    $minusid = StringSplit ( $edittext2, "|")
    $comments = IniRead ( "todo.ini", $minusid[1], "comments", "" )
    $text = StringReplace($comments, "*", @LF)
    MsgBox(0, "Comments", $text)
    Else
    MsgBox(64, "Edit", "Chose a todo to view Comments")
    EndIf






;Check if user clicked on the "10 min" button
      Case $msg = $wait
    $edittext =GUICtrlRead ( $listView )
    $edittext2 = GUICtrlRead ( $edittext )
    If NOT ($edittext = 0)  OR (GUICtrlRead ( $Checkbox1 ) == $GUI_CHECKED ) Then
    Run ( "wait.exe")
    testComment("Waited 10 min for something")

    Else
    MsgBox(64, "Wait", "Chose a todo to wait")
    EndIf

;Check if user clicked on the "timed" button
      Case $msg = $tellme
    $edittext =GUICtrlRead ( $listView )
    $edittext2 = GUICtrlRead ( $edittext )
    If NOT ($edittext = 0)  OR (GUICtrlRead ( $Checkbox1 ) == $GUI_CHECKED ) Then
    Run ( "tellme.exe")
    testComment("Scheduled Something")

    Else
    MsgBox(64, "Wait", "Chose a todo to Schedule...")
    EndIf

    ;Check if user clicked on the "Spy" button
      Case $msg = $Aspy
    $edittext =GUICtrlRead ( $listView )
    $edittext2 = GUICtrlRead ( $edittext )
    If NOT ($edittext = 0) OR (GUICtrlRead ( $Checkbox1 ) == $GUI_CHECKED )Then
            Spy($edittext2)
    Else
    MsgBox(64, "Stop", "Chose a Todo or Dont add comment (checkbox)")
    EndIf




         Case $msg = $Finito
            finito ()
         Case $msg = $oppd
    oppd()
   EndSelect
WEnd

Func add ($string , $id)
IniWrite ( "todo.ini", $id, "todo", $string )
EndFunc

Func remove ($id)
IniDelete ( "todo.ini", $id)
EndFunc

Func finito ()
$edittext =GUICtrlRead ( $listView )
$text = GUICtrlRead ( $edittext )
If NOT ($edittext = 0) Then
GUICtrlDelete($edittext)
$minusid = StringSplit ( $text, "|")

report($minusid[2], $minusid[1])
remove ($minusid[1])
Else
MsgBox(64, "Finito!", "Chose a Todo to Finito!")
EndIf
EndFunc

Func report($string, $id)
If NOT (FileExists ( "rapport.xls" )) Then
$file = FileOpen("rapport.xls", 1)

; Check if file opened for writing OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

FileWriteLine($file, "Time Finished "&@TAB&" Task" & @TAB & " Comments")
FileClose($file)
EndIf
$file = FileOpen("rapport.xls", 1)

; Check if file opened for writing OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
$time = @MDAY&"."&@MON&"."&@YEAR&" "&@HOUR&":"&@MIN


$all = IniRead ( "todo.ini", $id, "comments", "" )





FileWriteLine($file, $time&@TAB&$string&@TAB&$all)
FileClose($file)

EndFunc

Func oppd()
If NOT (FileExists ( "add.ini" )) Then
$file = FileOpen("add.ini", 1)

; Check if file opened for writing OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

FileWriteLine($file, "")
FileClose($file)
EndIf


$file2 = FileOpen("add.ini", 0)

; Check if file opened for reading OK
If $file2 = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file2)
    If @error = -1 Then ExitLoop
   ;MsgBox(0, "Line read:", $line)
    If NOT ($line == "") Then
    $id =rand()
    add ($line,$id)
         GuiCtrlCreateListViewItem($id & "|" & $line, $listView)
;add ($line)
;GuiCtrlCreateListViewItem($line, $listView)
    EndIf
Wend

FileClose($file2)

$file3 = FileOpen("add.ini", 2)

; Check if file opened for writing OK
If $file3 = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

FileWriteLine($file3, "")
FileClose($file3)

EndFunc


Func spy ($spying)

$user = InputBox("Når logger vedkommende seg på?", "Enter computername.", "")


;Asks the user to enter a password.  Don't forget to validate it!
If FileExists ( "\\xp2svr01\w2klogin$\Rapporter\SCANING\"&$user&".txt" ) Then
$en = "1"
While 1
$t = FileGetTime ( "\\xp2svr01\w2klogin$\Rapporter\SCANING\"&$user&".txt")
$yyyymd = $t[0] & "/" & $t[1] & "/" & $t[2]
$Date = @YEAR & "/" & @MON & "/" & @MDAY
If $yyyymd == $Date Then
MsgBox( 0 ,"","User "&$user&" logged on today at: "&$t[3]&":"&$t[4]&":"&$t[5] )


testComment("Runed ""User online"" button on "& $user & " Bruker "&$user&" logget seg på i dag kl: "&$t[3]&":"&$t[4]&":"&$t[5])
Return
Else
If $en == "1" Then



$file = FileOpen("\\xp2svr01\w2klogin$\Rapporter\SCANING\"&$user&".txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    $sted = "Sted = Unknown"
Else

    $line = FileReadLine($file)
$line = FileReadLine($file)
$sted = FileReadLine($file)
    

EndIf



FileClose($file)



$answer = MsgBox(0, "Last Login: "&$t[2] & "/" & $t[1] & "/" & $t[0]&" "&$t[3]&":"&$t[4]&":"&$t[5], $sted&@CR&@CR&$user&" has not logged on")
testComment("Runed ""User online"" button on "& $user & "Last Login: "&$t[2] & "/" & $t[1] & "/" & $t[0]&" "&$t[3]&":"&$t[4]&":"&$t[5]&" "& $sted&@CR&@CR&$user&" has not logged on ")
Return
EndIf
EndIf
WEnd

Else
MsgBox ( 0, "", "User don't exist")

EndIf
EndFunc

Func testComment($comment)
if NOT (GUICtrlRead ( $Checkbox1 ) == $GUI_CHECKED )Then
$edittext =GUICtrlRead ( $listView )
$edittext2 = GUICtrlRead ( $edittext )
If NOT ($edittext = 0) Then
$minusid = StringSplit ( $edittext2, "|")
AddComment($comment, $minusid[1])
EndIf
EndIf
EndFunc

Func AddComment($comment, $id)
$date = @YEAR&"."&@MON&"."&@MDAY&" "&@HOUR&":"&@MIN
$old = IniRead ( "todo.ini", $id, "comments", "" )

IniWrite("todo.ini", $id, "comments", $old & " " & $date & " - " &$comment&" * ")

EndFunc

Func rand()
$rand =Random ( 10000 , 99999, 1 )
Return $rand
EndFunc

Were ever i lay my script is my home...

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  
Followers 0