Sign in to follow this  
Followers 0
jvanegmond

Commented Custom Tray Example

14 posts in this topic

#1 ·  Posted (edited)

;Includes
#include <GUIConstants.au3>
#Include <Constants.au3>

;Options
Opt("TrayMenuMode",1)
Opt("TrayAutoPause", 0)
Opt("GUICloseOnESC", 0)

MsgBox(0x40,"Information", "This is a custom tray example. Click the AutoIt tray icon to see how it works.") ; You can remove this line

#region Settings
Dim $Menu[6] = ["Games", "Friends", "Servers", "Settings", "News", "Exit"] ; The menu options
Dim $ControlHeight = 20 ;The height of each option

Dim $BgColor = 0x293029 ; Background color
Dim $EdgeColor = 0x6B6963 ; Edge color
Dim $ActiveColor = 0x948639 ; Active menu color
Dim $FontColor = 0xFFFFFF

Dim $Width = 90 ; Width of the whole tray
#endregion Settings

; Variables
Dim $Height = UBound($Menu)*$ControlHeight
Dim $Colored, $Label[UBound($Menu)]

;Create the tray
Dim $GUI = GUICreate("Menu",$Width+3,$Height+4,-1,-1,$WS_POPUP,$WS_EX_TOOLWINDOW)
GUISetFont(9,300,0,"Verdana")
GUISetBkColor($EdgeColor)

For $x = 0 to UBound($Menu)-1 ; Populate it with menu's
    $Label[$x] = GUICtrlCreateLabel(" " & $Menu[$x],2,($x*$ControlHeight)+2,$Width-1,$ControlHeight)
    GUICtrlSetBkColor(-1,$BgColor)
    GUICtrlSetColor(-1,$FontColor)
Next

WinSetOnTop($GUI,"", 1) ; On top, else it will fall behind the start bar

While 1
    $nMsg = GUIGetMsg() ; Check if the user has clicked an option
    Switch $nMsg
        Case $Label[0]
            GUISetState(@SW_HIDE)
            MsgBox(0x40, "Notification","You clicked Games.")
        Case $Label[1]
            GUISetState(@SW_HIDE)
            MsgBox(0x40, "Notification", "You clicked Friends.")
        Case $Label[2]
            GUISetState(@SW_HIDE)
            MsgBox(0x40, "Notification", "You clicked Servers.")
        Case $Label[3]
            GUISetState(@SW_HIDE)
            MsgBox(0x40, "Notification", "You clicked Settings.")
        Case $Label[4]
            GUISetState(@SW_HIDE)
            MsgBox(0x40, "Notification", "You clicked News.")
        Case $Label[5]
            ExitLoop
    EndSwitch
    $tMsg = TrayGetMsg() ; Check if the user clicks the tray
    Switch $tMsg
        Case $TRAY_EVENT_PRIMARYDOWN
            $Pos = MouseGetPos()
            WinMove($GUI,"",$Pos[0]-$Width,$Pos[1]-$Height) ; position and show the tray
            GUISetState()
            WinActivate($GUI)
    EndSwitch
    If BitAND(WinGetState($GUI), 2) Then
        $Pos = MouseGetPos()
        $wPos = WinGetPos($GUI)
        If ($Pos[0] >= $wPos[0] And $Pos[0] <= $wPos[0] + $Width) And _
            ($Pos[1] >= $wPos[1] And $Pos[1] <= $wPos[1] + $Height) Then
            $Mouse = GUIGetCursorInfo() ; Color the active tray items
            If not @error Then
                If $Mouse[4] <> $Colored Then
                    GUICtrlSetBkColor($Colored,$BgColor)
                    GUICtrlSetBkColor($Mouse[4],$ActiveColor)
                    $Colored = $Mouse[4] ;remember which was colored so we can uncolor it later
                EndIf
            EndIf
        Else
            GUISetState(@SW_HIDE)
        EndIf
    EndIf
WEnd

Thanks to Smoke_N for hiding when the mouse wasn't on it.

Edited by Manadar

Share this post


Link to post
Share on other sites



Thank You Manadar for a nice, clean, simple custom and customizable tray menu example.

Nice work

All Good :)

Cheers

Share this post


Link to post
Share on other sites

I like the way you did that. Good example.


My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.

Share this post


Link to post
Share on other sites

I like the way you did that. Good example.

I like the formating nice job


[quote]Baby you're all that I want, When you're lyin' here in my armsI'm findin' it hard to believe, We're in heavenAnd love is all that I need , And I found it there in your heartIt isn't too hard to see, We're in heaven .Bryan Adams[/quote].............................................................................[u]AUTOIT[/u]

Share this post


Link to post
Share on other sites

Why do you load the menu on primary click instead of alternate click?

Other than that, it does look nice.

Share this post


Link to post
Share on other sites

May consider hiding the GUI if the mouse isn't within it's boundaries...

CODE
;Includes
#include <GUIConstants.au3>
#Include <Constants.au3>

;Options
Opt("TrayMenuMode",1)
Opt("TrayAutoPause", 0)
Opt("GUICloseOnESC", 0)

MsgBox(0x40,"Information", "This is a custom tray example. Click the AutoIt tray icon to see how it works.") ; You can remove this line

#region Settings
Dim $Menu[6] = ["Games", "Friends", "Servers", "Settings", "News", "Exit"] ; The menu options
Dim $ControlHeight = 20 ;The height of each option

Dim $BgColor = 0x293029 ; Background color
Dim $EdgeColor = 0x6B6963 ; Edge color
Dim $ActiveColor = 0x948639 ; Active menu color
Dim $FontColor = 0xFFFFFF

