#TrayIcon = 0
#Window = 0
#Menu = 0

If OpenWindow(#Window, 0, 0, 300, 100, "", #PB_Window_Invisible)
	If CreatePopupImageMenu(#Menu)
		MenuItem(0, "Exit")
	EndIf
	AddSysTrayIcon(#TrayIcon, WindowID(#Window), 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(#Menu, WindowID(#Window)) ; show popup menu
				EndSelect
			Case #PB_Event_Menu
				Select EventMenu()
					Case 0 ; Exit
						RemoveSysTrayIcon(#TrayIcon)
						FreeMenu(#Menu)
						CloseWindow(#Window)
						End
				EndSelect
		EndSelect
	ForEver
EndIf