AndroidZero Posted March 13, 2019 Posted March 13, 2019 (edited) I like to work with TrayIconMenus & Items and here is my problem I want to create a new TrayItem through clicking on a special TrayItem and this new created one should be added as a new Case to a Switch list. Is it possible or is there another way to realize this ? expandcollapse popup;~ #NoTrayIcon ;======= LIBRARIES ============ #include <TrayConstants.au3> #include <MsgBoxConstants.au3> ;=== Before loading [Includes/Globals/Constants/Registers etc]==== ;=== Important Stuff below ==== Global $TrayItemAdd, $TrayItemInfo, $TrayItemExit Global $TrayCustomCounter = 0 Opt("GUIOnEventMode", 1) Opt("TrayMenuMode", 3) Main() Func Main() $TrayItemAdd = TrayCreateItem("Add") $TrayItemInfo = TrayCreateItem("Info") $TrayItemExit = TrayCreateItem("Exit") TraySetState(1) While 1 Switch TrayGetMsg() Case $TrayItemAdd ;===== Count up $TrayCustomCounter ==== $TrayCustomCounter = $TrayCustomCounter + 1 ;===== Init New TrayMenu as Global Variable ==== Assign("CustomMenu" & $TrayCustomCounter, TrayCreateMenu("Custom Menu " & $TrayCustomCounter, -1, 0), 2) ;===== Init New TrayItem as Global Variable ==== Assign("CustomItem" & $TrayCustomCounter, TrayCreateItem("Custom Item" & $TrayCustomCounter, Eval("CustomMenu" & $TrayCustomCounter)), 2) ;===== Add New Global Variable Item to Switch Case List and add Function To Case ==== ;Case Eval("CustomItem" & $TrayCustomCounter) ;$TrayItemText = TrayItemGetText($CustomItem1) ;TrayTip("Tray Clicked", "Hello! I am CustomItem" & $TrayCustomCounter & @CRLF & "Thank you for creating me <3", 5) #comments-start =========== Here is the new Case Entry that $TrayItemAdd generated =============================== Case Eval("CustomItem" & $TrayCustomCounter) $TrayItemText = TrayItemGetText($CustomItem1) TrayTip("Tray Clicked", "Hello! I am CustomItem" & $TrayCustomCounter & @CRLF & "Thank you for creating me <3", 5) #comments-end Case $TrayItemInfo TrayTip("Info","Currently " & $TrayCustomCounter & " Custom TrayMenus & TrayItems created", 5) Case $TrayItemExit Exit EndSwitch Wend Sleep(500) EndFunc Edited March 13, 2019 by AndroidZero
Nine Posted March 13, 2019 Posted March 13, 2019 I would probably do it through an array of Tray Item. Then I would manage the message in the else case of the switch. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
AndroidZero Posted March 13, 2019 Author Posted March 13, 2019 (edited) @Nine Thank you buddy !! Saving Objects in Array thats simple and saved me a lot of lines in other projects... Here is a way how I solved my main script with the above example script expandcollapse popup;~ #NoTrayIcon ;======= LIBRARIES ============ #include <TrayConstants.au3> #include <MsgBoxConstants.au3> ;=== Before loading [Includes/Globals/Constants/Registers etc]==== ;=== Important Stuff below ==== Global $TrayItemAdd, $TrayItemInfo, $TrayItemExit Global $TrayCustomCounter = 0 Global $TrayCustomMenuContainer[0] Global $TrayCustomItemContainer[0] Opt("GUIOnEventMode", 1) Opt("TrayMenuMode", 3) Main() Func Main() $TrayItemAdd = TrayCreateItem("Add") $TrayItemInfo = TrayCreateItem("Info") $TrayItemExit = TrayCreateItem("Exit") TraySetState(1) While 1 $TrayGetMsgFrozen = TrayGetMsg() Switch $TrayGetMsgFrozen Case $TrayItemAdd ConsoleWrite(@CRLF & "======== $TrayItemAdd ========") ConsoleWrite(@CRLF & "TrayGetMsg ID: " & $TrayGetMsgFrozen) ConsoleWrite(@CRLF & "TrayItemAdd ID: " & $TrayItemAdd) ;===== Count up $TrayCustomCounter ==== $TrayCustomCounter = $TrayCustomCounter + 1 ;===== Init New TrayMenu as Global Variable ==== Assign("CustomMenu" & $TrayCustomCounter, TrayCreateMenu("Custom Menu " & $TrayCustomCounter, -1, 0), 2) ;===== Init New TrayItem as Global Variable ==== Assign("CustomItem" & $TrayCustomCounter, TrayCreateItem("Custom Item" & $TrayCustomCounter, Eval("CustomMenu" & $TrayCustomCounter)), 2) ;===== Add New Global Variable Item to Switch Case List and add Function To Case ==== ReDim $TrayCustomMenuContainer[$TrayCustomCounter] ReDim $TrayCustomItemContainer[$TrayCustomCounter] $TrayCustomMenuContainer[$TrayCustomCounter-1] = Eval("CustomMenu" & $TrayCustomCounter) $TrayCustomItemContainer[$TrayCustomCounter-1] = Eval("CustomItem" & $TrayCustomCounter) Case $TrayItemInfo ConsoleWrite(@CRLF & "======== $TrayItemInfo ========") ConsoleWrite(@CRLF & "TrayGetMsg ID: " & $TrayGetMsgFrozen) ConsoleWrite(@CRLF & "TrayItemInfo ID: " & $TrayItemInfo) TrayTip("Info","Currently " & $TrayCustomCounter & " Custom TrayMenus & TrayItems created", 5) Case $TrayItemExit Exit Case Else For $i=0 To UBound($TrayCustomItemContainer)-1 If $TrayGetMsgFrozen == $TrayCustomItemContainer[$i] Then ConsoleWrite(@CRLF & "======== ? Else ? ========") ConsoleWrite(@CRLF & "TrayGetMsg ID: " & $TrayGetMsgFrozen) ConsoleWrite(@CRLF & "Else ID: " & $TrayCustomItemContainer[$i]) $TrayItemText = TrayItemGetText($TrayCustomItemContainer[$i]) TrayTip("Tray Clicked", "Hello! I am CustomItem" & $i+1 & @CRLF & "Thank you for creating me <3", 5) ExitLoop EndIf Next EndSwitch Wend Sleep(500) EndFunc Edited March 13, 2019 by AndroidZero
Nine Posted March 13, 2019 Posted March 13, 2019 7 minutes ago, AndroidZero said: @Nine Thank you buddy !! Saving Objects in Array thats simple and saved me a lot of lines in other projects... Ya simple things are simpler to manage ! “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
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