Jump to content
gbrao

Display two menus from tray : depending on R- or L- click.

Recommended Posts

gbrao

I would like to display a different menu depending on whether the user has right- or left- clicked the tray icon.

Is this possible with autoit?

I was able to do it with autohotkey by modifing the code here :

https://autohotkey.com/board/topic/11250-mouseover-trayicon-triggering-an-event/#entry153388

I prefer autoit, so I would like to develop the same (compiled) program in autoit.

Share this post


Link to post
Share on other sites
AutoBert

Never tried this option (different traymenus) but as TrayGetMsg can recognize different clicks, i would say yes. 

Share this post


Link to post
Share on other sites
gbrao

What do I do after I recognize whether it's a L- or R- tray click ?

That's what I want to know.

Share this post


Link to post
Share on other sites
Melba23

gbrao,

I have used something like this in the past:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <TrayConstants.au3>

Opt("TrayOnEventMode", 1) ; Use event trapping for tray menu
Opt("TrayMenuMode", 3) ; Default tray menu items will not be shown.

TrayCreateItem("Tray Item")
TrayItemSetOnEvent(-1, "_TrayItem")
TrayCreateItem("")
TrayCreateItem("Tray Exit")
TrayItemSetOnEvent(-1, "_Exit")

TraySetState()

; Only left click will display tray menu
TraySetClick(8)

; Set right click to display user GUI menu
TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "_UserMenu")

; Create and hide user menu GUI
$hUser_GUI = GUICreate("User Menu", 200, 200, -1, -1, $WS_POPUP)

$cUser_Item = GUICtrlCreateLabel("User Item", 10, 10, 180, 20)

$cUser_Close = GUICtrlCreateLabel("User Close", 10, 30, 180, 20)

$cUser_Exit = GUICtrlCreateLabel("User Exit", 10, 50, 180, 20)


GUISetState(@SW_HIDE)

While 1

    Switch GUIGetMsg()
        Case $cUser_Item
            ; Hide user menu
            GUISetState(@SW_HIDE)
            MsgBox($MB_SYSTEMMODAL, "User Item", "Clicked")
        Case $cUser_Close
            ; Hide user menu
            GUISetState(@SW_HIDE)
        Case $cUser_Exit
            _Exit()
    EndSwitch

WEnd

Func _UserMenu()

    ; Get mouse position
    Local $aMousePos = MouseGetPos()

    ; Move user menu
    WinMove($hUser_GUI, "", $aMousePos[0] - 200, $aMousePos[1] - 200)

    ; Show user menu
    GUISetState(@SW_SHOW)

EndFunc

Func _TrayItem()
    MsgBox(0, "Tray Item", "Clicked")
EndFunc

Func _Exit()
    Exit
EndFunc

Obviously the user menu GUI needs to be "prettified" but the idea is there.

M23

  • Like 2

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______Open Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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

×