Page 1 of 1

Problem using GetFocus/LostFocus on SysTray

Posted: Fri Jul 24, 2009 5:08 am
by SkyManager
I am trying to catch the get focus and lost focus event of the system tray icon.

It looks like no response at all.

Is it suppose no such events on system tray at all?

Code: Select all

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

  CompilerIf #PB_Compiler_OS = #PB_OS_Windows
    IconName$ = "Data\CdPlayer.ico"
  CompilerElse
    IconName$ = "Data/Drive.bmp"
  CompilerEndIf
  
  AddSysTrayIcon(1, WindowID(0), LoadImage(0, IconName$))
  SysTrayIconToolTip(1, "Icon 1")
  
  Repeat
    Event = WaitWindowEvent()
    If Event = #PB_Event_SysTray
      If EventType() = #PB_EventType_Focus
        MessageRequester("SysTray", "SysTrayIcon "+Str(EventGadget())+" is gained focused.",0)
      EndIf
      If EventType() = #PB_EventType_LostFocus
        MessageRequester("SysTray", "SysTrayIcon "+Str(EventGadget())+" is lost focused.",0)
      EndIf
      If EventType() = #PB_EventType_LeftDoubleClick
        MessageRequester("SysTray", "Left DoubleClick on SysTrayIcon "+Str(EventGadget()),0)
      EndIf
      If EventType() = #PB_EventType_RightClick
        MessageRequester("SysTray", "RightClick on SysTrayIcon "+Str(EventGadget()),0)        
        ChangeSysTrayIcon (EventGadget(), LoadImage(2, IconName$))
        SysTrayIconToolTip(EventGadget(), "Changed !")
      EndIf
      If EventType() = #PB_EventType_LeftClick
        MessageRequester("SysTray", "LeftClick on SysTrayIcon "+Str(EventGadget()),0)
      EndIf      
    EndIf
  Until Event = #PB_Event_CloseWindow
EndIf 

Posted: Fri Jul 24, 2009 7:28 am
by rsts
It works fine for me.

Rightclick and leftclick.

cheers

Posted: Fri Jul 24, 2009 8:51 am
by SkyManager
The problems are not the left-click and right-click.

The problems are Get Focus and Lost Focus events :!:

Posted: Fri Jul 24, 2009 10:02 am
by netmaestro
#PB_EventType_Focus and _LostFocus are only for the StringGadget.

Posted: Mon Jul 27, 2009 9:31 am
by SkyManager
How can the system tray icon to receive GainFocus and LostFocus events?

Posted: Mon Jul 27, 2009 5:57 pm
by rsts
Maybe "Receiving Mouse events" on

http://msdn.microsoft.com/en-us/library ... S.85).aspx

cheers

Posted: Tue Jul 28, 2009 1:56 am
by Sparkie
You can get mouse movement and mouse clicks but I don't think keyboard focus is an option for a tray icon.

Posted: Sat Aug 01, 2009 4:50 pm
by Tomi

Posted: Sat Aug 01, 2009 11:58 pm
by netmaestro
I guess "focus" is a poor choice of words, as Sparkie points out it relates to keyboard focus. I'm assuming you mean mouse enter and leave, and on that basis I cooked up something here:

http://www.purebasic.fr/english/viewtop ... 270#294270

Maybe it's of some help. If not, it was a fun challenge anyway. Cheers!