argumentum Posted November 27, 2018 Share Posted November 27, 2018 ..so I'm coding, referring to the help file due to my poor memory, and I find that the TraySetOnEvent() does not behave as explained. Here is the code I'm using: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <TrayConstants.au3> #include <GuiMenu.au3> Opt("GUIOnEventMode", 1) Opt("TrayMenuMode", 3) Opt("TrayOnEventMode", 1) Global $hGui MyExample() Func MyExample() AutoItWinSetTitle(@ScriptFullPath & @AutoItPID) $hGui = GUICreate("MyExample", 0, 0, -1, -1, BitOR($WS_SYSMENU, $WS_POPUP), $WS_EX_TOPMOST, WinGetHandle(@ScriptFullPath & @AutoItPID)) GUISetState(@SW_HIDE) TraySetOnEvent($TRAY_EVENT_SECONDARYUP, "MyTrayMenu") TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu. While Sleep(10) ; An idle loop. WEnd EndFunc ;==>MyExample Func MyTrayMenu() Local Enum $e_idOpen = 1000, $e_idSave, $e_idInfo, $e_idClose Local $a, $hMenu = _GUICtrlMenu_CreatePopup() _GUICtrlMenu_AddMenuItem($hMenu, "Open", $e_idOpen) _GUICtrlMenu_AddMenuItem($hMenu, "Save", $e_idSave) _GUICtrlMenu_AddMenuItem($hMenu, "", 0) _GUICtrlMenu_AddMenuItem($hMenu, "Info", $e_idInfo) _GUICtrlMenu_AddMenuItem($hMenu, "", 0) _GUICtrlMenu_AddMenuItem($hMenu, "Close", $e_idClose) GUISetState(@SW_SHOW) Switch _GUICtrlMenu_TrackPopupMenu($hMenu, $hGui, -1, -1, 1, 1, 2) Case $e_idOpen ConsoleWrite("Open" & @CRLF) Case $e_idSave ConsoleWrite("Save" & @CRLF) Case $e_idInfo ConsoleWrite("Info" & @CRLF) ; TraySetOnEvent($TRAY_EVENT_SECONDARYUP, "") ; does not work as expected ; if the tray icon is right-click with the above, the context menu popup ; but it should not. ; setting a different one, does work as expected TraySetOnEvent($TRAY_EVENT_SECONDARYUP, "MyTrayMenu_None") MsgBox(0,@ScriptName,"info",10) AdlibRegister("MyTrayMenu_On") Case $e_idClose ConsoleWrite("Close" & @CRLF) Exit EndSwitch _GUICtrlMenu_DestroyMenu($hMenu) GUISetState(@SW_HIDE) EndFunc ;==>MyTrayMenu_Show Func MyTrayMenu_None() ; TraySetOnEvent($TRAY_EVENT_SECONDARYUP, "") ; does not work as expected ; so this is my workaround. EndFunc Func MyTrayMenu_On() AdlibUnRegister("MyTrayMenu_On") TraySetOnEvent($TRAY_EVENT_SECONDARYUP, "MyTrayMenu") EndFunc Please try it out and if found to be a bug, add a tracker. If I am the buggy one, let me know. Thanks. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Developers Jos Posted November 27, 2018 Developers Share Posted November 27, 2018 Moved to the appropriate forum, as the Developer General Discussion forum very clearly states: Quote General development and scripting discussions. If it's super geeky and you don't know where to put it - it's probably here. Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums. Moderation Team SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Developers Jos Posted November 27, 2018 Developers Share Posted November 27, 2018 (edited) It would help when you explains also what is not working and how you think it should work! I see there are some comments in the script. Jos Edited November 27, 2018 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
argumentum Posted November 27, 2018 Author Share Posted November 27, 2018 2 hours ago, Jos said: Moved to the appropriate forum @Jos, I don't need help. I believe there is a bug. Or help manual error. Where should I share that ?. I don' wanna open a ticket for something not peer reviewed. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
pixelsearch Posted November 28, 2018 Share Posted November 28, 2018 Hi argumentum Just did some research on the Internet and discovered that this question was already asked in 2006, here :https://www.autoitscript.com/forum/topic/28124-help-resetting-traysetonevent-functions/ The advice was to use the same workaround as you did : a "null" function, I like the way footswitch talked about it, when he wrote : "That's a workaround, yes. What i was wondering was if that is the only "solution"... unless someone tells me that initially Autoit associates these actions with null functions." So maybe the help file isn't really clear because we read in it (topic TraySetOnEvent) : => @error: 1 = the "function" is not defined => then : "If the function is an empty string "" the previous user-defined is disabled." Which should probably be changed to "if you call an empty function, the previous user-defined is disabled" In your script, I tested this part, modified, it went fine too : Case $e_idInfo ConsoleWrite("Info" & @CRLF) TraySetOnEvent($TRAY_EVENT_SECONDARYUP, "MyTrayMenu_None") sleep(5000) ; right click during these 5s won't do anything, great ! TraySetOnEvent($TRAY_EVENT_SECONDARYUP, "MyTrayMenu") ; bring it back ; MsgBox(0,@ScriptName,"info",10) ; AdlibRegister("MyTrayMenu_On") ... Func MyTrayMenu_None() ; TraySetOnEvent($TRAY_EVENT_SECONDARYUP, "") ; does not work as expected ; so this is my workaround [argumentum's notes] EndFunc Anyway, glad you found the workaround too, in case the function won't be amended... Link to comment Share on other sites More sharing options...
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