Jump to content

modifiable list of traymenu


Recommended Posts

#Include <Constants.au3>

HotKeySet ( "{ESC}" , "ExitProg")
AutoItSetOption ( "MouseCoordMode" , 2 )

Func ExitProg()
    Exit
EndFunc




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

TrayCreateItem ( "this would be a list of ", -1, -1, 1 )
TrayCreateItem ( "browser windows", -1, -1, 1 )
TrayCreateItem ( "when you select one of this, it's brought to front.", -1, -1, 1 )
TrayItemSetState(-1, $TRAY_CHECKED)
TrayCreateItem("")
$Open     = TrayCreateMenu("Open a browser")
$Open_this_swg  = TrayCreateItem("a list of browsers to open", $Open)
$Close    = TrayCreateMenu("Close a browser")
$Close_this_swg = TrayCreateItem("a list of browsers to close", $Close)
TrayCreateItem("")
$CloseAll   = TrayCreateMenu("Sleep")
$displayitem    = TrayCreateItem("YES", $CloseAll)
$CloseAll   = TrayCreateMenu("Reboot")
$displayitem    = TrayCreateItem("YES", $CloseAll)
TrayCreateItem("")
$aboutitem      = TrayCreateItem("About")
TrayCreateItem("")
$exititem       = TrayCreateItem("Exit")

TraySetState()

While 1
    

    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $aboutitem
            Msgbox( 0,"about:","I wrote this. :)")
        Case $msg = $exititem
            Exit
    EndSelect
    

WEnd

Exit

I am trying to make the list correspond to the number of windows there are; for instance, for the top part of the menu, if there are 4 browser windows, then there should be 4 radio buttons, if there are 5, there would be 5 radio buttons with the name of window being the text shown.

Is it possible to do this ?

Link to comment
Share on other sites

Here's my ruff example of adding and removing windows to and from the tray menu as the windows open and close, on the fly so to speak. :shocked:

Click a tray menu item and it activates the associated window.

More then 30 windows open will throw an array error.

(as said it's only an example and probly a bad example at that.)

#Include <Constants.au3>

Opt("WinTitleMatchMode", 4)
Opt("TrayMenuMode",1)

Global $TrayItem[31][3], $hm[1]

TrayCreateItem("",-1,30)
$exit = TrayCreateItem("Exit",-1,31)
TraySetState()

While 1
    _ListWin()
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $exit
            Exit
    EndSelect
    For $x = 1 To $hm[0]
        Select
            Case $msg = $TrayItem[$x][2]
                WinActivate($TrayItem[$x][0])
        EndSelect
    Next
WEnd

Func _ListWin()
    $hm1 = 0
    If $hm[0] = 0 Then
        SetTrayItems()
    ElseIf $hm[0] > 0 Then
        $var = WinList()
        For $i = 1 to $var[0][0]
            If $var[$i][0] <> "" AND IsVisible($var[$i][1]) And $var[$i][0] <> 'Program Manager' Then
                $hm1 = $hm1 + 1
            EndIf
        Next
        For $cPid = 1 To $hm[0]
            If WinGetProcess($TrayItem[$hm1][1]) == WinGetProcess($TrayItem[$cPid][1]) Then
                For $m = 1 To $hm[0]
                    If ProcessExists(WinGetProcess($TrayItem[$m][1])) = 0 Then
                        For $d = 1 To $hm[0]
                            TrayItemDelete($TrayItem[$d][2])
                            $TrayItem[$d][0] = ''
                            $TrayItem[$d][1] = ''
                            $TrayItem[$d][2] = ''
                        Next
                        $hm[0] = 0
                    EndIf
                Next
                Return
            EndIf
        Next
        If $hm1 = $hm[0] Then
            Return
        ElseIf $hm1 <> $hm[0] Then
            For $d = 1 To $hm[0]
                TrayItemDelete($TrayItem[$d][2])
                $TrayItem[$d][0] = ''
                $TrayItem[$d][1] = ''
                $TrayItem[$d][2] = ''
            Next
            SetTrayItems()
        EndIf
    EndIf
EndFunc

Func SetTrayItems()
    $hm[0] = 0
    $TrimTitle = ''
    $var = WinList()
    For $i = 1 to $var[0][0]
        If $var[$i][0] <> "" AND IsVisible($var[$i][1]) And $var[$i][0] <> 'Program Manager' Then
            $hm[0] = $hm[0] +1
            $TrayItem[$hm[0]][0] = $var[$i][0]
            $TrayItem[$hm[0]][1] = $var[$i][1]
            $TrayItem[$hm[0]][2] = TrayCreateItem($TrayItem[$hm[0]][0],-1,$hm[0]-1)
        EndIf
    Next
EndFunc

Func IsVisible($wdfds)
  If BitAnd(WinGetState($wdfds),2) Then
    Return 1
  Else
    Return 0
  EndIf
EndFunc

I think using On Event mode would be better on resources, this way you would only refresh the tray menu when a user accesses it, the way I've written the example is the the other way around, winlist is working every time a window is opened and closed even if the user doesn't even access the tray at all.

Sorry , didn't have time to comment what things do in the example.

Cheers

Edited by smashly
Link to comment
Share on other sites

Opt("TrayOnEventMode", 1)

Then you'll need to make all functions fire on event.

I'd suggest to read the help file as much as possible as well as browse through the forums to get differant examples of others on event scripts, between doing that experiment with small bits of code yourself. Even if those small bits of code are not needed by you, it just gets your mind open to how to tackle things that are relevent to your projects :shocked:

I can't rewrite what I posted above atm as I'm on my way to work.

Will have a go at doing it in on event when I get home.

Good luck and cheers.

Edit: probly helps when I write the correct option mode as TrayOnEventMode and not GUIOnEventMode, since your using a tray menu.

Edited by smashly
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...