MONaH-Rasta Posted May 13, 2019 Share Posted May 13, 2019 Opt('TrayAutoPause', 0) $iTray1 = TrayCreateItem('Tray 1') TrayItemSetState(-1, 1) TrayCreateItem('') $iTrayMenu1 = TrayCreateMenu('Tray Menu 1') $iTray2 = TrayCreateItem('Tray 2', $iTrayMenu1, -1, 1) TrayItemSetState(-1, 1) $iTray3 = TrayCreateItem('Tray 3', $iTrayMenu1, -1, 1) $iTray4 = TrayCreateItem('Tray 4', $iTrayMenu1, -1, 1) TrayCreateItem('') $iTrayMenu2= TrayCreateMenu('Tray Menu 2') $iTray5 = TrayCreateItem('Tray 5', $iTrayMenu2, -1, 1) TrayItemSetState(-1, 1) $iTray6 = TrayCreateItem('Tray 6', $iTrayMenu2, -1, 1) $iTray7 = TrayCreateItem('Tray 7', $iTrayMenu2, -1, 1) TrayCreateItem('') $iTray8 = TrayCreateItem('Tray 8') $iTray9 = TrayCreateItem('Tray 9') $iTray10 = TrayCreateItem('Tray 10') TrayItemSetState(-1, 1) While True Sleep(1000*5) WEnd When I click on Tray 3 / Tray 4 / Tray 6 / Tray 7 nothing happens. Only Tray 2 and Tray 5 stay checked. I have tried setting Opt("TrayMenuMode", 8) In this case radio menuitems act like normal menuitems only looks different. I'm using AutoIt v3.3.14.5. Tested on Windows 10 LTSC 2019 (1809) x64 version: 10.0.17763 build 17763.475 and Windows Server 2008 R2. Tried run script x64 and x86 same result. Is this kind a bug or something? Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted May 13, 2019 Share Posted May 13, 2019 @MONaH-Rasta That's because those "clicks" need to be handled in a different way. TrayGetMsg() will handle both the messages sent from the various Tray items, and add a sleep to the While loop, so you don't need to worry about CPU overload. Look at the example below: expandcollapse popup#include <TrayConstants.au3> Opt('TrayAutoPause', 0) $iTray1 = TrayCreateItem('Tray 1') TrayItemSetState(-1, 1) TrayCreateItem('') $iTrayMenu1 = TrayCreateMenu('Tray Menu 1') $iTray2 = TrayCreateItem('Tray 2', $iTrayMenu1, -1, 1) TrayItemSetState(-1, 1) $iTray3 = TrayCreateItem('Tray 3', $iTrayMenu1, -1, 1) $iTray4 = TrayCreateItem('Tray 4', $iTrayMenu1, -1, 1) TrayCreateItem('') $iTrayMenu2= TrayCreateMenu('Tray Menu 2') $iTray5 = TrayCreateItem('Tray 5', $iTrayMenu2, -1, 1) TrayItemSetState(-1, 1) $iTray6 = TrayCreateItem('Tray 6', $iTrayMenu2, -1, 1) $iTray7 = TrayCreateItem('Tray 7', $iTrayMenu2, -1, 1) TrayCreateItem('') $iTray8 = TrayCreateItem('Tray 8') $iTray9 = TrayCreateItem('Tray 9') $iTray10 = TrayCreateItem('Tray 10') TrayItemSetState(-1, 1) While True Switch TrayGetMsg() Case $iTray2 _CheckUncheckTrayItem($iTray2) Case $iTray3 _CheckUncheckTrayItem($iTray3) Case $iTray5 _CheckUncheckTrayItem($iTray5) Case $iTray6 _CheckUncheckTrayItem($iTray6) Case $iTray7 _CheckUncheckTrayItem($iTray7) EndSwitch WEnd Func _CheckUncheckTrayItem($idControl) Return TrayItemGetState($idControl) = BitOR($TRAY_ENABLE, $TRAY_CHECKED) ? TrayItemSetState($idControl, $TRAY_UNCHECKED) : TrayItemSetState($idControl, $TRAY_CHECKED) EndFunc Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
MONaH-Rasta Posted May 13, 2019 Author Share Posted May 13, 2019 (edited) @FrancescoDiMuro, please, understand, I'm not trying to handle nothing in my script. My point was that radiobuttons didn't change their state automaticly. Here is an example with radiobuttons working as they should: Opt('TrayAutoPause', 0) $iTray1 = TrayCreateItem('Tray 1', -1, -1, 1) TrayItemSetState(-1, 1) $iTray2 = TrayCreateItem('Tray 2', -1, -1, 1) $iTray3 = TrayCreateItem('Tray 3', -1, -1, 1) TrayCreateItem('') $iTray8 = TrayCreateItem('Tray 8') $iTray9 = TrayCreateItem('Tray 9') $iTray10 = TrayCreateItem('Tray 10') TrayItemSetState(-1, 1) While True Sleep(1000*5) WEnd If I klick on Tray 2 / Tray 3 it will become checked and other 2 will become unchecked, just as expected. The problem comes when using radiobuttons in menu. Edited May 13, 2019 by MONaH-Rasta Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted May 13, 2019 Share Posted May 13, 2019 1 minute ago, MONaH-Rasta said: The problem comes when using radiobuttons in menu. That's because they need to be handled in that manner. In your example, you are not showing the behaviour of a Menu item; instead, you are showing the behaviour of a tray item, which is not the problem you are trying to solve Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
MONaH-Rasta Posted May 13, 2019 Author Share Posted May 13, 2019 (edited) Oh, so you are telling me that behavior of menuradioitems are different when they are in tray menu Isn't that's strange? Edited May 13, 2019 by MONaH-Rasta Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted May 13, 2019 Share Posted May 13, 2019 (edited) @MONaH-Rasta Referring about what it is stated in the Help file, seems that those kind of messages need to be handled in that way Edited May 13, 2019 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
MONaH-Rasta Posted May 13, 2019 Author Share Posted May 13, 2019 (edited) Opt('TrayAutoPause', 0) $iTrayMenu1 = TrayCreateMenu('Tray Menu 1') $iTray1 = TrayCreateItem('Tray 1', $iTrayMenu1, -1, 1) TrayItemSetState(-1, 1) $iTray2 = TrayCreateItem('Tray 2', $iTrayMenu1, -1, 1) $iTray3 = TrayCreateItem('Tray 3', $iTrayMenu1, -1, 1) $iTray4 = TrayCreateItem('Tray 4', $iTrayMenu1, -1, 1) TrayCreateItem('', $iTrayMenu1) $iTray5 = TrayCreateItem('Tray 5', $iTrayMenu1, -1, 1) $iTray6 = TrayCreateItem('Tray 6', $iTrayMenu1, -1, 1) $iTray7 = TrayCreateItem('Tray 7', $iTrayMenu1, -1, 1) While True Sleep(1000*5) WEnd Tray 1 - Tray 4 works like expected, Tray 5-7 not. Can you explain why? Opt('TrayAutoPause', 0) $iTrayMenu1 = TrayCreateMenu('Tray Menu 1') $iTray1 = TrayCreateItem('Tray 1', $iTrayMenu1, -1, 1) TrayItemSetState(-1, 1) $iTray2 = TrayCreateItem('Tray 2', $iTrayMenu1, -1, 1) $iTray3 = TrayCreateItem('Tray 3', $iTrayMenu1, -1, 1) $iTray4 = TrayCreateItem('Tray 4', $iTrayMenu1, -1, 1) TrayCreateItem('', $iTrayMenu1) $iTray5 = TrayCreateItem('Tray 5', $iTrayMenu1, -1, 1) $iTray6 = TrayCreateItem('Tray 6', $iTrayMenu1, -1, 1) $iTray7 = TrayCreateItem('Tray 7', $iTrayMenu1, -1, 1) TrayCreateItem('', $iTrayMenu1) $iTray8 = TrayCreateItem('Tray 8', $iTrayMenu1, -1, 1) $iTray9 = TrayCreateItem('Tray 9', $iTrayMenu1, -1, 1) $iTray10 = TrayCreateItem('Tray 10', $iTrayMenu1, -1, 1) TrayCreateItem('', $iTrayMenu1) TrayCreateItem('Dumb', $iTrayMenu1) While True Sleep(1000*5) WEnd Tray 1 - Tray 7 works like expected, Tray 8-10 not. Can you explain why? Edited May 13, 2019 by MONaH-Rasta Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted May 13, 2019 Share Posted May 13, 2019 @MONaH-Rasta This line of code TrayCreateItem('', $iTrayMenu1) breaks the group made by TrayItem1 to 4, and since it's a radio button, they are controls apart. You need to use the TrayGetMsg() function in order to get messages from the other tray items Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
MONaH-Rasta Posted May 13, 2019 Author Share Posted May 13, 2019 (edited) @FrancescoDiMuro, I don't need to get messages. My script is something like this: While True If TrayItemGetState($iTray2) = 65 Then Scenario 1 Elseif TrayItemGetState($iTray3) = 65 Then Scenario 2 Else Scenario 3 EndIf Sleep(1000*60*5) WEnd Why Tray 8-10 not working? There is exactly same line of code there, I even added a checkbox in the end, but still they are not working like expected. After some tests I can say that to get those radio menuitems work propertly in menu there should be 1 additional empty item (line) + 2 additional radio menuitems TrayCreateItem('', $iTrayMenu1) $iTrayDumb1 = TrayCreateItem('Dumb 1', $iTrayMenu1, -1, 1) $iTrayDumb2 = TrayCreateItem('Dumb 2', $iTrayMenu1, -1, 1) I just want to understand why it's so. According to help file Quote Radio menuitems are automatically grouped together and these groups are separated by a separator line or a normal item which is not a radio item.By default, a clicked radio menuitem will be checked automatically and all other radio items in the same group will be unchecked!To turn off this behaviour use Opt("TrayMenuMode", 8). There is nothing about "but not when it in tray menu" Edited May 13, 2019 by MONaH-Rasta Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 14, 2019 Moderators Share Posted May 14, 2019 MONaH-Rasta, That was a fun bit of debugging! The problem seems to be using the default menu along with items with the $TRAY_ITEM_RADIO style. If you get rid of the default menu everything seems to work normally: expandcollapse popup#include <TrayConstants.au3> Opt("TrayMenuMode", 1) ; No default menu $iTray1 = TrayCreateItem('Tray 1') TrayItemSetState(-1, $TRAY_CHECKED) $iTrayMenu1 = TrayCreateMenu('Tray Menu 1') $iTray2 = TrayCreateItem('Tray 2', $iTrayMenu1, -1, $TRAY_ITEM_RADIO) TrayItemSetState(-1, $TRAY_CHECKED) $iTray3 = TrayCreateItem('Tray 3', $iTrayMenu1, -1, $TRAY_ITEM_RADIO) $iTray4 = TrayCreateItem('Tray 4', $iTrayMenu1, -1, $TRAY_ITEM_RADIO) TrayCreateItem('', $iTrayMenu1) ; Needed to close radio group $iTrayMenu2= TrayCreateMenu('Tray Menu 2') $iTray5 = TrayCreateItem('Tray 5', $iTrayMenu2, -1, $TRAY_ITEM_RADIO) TrayItemSetState(-1, $TRAY_CHECKED) $iTray6 = TrayCreateItem('Tray 6', $iTrayMenu2, -1, $TRAY_ITEM_RADIO) $iTray7 = TrayCreateItem('Tray 7', $iTrayMenu2, -1, $TRAY_ITEM_RADIO) TrayCreateItem('', $iTrayMenu2) ; Needed to close radio group $iTray8 = TrayCreateItem('Tray 8') $iTray9 = TrayCreateItem('Tray 9') $iTray10 = TrayCreateItem('Tray 10') TrayItemSetState(-1, $TRAY_CHECKED) TrayCreateItem('') $mExit = TrayCreateItem("Exit") ; Needed because there is no default menu While 1 Switch TrayGetMsg() Case $mExit Exit EndSwitch WEnd Which works fine for me - how about you? M23 FrancescoDiMuro and MONaH-Rasta 2 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 Link to comment Share on other sites More sharing options...
MONaH-Rasta Posted May 27, 2019 Author Share Posted May 27, 2019 (edited) Melba23, thanks for your suggestion. I like standart menu, so it's not an option for me. After some additional test I found that I need to place 4 empty trayitems to get everything work as expected, so my final code is like this: expandcollapse popupOpt('TrayAutoPause', 0) $iItem1 = TrayCreateItem('Item1') TrayItemSetState(-1, 1) TrayCreateItem('') $iMenu1 = TrayCreateMenu('Menu 1') $iItem2 = TrayCreateItem('Item 2', $iMenu1, -1, 1) TrayItemSetState(-1, 1) $iItem3 = TrayCreateItem('Item 3', $iMenu1, -1, 1) $iItem4 = TrayCreateItem('Item 4', $iMenu1, -1, 1) TrayCreateItem('', $iMenu1) $iItem5 = TrayCreateItem('Item 5', $iMenu1, -1, 1) TrayItemSetState(-1, 1) $iItem6 = TrayCreateItem('Item 6', $iMenu1, -1, 1) $iItem7 = TrayCreateItem('Item 7', $iMenu1, -1, 1) TrayCreateItem('', $iMenu1) TrayCreateItem('', $iMenu1) TrayCreateItem('', $iMenu1) TrayCreateItem('', $iMenu1) TrayCreateItem('') $iMenu2 = TrayCreateMenu('Menu 2') $iItem8 = TrayCreateItem('Item 8', $iMenu2, -1, 1) TrayItemSetState(-1, 1) $iItem9 = TrayCreateItem('Item 9', $iMenu2, -1, 1) $iItem10 = TrayCreateItem('Item 10', $iMenu2, -1, 1) TrayCreateItem('', $iMenu2) $iItem11 = TrayCreateItem('Item 11', $iMenu2, -1, 1) $iItem12 = TrayCreateItem('Item 12', $iMenu2, -1, 1) TrayItemSetState(-1, 1) $iItem13 = TrayCreateItem('Item 13', $iMenu2, -1, 1) TrayCreateItem('', $iMenu2) TrayCreateItem('', $iMenu2) TrayCreateItem('', $iMenu2) TrayCreateItem('', $iMenu2) TrayCreateItem('') $iMenu3 = TrayCreateMenu('Menu 3') $iItem14 = TrayCreateItem('Item 14', $iMenu3, -1, 1) TrayItemSetState(-1, 1) $iItem15 = TrayCreateItem('Item 15', $iMenu3, -1, 1) $iItem16 = TrayCreateItem('Item 16', $iMenu3, -1, 1) TrayCreateItem('', $iMenu3) $iItem17 = TrayCreateItem('Item 17', $iMenu3, -1, 1) TrayItemSetState(-1, 1) $iItem18 = TrayCreateItem('Item 18', $iMenu3, -1, 1) $iItem19 = TrayCreateItem('Item 19', $iMenu3, -1, 1) TrayCreateItem('', $iMenu3) TrayCreateItem('', $iMenu3) TrayCreateItem('', $iMenu3) TrayCreateItem('', $iMenu3) TrayCreateItem('') $iShowIEWnd = TrayCreateItem('Show IE') $iShowNotify = TrayCreateItem('Show notify') $iLogActions = TrayCreateItem('Log actions') TrayItemSetState(-1, 1) While True Sleep(1000*5) WEnd Edited May 27, 2019 by MONaH-Rasta Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 28, 2019 Moderators Share Posted May 28, 2019 MONaH-Rasta, Quote I like standart menu Why? All you get in the default tray menu is an "Exit" item - which you can easily replicate in your code - and the "Pause/Restart Script" item - which is a right pain and usually the first thing to go in any of my scripts. But if you are happy with the rather odd visual effect that your multiple empty entries give then by all means use it. 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 Link to comment Share on other sites More sharing options...
MONaH-Rasta Posted May 28, 2019 Author Share Posted May 28, 2019 @Melba23, ok, what do you use to pause script? It's quite usefull for me... Something like this? TrayCreateItem('') $mPause = TrayCreateItem("Pause") ; Needed because there is no default menu TrayCreateItem('') $mExit = TrayCreateItem("Exit") ; Needed because there is no default menu While True Switch TrayGetMsg() Case $mExit Exit Case $mPause While TrayItemGetState($mPause) = 65 Sleep(1000) WEnd EndSwitch WEnd Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 28, 2019 Moderators Share Posted May 28, 2019 MONaH-Rasta, I rarely want to pause my scripts - they are usually designed to work full-time! But there are many ways to pause scripts programmatically - just search the forum and you will find many examples of how to do it. As an aside, I quite often use TrayOnEvent mode for the tray menu, while retaining MessageLoop mode for the main idle loop. That way the tray items get actioned instantly and are not affected by any ongoing functions within the main script. Why is that important? The Interrupting a running function tutorial in the Wiki will explain. M23 MONaH-Rasta and krasnoshtan 2 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 Link to comment Share on other sites More sharing options...
MONaH-Rasta Posted May 31, 2019 Author Share Posted May 31, 2019 (edited) I'm using traymenu for 3 main purposes: Set script options (Like on/off logging, notifications, etc.) Pause the script Exit script. So I don't need no TrayGetMsg() nor TrayOnEven't mode. I just never need my script to react immediately on tray item state changes. If this "bug" with behaviour of traymenu with standard menu on is "ok" for developers of autoit, then I will just use 4 empty items and that's it 😎 Edited May 31, 2019 by MONaH-Rasta 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