WaitWindowEvent throws Minimize event after Systray event

Just starting out? Need help? Post your questions and find answers here.
User avatar
Frarth
Enthusiast
Enthusiast
Posts: 241
Joined: Tue Jul 21, 2009 11:11 am
Location: On the planet
Contact:

WaitWindowEvent throws Minimize event after Systray event

Post 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?
PureBasic 5.41 LTS | Xubuntu 16.04 (x32) | Windows 7 (x64)
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: WaitWindowEvent throws Minimize event after Systray even

Post 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
Egypt my love
User avatar
Frarth
Enthusiast
Enthusiast
Posts: 241
Joined: Tue Jul 21, 2009 11:11 am
Location: On the planet
Contact:

Re: WaitWindowEvent throws Minimize event after Systray even

Post 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.
PureBasic 5.41 LTS | Xubuntu 16.04 (x32) | Windows 7 (x64)
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

Re: WaitWindowEvent throws Minimize event after Systray even

Post 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))
    
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: WaitWindowEvent throws Minimize event after Systray even

Post 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

Egypt my love
User avatar
Frarth
Enthusiast
Enthusiast
Posts: 241
Joined: Tue Jul 21, 2009 11:11 am
Location: On the planet
Contact:

Re: WaitWindowEvent throws Minimize event after Systray even

Post by Frarth »

Thanks Rashad.
PureBasic 5.41 LTS | Xubuntu 16.04 (x32) | Windows 7 (x64)
Post Reply