Jump to content
Sign in to follow this  
bonehead

TrayGetMsg() $msg = $fullarray

Recommended Posts

bonehead

Is there a way to find any member of an array using a $msg event? I'm populating a

traymenu from a _filelisttoarray() and trying to do one simple event instead of 10, 20,

or more events that are very similar. Here is my code with the multiple "Case $msg ="

statments.

CODE

#include <GuiConstantsEx.au3>

#Include <File.au3>

#Include <Constants.au3>

#Include <array.au3>

#Include <string.au3>

#NoTrayIcon

Opt("TrayMenuMode",1)

Global $array[100], $array1, $i, $n, $s, $auto, $v

$menu = TrayCreateMenu("SCRIPTS")

$scripts = TrayCreateItem("SCRIPTS FOLDER", $menu)

$mute = TrayCreateItem("MUTE WMC")

$exititem = TrayCreateItem("Exit")

$i = 0

$auto = @AutoItExe

$s = 0

TraySetState()

While 1

$msg = TrayGetMsg()

$array1 = _FileListToArray("F:\scripts\", "*.au3", 1) ; makes list of script files in folder

_ArraySort($array1, 0, 1) ; sorts list while ignoring [0]

If $i < $array1[0] Then ; creates as many menu items as found scripts

$i = $i + 1

$array[$i] = TrayCreateItem($array1[$i], $menu) ; populates scripts to menu

EndIf

Select

Case $msg = 0

ContinueLoop

Case $msg = $scripts ; opens thumbdrive scriptfolder

Run("explorer.exe F:\scripts")

Case $msg = $mute ; mutes only media center on vista

Run("C:\Windows\System32\SNDVOL.exe")

WinWaitActive("Volume Mixer")

ControlClick("Volume Mixer","","Mute for Windows Media Center")

WinKill("Volume Mixer")

Case $msg = $array[1] ; start work on populated menu

$s = 1

Call("doit")

Case $msg = $array[2]

$s = 2

Call("doit")

Case $msg = $array[3]

$s = 3

Call("doit")

Case $msg = $array[4]

$s = 4

Call("doit")

Case $msg = $array[5]

$s = 5

Call("doit")

Case $msg = $array[6]

$s = 6

Call("doit")

Case $msg = $array[7]

$s = 7

Call("doit")

Case $msg = $array[8]

$s = 6

Call("doit")

Case $msg = $array[9]

$s = 6

Call("doit")

Case $msg = $array[10]

$s = 6

Call("doit")

Case $msg = $array[11]

$s = 6

Call("doit")

Case $msg = $exititem ; exits traymenu

ExitLoop

EndSelect

WEnd

Func doit() ; runs the script file chosen

$v = TrayItemGetText($array[$s])

$a = FileGetShortName($v, 1)

Run($auto & " " & $a)

EndFunc

Exit

Share this post


Link to post
Share on other sites
Valuater

Maybe..

;~ #include <GuiConstantsEx.au3>
#include <File.au3>
;~ #include <Constants.au3>
#include <array.au3>
;~ #include <string.au3>
;~ #NoTrayIcon

Opt("TrayMenuMode", 1)

Global $array, $i, $n, $s, $auto, $v

$menu = TrayCreateMenu("SCRIPTS")
$scripts = TrayCreateItem("SCRIPTS FOLDER", $menu)
$mute = TrayCreateItem("MUTE WMC")
$exititem = TrayCreateItem("Exit")
$i = 0
$auto = @AutoItExe
$s = 0

$array1 = _FileListToArray("F:\scripts\", "*.au3", 1) ; makes list of script files in folder
If @error = 1 Then
    MsgBox(0, "", "No Files\Folders Found.")
    Exit
EndIf

_ArraySort($array1, 0, 1) ; sorts list while ignoring [0]
For $x = 1 To UBound($array1) - 1
    $array[$i] = TrayCreateItem($array1[$i], $menu) ; populates scripts to menu
Next

TraySetState()

While 1
    $msg = TrayGetMsg()

    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $scripts ; opens thumbdrive scriptfolder
            ;Run("explorer.exe F:\scripts")
        Case $msg = $mute ; mutes only media center on vista
            ;Run("C:\Windows\System32\SNDVOL.exe")
            WinWaitActive("Volume Mixer")
            ControlClick("Volume Mixer", "", "Mute for Windows Media Center")
            WinKill("Volume Mixer")
        Case $msg = $exititem ; exits traymenu
            Exit
    EndSelect

    For $x = 1 To UBound($array)
        If $msg = $array[$x] Then doit($x)
    Next
WEnd

Func doit($s) ; runs the script file chosen
    $v = TrayItemGetText($array[$s])
    $a = FileGetShortName($v, 1)
    Run($auto & " " & $a)
EndFunc   ;==>doit

*** NOT TESTED ****

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites
rasim

@bonehead

Another way:

#include <Constants.au3>

Opt("TrayMenuMode", 1)
Opt("TrayOnEventMode", 1)

Dim $aItems[11]
$aItems[0] = 10

For $i = 1 To $aItems[0]
    $aItems[$i] = TrayCreateItem("Item " & $i)
    TrayItemSetOnEvent(-1, "_TrayEvents")
Next

$TrayItem_Exit = TrayCreateItem("Exit")
TrayItemSetState(-1, $TRAY_DEFAULT)
TrayItemSetOnEvent(-1, "_Exit")

While 1
    Sleep(100)
WEnd

Func _TrayEvents()
    ConsoleWrite("ID: " & @TRAY_ID & @LF & _
                 "Text: " & TrayItemGetText(@TRAY_ID) & @LF)
EndFunc   ;==>_TrayEvents

Func _Exit()
    Exit
EndFunc   ;==>_Exit

:)

Share this post


Link to post
Share on other sites
bonehead

Hey rasim thanks for the help especially for the @TRAY_ID, as many times as I

looked at the macros I can't believe I didn't see that. Finally got it working though.

Func _TrayEvents(); runs the script file chosen
    $v = TrayItemGetText(@TRAY_ID)
    $a = FileGetShortName($v, 1)
    Run($auto & " " & $a)
EndFunc
Edited by bonehead

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  

×