Search the Community
Showing results for tags 'tray menu icons'.
-
Here's a code sample showing how I add icon images (in this simple case just colored blocks) to the tray items. It should be noted that I used solid blocks to simplify the example, but anything can be set as the bitmap (and in any size) using the appropriate code to generate a bitmap to feed into the _GUICtrlMenu_SetItemBmp function. #NoTrayIcon #include <TrayConstants.au3> #include <ColorConstants.au3> #include <GuiMenu.au3> #include <WinAPIGdi.au3> 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. Opt("TrayOnEventMode", 1) ; Enable TrayOnEventMode. Global $idTrayText, $idUDFText Example() Func Example() Local $iBmpSize = 32 TrayCreateItem("About") TrayItemSetOnEvent(-1, "About") _TrayItemSetBmp(-1, $iBmpSize, $COLOR_BLUE) TrayCreateItem("") ; Create a separator line. $idTrayText = TrayCreateItem("Read Text with TrayItemGetText") TrayItemSetOnEvent(-1, "TrayText") _TrayItemSetBmp(-1, $iBmpSize, $COLOR_GREEN) $idUDFText = TrayCreateItem("Read Text with _GUICtrlMenu_GetItemText") TrayItemSetOnEvent(-1, "UDFText") _TrayItemSetBmp(-1, $iBmpSize, $COLOR_ORANGE) TrayCreateItem("") ; Create a separator line. TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "ExitScript") _TrayItemSetBmp(-1, $iBmpSize, $COLOR_RED) TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu. While 1 Sleep(100) ; An idle loop. WEnd EndFunc ;==>Example Func About() MsgBox(0, "Tray Menu Item Image Icons", "AutoIt tray menu item image icons example.") EndFunc ;==>About Func TrayText() ConsoleWrite("TrayText: " & TrayItemGetText($idTrayText) & @CRLF) EndFunc ;==>TrayText Func UDFText() Local $hMenu = TrayItemGetHandle(0) ConsoleWrite("UDFText: " & _GUICtrlMenu_GetItemText($hMenu, $idUDFText, False) & @CRLF) EndFunc ;==>UDFText Func ExitScript() Exit EndFunc ;==>ExitScript Func _TrayItemSetBmp($idControl, $iBmpSize, $iColor, $bRGB = 1) ; Adds an image (bitmap) to a tray menu item - solid block of color ; $idControl = the control ID of the menu item (or -1 for last created item) ; $iBmpSize = the size of the Bmp (height & width are the same) ; $iColor = the color of the bitmap, stated in RGB ; $bRGB [optional] = if True converts to COLOREF (0x00bbggrr) Local $hMenu = TrayItemGetHandle(0) ; handle for standard tray menu If $idControl = -1 Then $idControl = _GUICtrlMenu_GetItemID($hMenu, _GUICtrlMenu_GetItemCount($hMenu) - 1, True) ; last item in menu _GUICtrlMenu_SetItemBmp($hMenu, $idControl, _WinAPI_CreateSolidBitmap(WinGetHandle(AutoItWinGetTitle()), $iColor, $iBmpSize, $iBmpSize, $bRGB), False) EndFunc ;==>_TrayItemSetBmp This example also illustrates an odd quirk. Once you add an image to a tray menu item using the _GUICtrlMenu_SetItemBmp function, you can no longer use TrayItemGetText or TrayItemSetText on that item. Sometimes TrayItemGetText returns gibberish (like it's reading the wrong portion of memory) and sometimes it returns nothing. And TrayItemSetText doesn't change the item text. However, the functions _GUICtrlMenu_GetItemText and _GUICtrlMenuSetItemText work just fine as replacements. Any ideas from the developers (or anyone else) as to why adding an image messes up the TrayItemGetText and TrayItemSetText functions? Maybe something for the Bug Tracker?