Dim $Width = 90 ; Width of the whole tray
#endregion Settings

; Variables
Dim $Height = UBound($Menu)*$ControlHeight
Dim $Colored, $Label[UBound($Menu)]

;Create the tray
Dim $GUI = GUICreate("Menu",$Width+3,$Height+4,-1,-1,$WS_POPUP,$WS_EX_TOOLWINDOW)
GUISetFont(9,300,0,"Verdana")
GUISetBkColor($EdgeColor)

For $x = 0 to UBound($Menu)-1 ; Populate it with menu's
    $Label[$x] = GUICtrlCreateLabel(" " & $Menu[$x],2,($x*$ControlHeight)+2,$Width-1,$ControlHeight)
    GUICtrlSetBkColor(-1,$BgColor)
    GUICtrlSetColor(-1,$FontColor)
Next

WinSetOnTop($GUI,"", 1) ; On top, else it will fall behind the start bar

While 1
    $nMsg = GUIGetMsg() ; Check if the user has clicked an option
    Switch $nMsg
        Case $Label[0]
            GUISetState(@SW_HIDE)
            MsgBox(0x40, "Notification","You clicked Games.")
        Case $Label[1]
            GUISetState(@SW_HIDE)
            MsgBox(0x40, "Notification", "You clicked Friends.")
        Case $Label[2]
            GUISetState(@SW_HIDE)
            MsgBox(0x40, "Notification", "You clicked Servers.")
        Case $Label[3]
            GUISetState(@SW_HIDE)
            MsgBox(0x40, "Notification", "You clicked Settings.")
        Case $Label[4]
            GUISetState(@SW_HIDE)
            MsgBox(0x40, "Notification", "You clicked News.")
        Case $Label[5]
            ExitLoop
    EndSwitch
    $tMsg = TrayGetMsg() ; Check if the user clicks the tray
    Switch $tMsg
        Case $TRAY_EVENT_PRIMARYDOWN
            $Pos = MouseGetPos()
            WinMove($GUI,"",$Pos[0]-$Width,$Pos[1]-$Height) ; position and show the tray
            GUISetState()
            WinActivate($GUI)
    EndSwitch
    If BitAND(WinGetState($GUI), 2) Then
        $Pos = MouseGetPos()
        $wPos = WinGetPos($GUI)
        If ($Pos[0] >= $wPos[0] And $Pos[0] <= $wPos[0] + $Width) And _
            ($Pos[1] >= $wPos[1] And $Pos[1] <= $wPos[1] + $Height) Then
            $Mouse = GUIGetCursorInfo() ; Color the active tray items
            If not @error Then
                If $Mouse[4] <> $Colored Then
                    GUICtrlSetBkColor($Colored,$BgColor)
                    GUICtrlSetBkColor($Mouse[4],$ActiveColor)
                    $Colored = $Mouse[4] ;remember which was colored so we can uncolor it later
                EndIf
            EndIf
        Else
            GUISetState(@SW_HIDE)
        EndIf
    EndIf
WEnd

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.

Share this post


Link to post
Share on other sites

May consider hiding the GUI if the mouse isn't within it's boundaries...

Didn't even think about hiding it at all.. Good idea, and thanks.

Updated initial post.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Glad to see anther release from you Manadar.

This will be very helpful, just wish you had a better taste in colours :)

Edited by Dethredic

"Its not about the 30 inch 1080p display, or the SLI 8800 ultras, or the DDR3 memory. It's about when you turn on your PC, does it return the favor?"Math is like sex. Sure, it may give some practical results, but that is not why we do it

Share this post


Link to post
Share on other sites

I like the menu - works great. I ran into a problem on my computer because I always have my taskbar on the left side of the screen (instead of at the bottom as it is by default). When the menu would "draw" onscreen, all of the menu items were pushed off the left side of the display from the original code to draw at X-Width.

I added a couple SELECT statements to handle this and used the variables created to change the actual draw point on the WinMove function you were using on the GUI.

With this added in, the menu will be displayed correctly on all four sides of the screen. I'm posting it here in case anyone else has need of it.

Switch $tMsg
    Case $TRAY_EVENT_PRIMARYDOWN
        $Pos = MouseGetPos()
            Select ;Determines the X and Y coords to draw the window for the tray menu
                Case $Pos[0]-$Width < $Width
                    $MenuX=$Pos[0]
                Case Else
                    $MenuX=$Pos[0]-$Width
            EndSelect
            Select
                Case $Pos[1]-$Height < $Height
                    $MenuY=$Pos[1]
                Case Else
                    $MenuY=$Pos[1]-$Height
                EndSelect  ; End of section for X and Y coords determination
            WinMove($GUI,"",$MenuX,$MenuY) ; position and show the tray
            GUISetState()
            WinActivate($GUI)
EndSwitch

Thanks again for posting a great menu!

- Mo


- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Share this post


Link to post
Share on other sites

Nice job, its a lot better than mine. It even looks like the steam menu.


[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Share this post


Link to post
Share on other sites

Nice job, its a lot better than mine. It even looks like the steam menu.

I just read your comment, because I only needed this example until now.

I attempted to recreate the Steam menu, indeed. How nice of you to notice. :whistle:

Share this post


Link to post
Share on other sites

It's Greate!

Now we can use colored/fonted tray items :whistle:

Thanks Manadar for sharing!

P.S

It would be great also to have ability set icons for the items :lmao:


 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

It's Greate!

Now we can use colored/fonted tray items :whistle:

Thanks Manadar for sharing!

P.S

It would be great also to have ability set icons for the items :lmao:

Expanded menu's.. That would be even better. ;)

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