Always show systray icon in notification area
Posted: Wed Nov 08, 2023 11:03 am
Example code from PB's help for AddSysTrayIcon():
When the code is run for the first time e.g. on Windows 11, the CD player icon is not shown in the taskbar notification area, but is hidden in the taskbar corner overflow (see red arrow on the left side of the following picture):

I know I can move any icon from there to the taskbar notification area, e.g. by drag and drop with the mouse. However, I'm writing a program, the only purpose of which is to show an icon in the tasbar notification area that represents some information about the current status of the computer. Is it possible to programmatically tell Windows (11) to show my icon from the very beginning in the taskbar notification area, without the user having to move it there manually?
Code: Select all
If OpenWindow(0, 0, 0, 300, 100, "", #PB_Window_Invisible)
; Create a pop-up menu and a Systray icon (CD symbol) with this menu associated:
If CreatePopupImageMenu(0)
MenuItem(0, "Exit")
EndIf
AddSysTrayIcon(0, WindowID(0), LoadImage(0, #PB_Compiler_Home + "Examples\Sources\Data\CdPlayer.ico"))
Repeat
Select WaitWindowEvent()
Case #PB_Event_SysTray
Select EventType()
Case #PB_EventType_RightClick, #PB_EventType_LeftClick
DisplayPopupMenu(0, WindowID(0)) ; Show pop-up menu after a mouse-click on the Systray icon
EndSelect
Case #PB_Event_Menu
Select EventMenu()
Case 0 ; Exit
RemoveSysTrayIcon(0)
FreeMenu(0)
CloseWindow(0)
End
EndSelect
EndSelect
ForEver
EndIf

I know I can move any icon from there to the taskbar notification area, e.g. by drag and drop with the mouse. However, I'm writing a program, the only purpose of which is to show an icon in the tasbar notification area that represents some information about the current status of the computer. Is it possible to programmatically tell Windows (11) to show my icon from the very beginning in the taskbar notification area, without the user having to move it there manually?