Sign in to follow this  
Followers 0
busysignal

Tray Sub-menu Issues

4 posts in this topic

I am trying to write a Tray Menu script but I am running into a program that I cannot see. It seems that the $msg value is not getting a value other than zero. Can anyone shed some light on what I am missing. I am sure it is really simple.. See code below..

#include <Constants.au3>
#NoTrayIcon

; << AutoIt Options >>
;
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)
Opt("TrayIconHide", 0)
;Opt("TrayAutoPause", 0)

; << Hotkey Definitions >>
;
HotKeySet("^!x", "_Exit")
HotKeySet("^!h", "_Help")

$Settings_tray = TrayCreateMenu("Settings")
$HDDitem = TrayCreateItem("HDD Info", $Settings_tray)

$Current_tray = TrayCreateItem("Current HotKeys (Ctrl+Alt+H)")
TrayItemSetOnEvent($Current_tray, "_Help")

$exit_tray = TrayCreateItem("Exit (Ctrl+Alt+X)")
TrayItemSetOnEvent($exit_tray, "_Exit")

TraySetState()


While 1
    Sleep(100)
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $HDDitem
            _HDDInfo()
        Case Else
        ;;;
    EndSelect
WEnd
Exit


;===================================================================================================

===================
;                                                     Function Area
;===================================================================================================

===================

Func _HDDInfo(); Display HDDInfo
    Local $hdSizeC, $hdFreeSizeC, $hdSizeD, $hdFreeSizeD
    $hdSizeC = DriveSpaceTotal( "c:\")
    $hdFreeSizeC = DriveSpaceFree( "c:\")
    $hdSizeD = DriveSpaceTotal( "d:\")
    $hdFreeSizeD = DriveSpaceFree( "d:\")
    MsgBox(0, "HDD Info", _
            "Hostname                  : " & @ComputerName & @CRLF _
             & "Domain                     : " & @LogonDomain & @CRLF _
             & "LogonServer            : " & @LogonServer & @CRLF _
             & "OS Type                 : " & @OSTYPE & @CRLF _
             & "Version                : " & @OSVersion & @CRLF _
             & "ServicePack            : " & @OSServicePack & @CRLF _
             & "Drive C size                 : " & Round($hdSizeC) & " MB" & @CRLF _
             & "Drive C free                : " & Round($hdFreeSizeC) & " MB" & @CRLF _
             & "Drive D size                 : " & Round($hdSizeD) & " MB" & @CRLF _
             & "Drive D free                : " & Round($hdFreeSizeD) & " MB" & @CRLF _
             & "ScriptStarting User     : " & @UserName)
    
EndFunc  ;==>_HDDInfo

Func _Help();printing out the current set HotKeys
    Local $HKeys = "Ctrl+Alt+X for Exit" & @CRLF & _
            "Ctrl+Alt+H for Help"
    MsgBox(64, "-= HELP =-", "Hotkey List:" & @CRLF & $HKeys)
EndFunc  ;==>_Help

Func _Exit();Exit Script
    Exit
EndFunc  ;==>_Exit

Any help would be greatly appreciated..

Cheers.. :)

Share this post


Link to post
Share on other sites



You can't use Opt("TrayOnEventMode", 1) with TrayGetMsg() too. One or the other.... You could just use the TrayOnEventMode() and set TrayItemSetOnEvent($HDDitem, "_HDDInfo") for $HDDitem = TrayCreateItem("HDD Info", $Settings_tray).


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Here ya go:

#include <Constants.au3>
#NoTrayIcon

; << AutoIt Options >>
;
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)
Opt("TrayIconHide", 0)
;Opt("TrayAutoPause", 0)

; << Hotkey Definitions >>
;
HotKeySet("^!x", "_Exit")
HotKeySet("^!h", "_Help")

$Settings_tray = TrayCreateMenu("Settings")
$HDDitem = TrayCreateItem("HDD Info", $Settings_tray)
TrayItemSetOnEvent($HDDitem, "_HDDInfo")
$Current_tray = TrayCreateItem("Current HotKeys (Ctrl+Alt+H)")
TrayItemSetOnEvent($Current_tray, "_Help")

$exit_tray = TrayCreateItem("Exit (Ctrl+Alt+X)")
TrayItemSetOnEvent($exit_tray, "_Exit")

TraySetState()


While 1
WEnd
Exit


;===================================================================================================

===================
;                                                     Function Area
;===================================================================================================

===================

Func _HDDInfo(); Display HDDInfo
    Local $hdSizeC, $hdFreeSizeC, $hdSizeD, $hdFreeSizeD
    $hdSizeC = DriveSpaceTotal( "c:\")
    $hdFreeSizeC = DriveSpaceFree( "c:\")
    $hdSizeD = DriveSpaceTotal( "d:\")
    $hdFreeSizeD = DriveSpaceFree( "d:\")
    MsgBox(0, "HDD Info", _
            "Hostname                  : " & @ComputerName & @CRLF _
             & "Domain                     : " & @LogonDomain & @CRLF _
             & "LogonServer            : " & @LogonServer & @CRLF _
             & "OS Type                 : " & @OSTYPE & @CRLF _
             & "Version                : " & @OSVersion & @CRLF _
             & "ServicePack            : " & @OSServicePack & @CRLF _
             & "Drive C size                 : " & Round($hdSizeC) & " MB" & @CRLF _
             & "Drive C free                : " & Round($hdFreeSizeC) & " MB" & @CRLF _
             & "Drive D size                 : " & Round($hdSizeD) & " MB" & @CRLF _
             & "Drive D free                : " & Round($hdFreeSizeD) & " MB" & @CRLF _
             & "ScriptStarting User     : " & @UserName)
    
EndFunc  ;==>_HDDInfo

Func _Help();printing out the current set HotKeys
    Local $HKeys = "Ctrl+Alt+X for Exit" & @CRLF & _
            "Ctrl+Alt+H for Help"
    MsgBox(64, "-= HELP =-", "Hotkey List:" & @CRLF & $HKeys)
EndFunc  ;==>_Help

Func _Exit();Exit Script
    Exit
EndFunc  ;==>_Exit

U had it set on TrayEventMode and were trying to get the message by doing msg=TrayGetMsg()...

should work now.

Share this post


Link to post
Share on other sites

@ SmOke_N & CHRIS95219, thanks for your reply. Now I understand what the OPT is trying to do. It was not clear when I was reading the AutoIt Help description that there would be a conflict between the two approaches.

Cheers.. :)

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