benched42 Posted October 10, 2019 Posted October 10, 2019 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 Melba23 Posted October 10, 2019 Moderators Posted October 10, 2019 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Aelc Posted October 11, 2019 Posted October 11, 2019 (edited) I guess u mean something like expandcollapse popup#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 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 Greetings EDIT: I'm sorry didn't read it exactly..... Thought you wanted 2 menus But it's possible with this script, too. There you go with your GUI expandcollapse popup#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 October 11, 2019 by Aelc why do i get garbage when i buy garbage bags?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now