Is there a way to create a PureBasic app
that only uses a tray icon?
It shouldn't create / show any visible windows
and it would be nice if the tray icon could
provide a right click menu with toggle options
(option1, option2, etc. - on / off) and an "Exit"
entry that kills the whole app...
Tray icon only?
Re: Tray icon only?
Why even make it visible?It shouldn't create / show any visible windows
Code: Select all
If OpenWindow(0, 100, 150, 300, 100, "PureBasic - SysTray Example", #PB_Window_Invisible)
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
; .ico format is available only on Windows
IconName$ = #PB_Compiler_Home + "examples/sources/Data/CdPlayer.ico"
CompilerElse
IconName$ = #PB_Compiler_Home + "examples/sources/Data/Drive.bmp"
CompilerEndIf
AddSysTrayIcon(1, WindowID(0), LoadImage(0, IconName$))
SysTrayIconToolTip(1, "Icon 1")
If CreatePopupMenu(0)
MenuItem(1, "Option 1")
MenuItem(2, "Option 2")
MenuItem(3, "Option 3")
MenuBar()
MenuItem(0, "Exit")
EndIf
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_SysTray
Select EventType()
Case #PB_EventType_LeftClick, #PB_EventType_RightClick
DisplayPopupMenu(0, WindowID(0))
EndSelect
Case #PB_Event_Menu
Select EventMenu()
Case 0
Event = #PB_Event_CloseWindow
Case 1 To 3
SetMenuItemState(0, EventMenu(), 1-GetMenuItemState(0, EventMenu()))
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
Et cetera is my worst enemy
Re: Tray icon only?
Very cool.
Thanks a lot for the example code, chi!
Works like a charm...
Thanks a lot for the example code, chi!
Works like a charm...
- netmaestro
- PureBasic Bullfrog
- Posts: 8425
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Tray icon only?
Best window to use for that is a message-only window. It is not visible, has no toolbar icon and is not enumerated. For most window purposes, it simply does not exist. But it will process messages and that's all you need. Make a message-only window like this:
Code: Select all
#HWND_MESSAGE = -3
OpenWindow(0,0,0,0,0,"",#PB_Window_Invisible)
SetParent_(WindowID(0), #HWND_MESSAGE)
BERESHEIT
Re: Tray icon only?
Nice one, thanksnetmaestro wrote:SetParent_(WindowID(0), #HWND_MESSAGE)
Et cetera is my worst enemy
Re: Tray icon only?
From me as wellNice one, thanks