Get handle to "clock window" in system tray

Hi!

Why can't I get the window handle to clock window. (lower left corner of the desktop where clock is displayed)

Spy++ can get all information of that window like with any other window, but FindWindow API can't find it. Why?
Is the re some other way to get that handle using VB6?

'---------------------------------------------
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Sub Command1_Click()
    Dim ClockHandle As Long
    'ClockHandle = FindWindow("TrayClockWClass", Hour(Now) & ":" & Minute(Now))
    MsgBox ClockHandle
End Sub
'----------------------------------------------
LVL 11
dbrckoviAsked:
Who is Participating?
 
EDDYKTCommented:
Option Explicit
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Sub Command1_Click()
  Dim hwnd As Long

  hwnd = FindWindowEx(FindWindowEx(FindWindow("Shell_TrayWnd", vbNullString), 0, "TrayNotifyWnd", vbNullString), 0, "TrayClockWClass", vbNullString)
Call ShowWindow(hwnd, 0)

End Sub

Private Sub Command2_Click()
Dim hwnd As Long
hwnd = FindWindowEx(FindWindowEx(FindWindow("Shell_TrayWnd", vbNullString), 0, "TrayNotifyWnd", vbNullString), 0, "TrayClockWClass", vbNullString)
Call ShowWindow(hwnd, 5)
End Sub
0
 
jimbobmcgeeCommented:
It may be because the clock window has no title -- I imagine Hour(Now) & ":" & Minute(Now) is window content.

What happens if you do not specify Hour(Now) & ":" & Minute(Now)?

J.
0
 
Amritpal SinghCommented:
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
dbrckoviAuthor Commented:
Same thing happens. It returns 0.

Spy++ gets "12:55" as window caption, which is exactly what    Hour(Now) & ":" & Minute(Now)     returns.    (Assuming that the time is 12:55)
When I use caption value returned by Spy++ as second parametert in FindWindow function, it works with any other window, except few windows in the tray.

According to http://www.mentalis.org/apilist/FindWindow.shtml,  If I set this value to Null, all window names should match, but the following also returns 0:
ClockHandle = FindWindow("TrayClockWClass", vbNullString)
0
 
dbrckoviAuthor Commented:
>> http://www.codeproject.com/shell/trayposition.asp
I know how to find tray window. Tray is one of the windows that can be found without problems. And after I find it, I can draw on it, but stuff I draw there are drawn behind the clock window.
That's why I need a handle to the clock window, so I can draw on it.

>> http://support.microsoft.com/kb/q88167/
It shows 3 ways to find some window, but none of these ways work with clock window.

I wouldn't bother with that if I was not sure it is possible, but since Spy++ can do it, then I assume there must be a way in VB6 to do it too?
0
 
dbrckoviAuthor Commented:
Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.