minimizing a window to the system tray and not the task bar

Just starting out? Need help? Post your questions and find answers here.
Rookie
Enthusiast
Enthusiast
Posts: 106
Joined: Tue May 20, 2003 4:16 pm
Location: Florida
Contact:

minimizing a window to the system tray and not the task bar

Post by Rookie »

how would you go about do it i have no clue
Insanity is over rated, unless you can join me in mine.
Don't post questions at work
Don't post questions at work
Don't post questions at work
newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

Post by newbie »

Hi,

in your evenments loop, you should have the following Select :

Code: Select all

Select EventID 

case xx

case xx

default

endselect
before the loop, in your code, write this :

Code: Select all

hwnd = WindowID(#Window_0)
SysTrayIcon.l = ExtractIcon_(hwnd,"yourappname.exe",0)
AddSysTrayIcon(0, WindowID(0), SysTrayIcon) 
SysTrayIconToolTip(0, "your text description") 
Then under default, write :

Code: Select all

If IsIconic_(hwnd) <> 0 ;the window has been minimized 
  HideWindow(#Window_0, 1)
endif
and add after Select EventID :

Code: Select all

Case #PB_Event_SysTray
  Select EventType() 
      Case #PB_EventType_LeftDoubleClick 
      HideWindow(#Window_0, 0)
   EndSelect
- Registered PB user -

Using PB 4.00
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Re: minimizing a window to the system tray and not the task

Post by NoahPhense »

Rookie,

Do you have the 'codearchiv'?

Code: Select all

; German forum: http://robsite.de/php/pureboard/viewtopic.php?t=3339&highlight=
; Author: PWS32
; Date: 05. January 2004


If OpenWindow(0, 100, 200, 195, 260, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget, "Test Window") 

  If CreatePopupMenu(0) 
    MenuItem(1, "Restore Window") 
    MenuBar() 
    MenuItem(2, "Quit") 
  EndIf  
  
  MessageRequester("Info", "lass mal verschwinden", 0) 
  HideWindow(0, 1) 
  AddSysTrayIcon (1, WindowID(), LoadImage(0, "..\..\Graphics\Gfx\help16.ico")) ; <<--- hier irgend ein 16X16 Icon nehmen 
  SysTrayIconToolTip (1, "Rechte Maustaste für PopUp") 


  Repeat 

    EventID.l = WaitWindowEvent() 

    If EventID = #PB_Event_SysTray ; <<-- PopUp bei click auf rechter Maustaste auf Dein Systray Icon 
      If EventType() = #PB_EventType_RightClick 
        DisplayPopupMenu(0, WindowID()) 
      EndIf 
    EndIf 

    If EventID = #PB_EventMenu ; <<-- PopUp Event 
      Select EventMenuID() 
        Case 1 ; Restore 
           RemoveSysTrayIcon (1) 
           HideWindow(0, 0) 
           MessageRequester("Info", "drück mal OK und dann den Minimize Button am Fenster", 0) 
        Case 2 ; Quit 
           Quit = 1 
      EndSelect 
    EndIf 
    
    If IsIconic_(WindowID()) ;<<-- dasselbe mit dem Minimize Button 
      HideWindow(0, 1) 
      AddSysTrayIcon (1, WindowID(), LoadImage(0, "..\..\Graphics\Gfx\help16.ico")) 
      SysTrayIconToolTip (1, "Rechte Maustaste für PopUp") 
    EndIf 



    If EventID = #PB_Event_CloseWindow 
      Quit = 1 
    EndIf 

  Until Quit = 1 
  
EndIf 

End  
If not you can get it from here:
http://www.purearea.net/

- np
Nico
Enthusiast
Enthusiast
Posts: 274
Joined: Sun Jan 11, 2004 11:34 am
Location: France

Post by Nico »

Here is a simple code:

Code: Select all

If OpenWindow(0, 100, 150, 300, 100, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget, "PureBasic - SysTray Example") 

  AddSysTrayIcon(0, WindowID(), LoadImage(0, "Data\CdPlayer.ico")) 
  SysTrayIconToolTip(0, "Icon 1") 
  
  If CreatePopupMenu(0) 
    MenuItem(1, "Restaurer") 
  EndIf 
  
  Repeat 
    Event = WaitWindowEvent() 
    
    Select Event 
      Case #PB_Event_SysTray 
        If EventType() = #PB_EventType_RightClick 
          DisplayPopupMenu(0, WindowID()) 
           If IsIconic_(WindowID(0)) 
            ;cette ligne est utilisée pour l'effet d'agrandissement 
            ShowWindow_(WindowID(0),#sw_minimize) 
            ;Une tempo est nécessaire sinon ça ne fonctionne pas à tous les coups 
            Delay(250) 
            ShowWindow_(WindowID(0),#sw_restore) 
          EndIf 
        EndIf 

      Case #WM_SIZE 
        If IsIconic_(WindowID(0)) 
          ShowWindow_(WindowID(0),#sw_hide) 
        EndIf 
    EndSelect  
  Until Event = #PB_Event_CloseWindow 
EndIf 
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

..

Post by NoahPhense »

And here is a modified version with the icon embedded in the exe..

Code: Select all

Enumeration
  #Image0
EndEnumeration

Image0 = CatchImage(0, ?Image0)

If OpenWindow(0, 100, 150, 300, 100, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget, "PureBasic - SysTray Example") 

  AddSysTrayIcon(0, WindowID(), Image0)
  SysTrayIconToolTip(0, "Icon 1") 
  
  If CreatePopupMenu(0) 
    MenuItem(1, "Restaurer") 
  EndIf 
  
  Repeat 
    Event = WaitWindowEvent() 
    
    Select Event 
      Case #PB_Event_SysTray 
        If EventType() = #PB_EventType_RightClick 
          DisplayPopupMenu(0, WindowID()) 
           If IsIconic_(WindowID(0)) 
            ;cette ligne est utilisée pour l'effet d'agrandissement 
            ShowWindow_(WindowID(0),#sw_minimize) 
            ;Une tempo est nécessaire sinon ça ne fonctionne pas à tous les coups 
            Delay(250) 
            ShowWindow_(WindowID(0),#sw_restore) 
          EndIf 
        EndIf 

      Case #WM_SIZE 
        If IsIconic_(WindowID(0)) 
          ShowWindow_(WindowID(0),#sw_hide) 
        EndIf 
    EndSelect  
  Until Event = #PB_Event_CloseWindow 
EndIf

; // DataSection // ------------------------------------------------- //
DataSection
Image0:
  IncludeBinary "C:\Program Files\NSIS\Contrib\Graphics\Icons\box-install.ico"
EndDataSection
- np
Post Reply