Page 1 of 1

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

Posted: Sat Jul 17, 2004 5:43 pm
by Rookie
how would you go about do it i have no clue

Posted: Sat Jul 17, 2004 6:03 pm
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

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

Posted: Sat Jul 17, 2004 6:25 pm
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

Posted: Sat Jul 17, 2004 7:52 pm
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 

..

Posted: Sat Jul 17, 2004 11:49 pm
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