Page 1 of 1

WaitWindowEvent throws Minimize event after Systray event

Posted: Sun Jun 12, 2016 10:41 pm
by Frarth
This has driving me nuts.

My program starts with a window set to invisible. On startup a system tray icon appears. So far so good.

1. When I click on the system tray icon the window appears. When I minimize the window, it is hidden again. Perfect.

2. When I click on the system tray icon again, the window does not show up again.

When debugging I noticed that after step 1 WaitWindowEvent throws a minimize event (12) automatically after the systray event (9), which causes the window to never show up again. This is happening on Linux by the way.

Here is the event loop:

Code: Select all

repeat
    event = WaitWindowEvent()
    select event
    case #PB_Event_SysTray
      HideWindow(#win1, #false, #PB_Window_ScreenCentered)
    case #PB_Event_MinimizeWindow
      HideWindow(#win1, #true)
    endselect
  until event = #PB_Event_CloseWindow
Does anyone have any idea?

Re: WaitWindowEvent throws Minimize event after Systray even

Posted: Mon Jun 13, 2016 12:48 am
by RASHAD
The window should be in normal or maximum state(Shown - Active) to respond to commands

Code: Select all

If OpenWindow(0, 100, 150, 300, 100, "PureBasic - SysTray Example", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_Invisible)
   StickyWindow(0,1)
  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$))
  ;AddSysTrayIcon(2, WindowID(0), LoadImage(1, IconName$))
  SysTrayIconToolTip(1, "Icon 1")
  ;SysTrayIconToolTip(2, "Icon 2")
  
  Repeat
    event = WaitWindowEvent()
    Select event
    Case #PB_Event_SysTray
          SetWindowState(0,#PB_Window_Normal) 
          HideWindow(0, #False, #PB_Window_ScreenCentered)
      
    Case #PB_Event_MinimizeWindow
          HideWindow(0, #True)
      
    EndSelect
  Until event = #PB_Event_CloseWindow
  
EndIf

Re: WaitWindowEvent throws Minimize event after Systray even

Posted: Mon Jun 13, 2016 8:13 am
by Frarth
Thanks a lot Rashad. I tried to set the window state too, but after the HideWindow command

Code: Select all

HideWindow(#win1, #false, #PB_Window_ScreenCentered)
SetWindowState(#win1, #PB_Window_Normal)
So that seems to be the problem. Thanks again.

Re: WaitWindowEvent throws Minimize event after Systray even

Posted: Mon Jun 13, 2016 8:59 pm
by mestnyi
The only way windows works

Code: Select all

Case #PB_Event_SysTray
          SetWindowState(0,#PB_Window_Normal) 
          HideWindow(0, #False, #PB_Window_ScreenCentered)
          SetForegroundWindow_(WindowID(0))
    

Re: WaitWindowEvent throws Minimize event after Systray even

Posted: Mon Jun 13, 2016 11:30 pm
by RASHAD
PureBasic 5.41 | Linux Mint 17 | Windows 7 (x64)
Hi Frarth
Cross platform

Code: Select all

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

  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$))
  ;AddSysTrayIcon(2, WindowID(0), LoadImage(1, IconName$))
  SysTrayIconToolTip(1, "Icon 1")
  ;SysTrayIconToolTip(2, "Icon 2")
  
  Repeat
    event = WaitWindowEvent()
    Select event
         
    Case #PB_Event_SysTray
          HideWindow(0, #False)
          SetWindowState(0,#PB_Window_Normal)
          HideWindow(0, #False, #PB_Window_ScreenCentered)
     
    Case #PB_Event_MinimizeWindow
          HideWindow(0, #True)
     
    EndSelect
  Until event = #PB_Event_CloseWindow
 
EndIf


Re: WaitWindowEvent throws Minimize event after Systray even

Posted: Tue Jun 14, 2016 7:00 am
by Frarth
Thanks Rashad.