Jump to content

Recommended Posts

Posted

Is there a way to differentiate between a left click and a right click on a tray icon? I have an application that I want to show the main window when the primary mouse button is clicked but when the secondary mouse button is clicked I want a menu with items like About, Settings and Exit in it. The entire script I'm working on is over 1100 lines long, so I'd rather not post it all but I can if people think it would be helpful.

Who lied and told you life would EVER be fair?

  • Moderators
Posted

benched42,

Just look for the $TRAY_EVENT_PRIMARYUP event in your TrayGetMsg loop - or set that event if you are in TrayOnEvent mode - to detect the left click and run a function to show the GUI. You will automatically get the tray menu when you right click on the tray icon.

  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

 

Posted (edited)

I guess u mean something like

#include <TrayConstants.au3>
#include <GuiConstants.au3>
#include <misc.au3>
Opt("TrayMenuMode", 3)
    Global $iDisplay
    Global $iDisplay_2
    Global $iPrinter
    Global $iPrinter_2
    Global $iExit
Example()

Func Example()
    TraySetClick(64)
    While 1
        Switch TrayGetMsg()
            Case $GUI_EVENT_PRIMARYDOWN
                TraySetState($TRAY_ICONSTATE_HIDE)
                $iDisplay = TrayCreateItem("Primary menu")
                $iPrinter = TrayCreateItem("Printer 1")
                $iExit = TrayCreateItem("exit")
                TraySetState($TRAY_ICONSTATE_SHOW)
                _del_old()
                _TrayGetMsg_Funcs("pri")
            Case $GUI_EVENT_SECONDARYDOWN
                TraySetState($TRAY_ICONSTATE_HIDE)
                $iDisplay_2 = TrayCreateItem("Secondary menu")
                $iPrinter_2 = TrayCreateItem("Printer 2")
                $iExit = TrayCreateItem("exit")
                TraySetState($TRAY_ICONSTATE_SHOW)
                _del_old()
                _TrayGetMsg_Funcs("sec")
        EndSwitch
    WEnd
EndFunc   ;==>Example



; Author ........: aElc
; Function ......: _TrayGetMsg_Funcs()
; Description ...: You have to add the functions u need below instead of the "TrayGetMsg()" in the loop
; ===============================================================================================================================

Func _TrayGetMsg_Funcs($switch)
    Switch $switch
        Case "pri"
            Do
                Sleep(15)
                Switch TrayGetMsg()
                    Case $iExit
                        Exit
                    Case $iDisplay
                        MsgBox(64, "", "Func $iDisplay")
                    Case $iPrinter
                        MsgBox(64, "", "Func $iPrinter")
                EndSwitch
            Until _IsPressed("01") Or _IsPressed ( "02" )
        Case "sec"
            Do
                Sleep(15)
                Switch TrayGetMsg()
                    Case $iExit
                        Exit
                    Case $iDisplay_2
                        MsgBox(64, "", "Func $iDisplay_2")
                    Case $iPrinter_2
                        MsgBox(64, "", "Func $iPrinter_2")
                EndSwitch
            Until _IsPressed("01") Or _IsPressed ( "02" )
    EndSwitch
EndFunc   ;==>_TrayGetMsg_Funcs


Func _del_old()
    TrayItemDelete($iDisplay)
    TrayItemDelete($iDisplay_2)
    TrayItemDelete($iPrinter)
    TrayItemDelete($iPrinter_2)
    TrayItemDelete($iExit)
EndFunc   ;==>_del_old

just a fast solution that could be more compact i guess but it's soo late actually :D 

You have to care because the TrayItemIDs resets after deleting and i guess it's possible without deleting but i didn't found a workable solution for that at the moment. Maybe i will try to optimize it later... but no guarantee for this :P 

Greetings

 

 

EDIT: I'm sorry didn't read it exactly.....  Thought you wanted 2 menus :sweating::>

But it's possible with this script, too. There you  go with your GUI

#include <TrayConstants.au3>
#include <GuiConstants.au3>
#include <misc.au3>
Opt("TrayMenuMode", 3)
    Global $iDisplay
    Global $iDisplay_2
    Global $iPrinter
    Global $iPrinter_2
    Global $iExit
$hGUI = GUICreate ( "",400,200,-1,-1)
$label = GUICtrlCreateLabel ( "click hide and restore it with tray icon",2,2,300,20 )
$btn = GUICtrlCreateButton ( "hide",2,37,100,20 )
GUISetState ( @SW_SHOW )
Example()

Func Example()
    TraySetClick(64)
    While 1
        $nMsg = GUIGetMsg ()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $btn
                GUISetState (@SW_HIDE)
        EndSwitch
        Switch TrayGetMsg()
            Case $GUI_EVENT_PRIMARYDOWN
                GUISetState (@SW_SHOW)
            Case $GUI_EVENT_SECONDARYDOWN
                TraySetState($TRAY_ICONSTATE_HIDE)
                $iDisplay_2 = TrayCreateItem("Secondary menu")
                $iPrinter_2 = TrayCreateItem("Printer 2")
                $iExit = TrayCreateItem("exit")
                TraySetState($TRAY_ICONSTATE_SHOW)
                _del_old()
                _TrayGetMsg_Funcs("sec")
        EndSwitch
    WEnd
EndFunc   ;==>Example



; Author ........: aElc
; Function ......: _TrayGetMsg_Funcs()
; Description ...: You have to add the functions u need below instead of the "TrayGetMsg()" in the loop
; ===============================================================================================================================

Func _TrayGetMsg_Funcs($switch)
    Switch $switch
        Case "pri"
            Do
                Sleep(15)
                Switch TrayGetMsg()
                    Case $iExit
                        Exit
                    Case $iDisplay
                        MsgBox(64, "", "Func $iDisplay")
                    Case $iPrinter
                        MsgBox(64, "", "Func $iPrinter")
                EndSwitch
            Until _IsPressed("01") Or _IsPressed ( "02" )
        Case "sec"
            Do
                Sleep(15)
                Switch TrayGetMsg()
                    Case $iExit
                        Exit
                    Case $iDisplay_2
                        MsgBox(64, "", "Func $iDisplay_2")
                    Case $iPrinter_2
                        MsgBox(64, "", "Func $iPrinter_2")
                EndSwitch
            Until _IsPressed("01") Or _IsPressed ( "02" )
    EndSwitch
EndFunc   ;==>_TrayGetMsg_Funcs


Func _del_old()
    TrayItemDelete($iDisplay)
    TrayItemDelete($iDisplay_2)
    TrayItemDelete($iPrinter)
    TrayItemDelete($iPrinter_2)
    TrayItemDelete($iExit)
EndFunc   ;==>_del_old

You can delete the "pri" case in the function when don't needed

Greetings again :) 

Edited by Aelc

why do i get garbage when i buy garbage bags? <_<

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...