Page 1 of 1
Issue with custom systray clock
Posted: Sun Jan 01, 2017 3:04 pm
by firace
Happy New Year!
I'm fooling around with the below systray clock code (on Windows 10) and it's working fine, except for a little bug: at the start of every minute, the standard Windows clock briefly appears instead of my custom display. What would be a quick way to solve that?
Code: Select all
hwnd = FindWindow_("Shell_TrayWnd",#Null)
hwnd = FindWindowEx_(hwnd,#Null,"TrayNotifyWnd",#Null)
hwnd = FindWindowEx_(hwnd,#Null,"TrayClockWClass",#Null)
GetWindowRect_(hwnd,@Rect.rect)
Window_Width = Rect\right - Rect\left
Window_Height = Rect\bottom - Rect\Top - 4
OpenWindow(0,0,2,Window_Width,Window_Height+10,"Clock",#PB_Window_BorderLess)
; StickyWindow(0,1)
TextGadget(1,1,1,Window_Width,Window_Height,"")
SetParent_(WindowID(0),hwnd)
SetTimer_(WindowID(0), 0, 300, 0)
Repeat
Select WaitWindowEvent()
Case #WM_TIMER : SetGadgetText(1, "> "+ Hour(date()) +":" + Minute(date()) + ":" + second(date()))
EndSelect
Forever
Re: Issue with custom systray clock
Posted: Sun Jan 01, 2017 3:35 pm
by Lunasole
Hi, I like stuff you playing with
firace wrote:What would be a quick way to solve that?
Maybe just disabling original clock window will help (at least here I've checked and it worked nice without blinking, etc):
Code: Select all
EnableExplicit
Define hwnd = FindWindow_("Shell_TrayWnd",#Null)
Define hwnd2 = FindWindowEx_(hwnd,#Null,"TrayNotifyWnd",#Null)
hwnd = FindWindowEx_(hwnd2,#Null,"TrayClockWClass",#Null)
Define Rect.RECT
GetWindowRect_(hwnd, @Rect)
Define Window_Width = Rect\right - Rect\left
Define Window_Height = Rect\bottom - Rect\Top - 4
OpenWindow(0,0,0,Window_Width,Window_Height+10,"Clock",#PB_Window_BorderLess)
TextGadget(1,1,1,Window_Width,Window_Height,"")
SetParent_(WindowID(0),hwnd)
EnableWindow_(hwnd, #False)
SetTimer_(WindowID(0), 0, 300, 0)
Repeat
Define E = WaitWindowEvent()
Select E
Case #WM_TIMER:
SetGadgetText(1, "> "+ Hour(Date()) +":" + Minute(Date()) + ":" + Second(Date()))
; quit by pressing escape
If GetAsyncKeyState_(#VK_ESCAPE)
Break
EndIf
EndSelect
ForEver
EnableWindow_(hwnd, #True)
End
Re: Issue with custom systray clock
Posted: Sun Jan 01, 2017 4:48 pm
by firace
Glad you like that.
But unfortunately your version doesn't fix it here.

This is under a standard Win 10 x64 installation. I will try on a Win 8.1 machine later.
Re: Issue with custom systray clock
Posted: Sun Jan 01, 2017 5:05 pm
by RASHAD
Re: Issue with custom systray clock
Posted: Sun Jan 01, 2017 5:19 pm
by firace
RASHAD wrote:Replace
With
Nope, that just completely blanks out the clock area for me.

BTW, same result on Win 8.1 x86.
Just to clarify (if needed), the issue appears only when a new minute starts (ie, when seconds = 0)
Re: Issue with custom systray clock
Posted: Sun Jan 01, 2017 5:23 pm
by Lunasole
firace wrote:
This is under a standard Win 10 x64 installation. I will try on a Win 8.1 machine later.
Well if it doesn't help on 10, probably 8 will be the same. I was trying on XP only
I also tried that, It's not a solution while using SetParent_(WindowID(0),hwnd).
Maybe if using SetParent_(WindowID(0),hwnd2) [following that my code], then something can be done this way
Re: Issue with custom systray clock
Posted: Sun Jan 01, 2017 5:45 pm
by firace
I just found a much quicker way to reproduce the problem without having to wait for a new minute to start:
Just press Win+D a couple of times (minimize all / unminimize all) to see it.
Re: Issue with custom systray clock
Posted: Sun Jan 01, 2017 6:05 pm
by GJ-68
This one works on Win7 x64:
Code: Select all
EnableExplicit
Define hwnd = FindWindow_("Shell_TrayWnd",#Null)
Define hwnd2 = FindWindowEx_(hwnd,#Null,"TrayNotifyWnd",#Null)
hwnd = FindWindowEx_(hwnd2,#Null,"TrayClockWClass",#Null)
Define Rect.RECT, Rect2.RECT
GetWindowRect_(hwnd, @Rect)
GetWindowRect_(hwnd2, @Rect2)
Define Window_Width = Rect\right - Rect\left
Define Window_Height = Rect\bottom - Rect\Top - 4
OpenWindow(0,Rect\left - Rect2\left,0,Window_Width,Window_Height+10,"Clock",#PB_Window_BorderLess)
TextGadget(1,1,1,Window_Width,Window_Height,"")
SetParent_(WindowID(0),hwnd2)
ShowWindow_(hwnd,#SW_HIDE)
;EnableWindow_(hwnd, #False)
SetTimer_(WindowID(0), 0, 300, 0)
Repeat
Define E = WaitWindowEvent()
Select E
Case #WM_TIMER:
SetGadgetText(1, "> "+ Hour(Date()) +":" + Minute(Date()) + ":" + Second(Date()))
; quit by pressing escape
If GetAsyncKeyState_(#VK_ESCAPE)
Break
EndIf
EndSelect
ForEver
ShowWindow_(hwnd,#SW_SHOW)
;EnableWindow_(hwnd, #True)
End
Re: Issue with custom systray clock
Posted: Sun Jan 01, 2017 6:10 pm
by firace
@GJ-68 Yes! This one looks perfect on Win 10 too
Thanks everyone!!!
Re: Issue with custom systray clock
Posted: Sun Jan 01, 2017 6:17 pm
by infratec
Only as an additional tip:
Code: Select all
SetGadgetText(1, FormatDate("> %hh:%ii:%ss", Date()))
Bernd
Re: Issue with custom systray clock
Posted: Sun Jan 01, 2017 7:53 pm
by firace
Argggh! Another issue popped up I'm afraid. If another application adds or removes a systray icon while my code is running, the system clock disappears and positioning gets messed up... Is there some kind of systray change notification I should listen to and trigger a refresh somehow?
Re: Issue with custom systray clock
Posted: Sun Jan 01, 2017 8:08 pm
by RASHAD
Try
Code: Select all
;EnableExplicit
hwnd = FindWindow_("Shell_TrayWnd",#Null)
hwnd = FindWindowEx_(hwnd,#Null,"TrayNotifyWnd",#Null)
hwnd = FindWindowEx_(hwnd,#Null,"TrayClockWClass",#Null)
GetWindowRect_(hwnd, @Rect.RECT)
Window_Width = Rect\right - Rect\left
Window_Height = Rect\bottom - Rect\Top - 4
LoadFont(0,"Georgia",12)
LoadFont(1,"Tahoma",8)
OpenWindow(0,Rect\right-60,Rect\Top+2,60,Window_Height,"Clock",#PB_Window_BorderLess)
StickyWindow(0,1)
TextGadget(1,1,1,60,Window_Height/2-2,"",#SS_CENTER|#SS_CENTERIMAGE)
SetGadgetFont(1,FontID(0))
TextGadget(2,1,Window_Height/2,60,Window_Height/2,"",#SS_CENTER|#SS_CENTERIMAGE)
SetGadgetFont(2,FontID(1))
;SetParent_(WindowID(0),hwnd2)
ShowWindow_(hwnd,#SW_HIDE)
;EnableWindow_(hwnd, #False)
SetTimer_(WindowID(0), 0, 300, 0)
Repeat
Define E = WaitWindowEvent()
Select E
Case #WM_TIMER:
SetGadgetText(1, RSet(""+ Hour(Date()),2,"0") +":" + RSet(""+Minute(Date()),2,"0"))
SetGadgetText(2, RSet(""+ Second(Date()),2,"0"))
; quit by pressing escape
If GetAsyncKeyState_(#VK_ESCAPE)
Break
EndIf
EndSelect
ForEver
ShowWindow_(hwnd,#SW_SHOW)
;EnableWindow_(hwnd, #True)
End
Re: Issue with custom systray clock
Posted: Sun Jan 01, 2017 10:12 pm
by firace
RASHAD wrote:...
No luck I'm afraid. See:

Re: Issue with custom systray clock
Posted: Sun Jan 01, 2017 10:50 pm
by RASHAD
This snippet should be OK
Code: Select all
;EnableExplicit
hwnd = FindWindow_("Shell_TrayWnd",#Null)
hwnd = FindWindowEx_(hwnd,#Null,"TrayNotifyWnd",#Null)
hwnd = FindWindowEx_(hwnd,#Null,"TrayClockWClass",#Null)
GetWindowRect_(hwnd, @Rect.RECT)
Window_Width = Rect\right - Rect\left
Window_Height = Rect\bottom - Rect\Top
LoadFont(0,"Georgia",12)
LoadFont(1,"Tahoma",8)
IconName$ = #PB_Compiler_Home+"examples\sources\data\CdPlayer.ico"
OpenWindow(0,Rect\right-62,Rect\Top+2,64,Window_Height,"Clock",#PB_Window_BorderLess,hwnd)
;StickyWindow(0,1)
TextGadget(1,1,1,60,Window_Height/2,"",#SS_CENTER|#SS_CENTERIMAGE)
SetGadgetFont(1,FontID(0))
TextGadget(2,1,Window_Height/2,60,Window_Height/2,"",#SS_CENTER|#SS_CENTERIMAGE)
SetGadgetFont(2,FontID(1))
SetTimer_(WindowID(0), 0, 300, 0)
AddSysTrayIcon(0, WindowID(0), LoadImage(0,IconName$))
Repeat
Define E = WaitWindowEvent()
Select E
Case #PB_Event_SysTray
If EventType() = #PB_EventType_LeftDoubleClick
RemoveSysTrayIcon(0)
EndIf
Case #WM_TIMER:
SetGadgetText(1, RSet(""+ Hour(Date()),2,"0") +":" + RSet(""+Minute(Date()),2,"0"))
SetGadgetText(2, RSet(""+ Second(Date()),2,"0"))
; quit by pressing escape
If GetAsyncKeyState_(#VK_ESCAPE)
Break
EndIf
EndSelect
ForEver
End
Re: Issue with custom systray clock
Posted: Mon Jan 02, 2017 7:18 am
by firace
@RASHAD Clever! Thanks for your help.