WoodGrain Posted July 16, 2015 Posted July 16, 2015 Hi guys,I'm using this startup example to allow the program menu to insert an option to "AutoStart" the script. What I'd like to do is update the checkbox of the menu item after they click it to then reflect the "AutoStart" state (on or off).How do I update the menu on the event someone clicks the menu option? The registry is updating correctly, and if I close and re-run the script the menu is updated, but not in the same script execution. I wasn't sure with TrayItemSetState for my "Func AutoStart()" Function what the "controlID" was. I tried 0 through to 3 and "AutoStart" text. Perhaps this is where I'm going wrong?expandcollapse popup; Add custom tray icon menu #NoTrayIcon #include <MsgBoxConstants.au3> #include <TrayConstants.au3> Opt("TrayMenuMode", 3) Opt("TrayOnEventMode", 1) #include '_Startup.au3' TrayCreateItem("AutoStart") TrayItemSetOnEvent(-1, "AutoStart") If _StartupRegistry_Exists() Then TrayItemSetState(-1, $TRAY_CHECKED) Else TrayItemSetState(-1, $TRAY_UNCHECKED) EndIf TrayCreateItem("About") TrayItemSetOnEvent(-1, "About") TrayCreateItem("") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "ExitScript") TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "About") TraySetState($TRAY_ICONSTATE_SHOW) ; ################## ; ### OTHER CODE ### ; ################## Func About() MsgBox(0,"About","etc") EndFunc Func AutoStart() If _StartupRegistry_Exists() Then _StartupRegistry_Uninstall() TrayItemSetState("AutoStart", $TRAY_UNCHECKED) Else _StartupRegistry_Install() TrayItemSetState("AutoStart", $TRAY_CHECKED) EndIf EndFunc Func ExitScript() Exit EndFuncThanks!
WoodGrain Posted July 16, 2015 Author Posted July 16, 2015 I note that I could probably use the "$TRAY_ITEM_RADIO" for "TrayCreateItem" but would prefer the check box, looks cleaner and only gives them 1 option.The checkbox appears to function, it's just the menu isn't updating while the script is running.
Moderators Melba23 Posted July 16, 2015 Moderators Posted July 16, 2015 WoodGrain,You need to use a ControlID in the TrayItemSetState call - at the moment you are using a literal text string:expandcollapse popup#include <TrayConstants.au3> Opt("TrayMenuMode", 3) Opt("TrayOnEventMode", 1) Global $bRegIstalled = False $cAutoStart = TrayCreateItem("AutoStart") ; Store ControlID here TrayItemSetOnEvent($cAutoStart, "AutoStart") TrayCreateItem("About") TrayCreateItem("") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "ExitScript") TraySetState($TRAY_ICONSTATE_SHOW) While 1 Sleep(10) WEnd Func AutoStart() If $bRegIstalled Then $bRegIstalled = False TrayItemSetState($cAutoStart, $TRAY_UNCHECKED) ; Use it here... Else $bRegIstalled = True TrayItemSetState($cAutoStart, $TRAY_CHECKED) ; ...and here EndIf EndFunc Func ExitScript() Exit EndFuncAll clear?M23 WoodGrain 1 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
WoodGrain Posted July 16, 2015 Author Posted July 16, 2015 Perfect! Thank you Melba23!I thought I was on the path with the ControlID.
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