EnableExplicit

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

Global tt = MemoryStatus(#PB_System_TotalPhysical) / 16
Global mem


If OpenWindow(#Window, 0, 0, 300, 100, "", #PB_Window_Invisible)
	If CreateImage(0, 16, 16) And StartDrawing(ImageOutput(0))
		Box(0, 0, 16 , 16, $00FFFF)
		StopDrawing()
	EndIf
	If CreatePopupImageMenu(#Menu)
		MenuItem(0, "Exit")
	EndIf
	AddSysTrayIcon(#TrayIcon, WindowID(#Window), ImageID(0))
	AddWindowTimer(#Window, #Timer, 1000)

    ;- loop
	Repeat
		Select WaitWindowEvent()
			Case #PB_Event_Timer
				If StartDrawing(ImageOutput(0))
					Box(0, 0, 16 , 16, $00FFFF)
					mem = MemoryStatus(#PB_System_FreePhysical) / tt
					Box(1, mem, 14, 16 - mem, $0000FF)
					StopDrawing()
					ChangeSysTrayIcon(#TrayIcon, ImageID(0))
				EndIf
			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