Jump to content

TrayCreateMenu only on right-click


DrLarch
 Share

Recommended Posts

I'm sure this must be simple, but I'm not figuring it out. I want to have an action tied to clicking with the primary mouse button on the tray icon, and have a menu show only if clicking with the secondary button. I'm playing with the example from TraySetOnEvent in the help file. The way it is here, the menu shows up regardless of primary or secondary click:

#NoTrayIcon
#include <MsgBoxConstants.au3>
#include <TrayConstants.au3> ; Required for the $TRAY_EVENT_PRIMARYDOUBLE, $TRAY_EVENT_SECONDARYUP and $TRAY_ICONSTATE_SHOW constants.

Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode.
Opt("TrayOnEventMode", 1) ; Enable TrayOnEventMode.

Example()

Func Example()
    TrayCreateItem("Exit")
    TrayItemSetOnEvent(-1, "ExitScript")

    TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "TrayEvent")

    TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu.

    While 1
        Sleep(100) ; An idle loop.
    WEnd
EndFunc   ;==>Example

Func TrayEvent()
    Switch @TRAY_ID ; Check the last tray item identifier.
        Case $TRAY_EVENT_PRIMARYUP
            ; Display a message box about the AutoIt version and installation path of the AutoIt executable.
            MsgBox($MB_SYSTEMMODAL, "Title", "Text")

    EndSwitch
EndFunc   ;==>TrayEvent

Func ExitScript()
    Exit
EndFunc   ;==>ExitScript

I've tried adding a Case $TRAY_EVENT_SECONDARYUP event to the TrayEvent(), and generating the menu there but that doesn't work correctly. The Example() function is obviously where the menu should be setup, but how does one control under what condition (primary or secondary click) the menu actually appears?

Link to comment
Share on other sites

I haven't tried to do this myself, and are not currently setup to do so, but have you played around with TrayGetMsg ?

Seems to me that the key to what you want is there.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Thanks Saint, but I'm still not able to get it to do what I want via TrayGetMsg. If I generate the menu with TrayCreateItem under Case $TRAY_EVENT_SECONDARYUP then it appears on subsequent left clicks also. I've tried using TrayItemDelete to get rid of the menu under Case $TRAY_EVENT_PRIMARYUP, but that doesn't work either. Does anybody have code that shows the tray menu under secondary click only?

Link to comment
Share on other sites

  • Moderators

DrLarch,

You need TraySetClick - look in the Help file for more details.

M23

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 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

 

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...