Tredi51 Posted January 22, 2023 Share Posted January 22, 2023 Hi, AutoIt help says " TrayItemGetHandle Returns the handle for a tray menu(item). TrayItemGetHandle ( controlID ) Parameters controlID The control identifier (controlID) as returned by a TrayCreateItem or TrayCreateMenu function. " but it doesn't work if the controlID is a control created with TrayCreateItem. You can see it In the example #NoTrayIcon Opt("TrayMenuMode", 3) Local $idMenu = TrayCreateMenu("Menu") Local $idItem = TrayCreateItem("Item") MsgBox(Default,"Test", _ "Menu " & $idMenu & " " & TrayItemGetHandle($idMenu) _ & @CRLF & _ "Item " & $idItem & " " & TrayItemGetHandle($idItem) _ ) Exit Is it a bug? Link to comment Share on other sites More sharing options...
Trong Posted January 22, 2023 Share Posted January 22, 2023 I got the code in the manual it works fine on my computer: expandcollapse popup#NoTrayIcon #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <TrayConstants.au3> ; Required for the $TRAY_ICONSTATE_SHOW constant. Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode. Global Const $MIM_APPLYTOSUBMENUS = 0x80000000, $MIM_BACKGROUND = 0x00000002 ; Constants required for SetMenuColor Example() Func Example() Local $idSettings = TrayCreateMenu("Settings") ; Create a tray menu sub menu with two sub items. Local $idDisplay = TrayCreateItem("Display", $idSettings) Local $idPrinter = TrayCreateItem("Printer", $idSettings) TrayCreateItem("") ; Create a separator line. Local $idAbout = TrayCreateItem("About") TrayCreateItem("") ; Create a separator line. Local $idExit = TrayCreateItem("Exit") TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu. SetMenuColor(0, 0xEEBB99) ; BGR color value, '0' refers to the tray menu itself. SetMenuColor($idSettings, 0x66BB99); BGR color value for the 'Settings' menu. While 1 Switch TrayGetMsg() Case $idAbout ; Display a message box about the AutoIt version and installation path of the AutoIt executable. MsgBox($MB_SYSTEMMODAL, "", "AutoIt tray menu example." & @CRLF & @CRLF & _ "Version: " & @AutoItVersion & @CRLF & _ "Install Path: " & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1)) ; Find the folder of a full path. Case $idDisplay, $idPrinter MsgBox($MB_SYSTEMMODAL, "", "A sub menu item was selected from the tray menu.") Case $idExit ; Exit the loop. ExitLoop EndSwitch WEnd EndFunc ;==>Example Func SetMenuColor($iMenuID, $iColor) Local $hMenu = TrayItemGetHandle($iMenuID) ; Get the internal menu handle Local $hBrush = DllCall("gdi32.dll", "hwnd", "CreateSolidBrush", "int", $iColor) $hBrush = $hBrush[0] Local $tMenuInfo = DllStructCreate("dword;dword;dword;uint;ptr;dword;ptr") DllStructSetData($tMenuInfo, 1, DllStructGetSize($tMenuInfo)) DllStructSetData($tMenuInfo, 2, BitOR($MIM_APPLYTOSUBMENUS, $MIM_BACKGROUND)) DllStructSetData($tMenuInfo, 5, $hBrush) DllCall("user32.dll", "int", "SetMenuInfo", "hwnd", $hMenu, "struct*", $tMenuInfo) EndFunc ;==>SetMenuColor Regards, Link to comment Share on other sites More sharing options...
Nine Posted January 22, 2023 Share Posted January 22, 2023 @Trong You got it wrong. The example gets the handle of a tray menu (not a tray item). Issue found by @Tredi51 is about retrieving the handle of a trey item (see his example). @jpm might be able to answer better than me. “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) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
TimRude Posted January 23, 2023 Share Posted January 23, 2023 (edited) I don't think tray items have handles since they're not separate controls. The standard tray menu itself is a control that has a handle accessible via TrayItemGetHandle(0) but I looked through the MSDN info and couldn't find any reference to handles for menu items themselves. If you create a menu on a GUI using GUICtrlCreateMenu and GUICtrlCreateMenuItem, you can get the handle of the menu control with GUICtrlGetHandle but you can't get a handle for a menu item using GUICtrlGetHandle. And if you look at the _GUICtrlMenu... functions, none of them reference a handle for a menu item directly. It's always the handle of the menu control, and then the ID number of the menu item on that control. So it sounds like the help info for TrayItemGetHandle could use some tweaking to clarify what it can and can't return. Edited January 23, 2023 by TimRude 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