It is currently Mon Dec 11, 2017 5:06 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Tray icon only?
PostPosted: Tue Oct 31, 2017 3:29 pm 
Offline
User
User

Joined: Tue Jun 17, 2014 4:49 pm
Posts: 39
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...


Top
 Profile  
Reply with quote  
 Post subject: Re: Tray icon only?
PostPosted: Tue Oct 31, 2017 3:49 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat May 05, 2007 5:31 pm
Posts: 370
Location: Linz, Austria
Quote:
It shouldn't create / show any visible windows
Why even make it visible? ;)
Code:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Tray icon only?
PostPosted: Tue Oct 31, 2017 5:33 pm 
Offline
User
User

Joined: Tue Jun 17, 2014 4:49 pm
Posts: 39
Very cool.

Thanks a lot for the example code, chi!

Works like a charm...


Top
 Profile  
Reply with quote  
 Post subject: Re: Tray icon only?
PostPosted: Tue Oct 31, 2017 9:01 pm 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 7957
Location: Kelowna, BC, Canada
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:
#HWND_MESSAGE = -3
OpenWindow(0,0,0,0,0,"",#PB_Window_Invisible)
SetParent_(WindowID(0), #HWND_MESSAGE)

_________________
Veni, vidi, vici.


Top
 Profile  
Reply with quote  
 Post subject: Re: Tray icon only?
PostPosted: Wed Nov 01, 2017 3:05 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat May 05, 2007 5:31 pm
Posts: 370
Location: Linz, Austria
netmaestro wrote:
SetParent_(WindowID(0), #HWND_MESSAGE)
Nice one, thanks


Top
 Profile  
Reply with quote  
 Post subject: Re: Tray icon only?
PostPosted: Wed Nov 01, 2017 12:57 pm 
Offline
User
User

Joined: Tue Jun 17, 2014 4:49 pm
Posts: 39
Quote:
Nice one, thanks


From me as well :mrgreen:


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye