Problem using GetFocus/LostFocus on SysTray

Just starting out? Need help? Post your questions and find answers here.
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Problem using GetFocus/LostFocus on SysTray

Post 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 
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

It works fine for me.

Rightclick and leftclick.

cheers
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Post by SkyManager »

The problems are not the left-click and right-click.

The problems are Get Focus and Lost Focus events :!:
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

#PB_EventType_Focus and _LostFocus are only for the StringGadget.
BERESHEIT
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Post by SkyManager »

How can the system tray icon to receive GainFocus and LostFocus events?
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

Maybe "Receiving Mouse events" on

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

cheers
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

You can get mouse movement and mouse clicks but I don't think keyboard focus is an option for a tray icon.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Tomi
Enthusiast
Enthusiast
Posts: 270
Joined: Wed Sep 03, 2008 9:29 am

Post by Tomi »

User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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!
BERESHEIT
Post Reply