How can I force the window to have focus? (also restoring from code (I use a timer in the example) doesn't give it focus)
Code: Select all
Enumeration
#Image0
EndEnumeration
If OpenWindow(0, 100, 150, 300, 100, "SysTray Example", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget)
TrayIcon = CatchImage(0, ?TrayIcon)
If CreatePopupImageMenu(0)
MenuItem(1, "Restore",TrayIcon)
MenuItem(2, "Close")
EndIf
Repeat
Event = WaitWindowEvent(1000)
Select Event
Case #PB_Event_Timer
Select EventTimer()
Case 1
RemoveWindowTimer(0,1)
PostEvent(#PB_Event_Menu,0,1)
EndSelect
Case #PB_Event_Menu
Select EventMenu()
Case 1
ShowWindow_(WindowID(0),#SW_RESTORE)
RemoveSysTrayIcon(0)
HideWindow(0,#False)
; Required for "double click"
; but doesn't get focus...
StickyWindow(0,#True)
SetActiveWindow(0)
StickyWindow(0,#False)
Case 2
PostEvent(#PB_Event_CloseWindow)
EndSelect
Case #PB_Event_SysTray
Select EventType()
Case #PB_EventType_RightClick
DisplayPopupMenu(0, WindowID(0))
Case #PB_EventType_LeftDoubleClick
PostEvent(#PB_Event_Menu,0,1)
EndSelect
Case #PB_Event_MinimizeWindow
HideWindow(0,#True )
AddSysTrayIcon(0, WindowID(0), TrayIcon)
SysTrayIconToolTip(0, "DBL click or right click to restore")
AddWindowTimer(0,1, 10000)
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
DataSection
TrayIcon:
IncludeBinary #PB_Compiler_Home+"\Examples\Sources - Advanced\MoviePlayer\Icons\Play.ico"
EndDataSection

