While trying to use the FindWindow (and FindWindowEx) APIs to get the hWnd for the SysTray clock, I ran into a problem. The original (and, for some strange reason, non-working) code is:
VB Code:
  1. Dim tmpWnd&
  2. tmpWnd = FindWindow("Shell_TrayWnd", "") 'Task bar
  3. tmpWnd = FindWindowEx(tmpWnd, 0&, "TrayNotifyWnd", "") 'System tray
  4. trayClock = FindWindowEx(tmpWnd, 0&, "TrayClockWClass", "") 'System tray clock
However, when I added to it to look like the following:
VB Code:
  1. Dim tmpWnd&, clsName As String * 100, clsLen&
  2. tmpWnd = FindWindow("Shell_TrayWnd", "") 'Task bar
  3. tmpWnd = FindWindowEx(tmpWnd, 0&, "TrayNotifyWnd", "") 'System tray
  4. trayClock = FindWindowEx(tmpWnd, 0&, "TrayClockWClass", "") 'System tray clock
  5. If trayClock = 0 Then
  6.     tmpWnd = GetWindow(tmpWnd, GW_CHILD)
  7.     Do While tmpWnd <> 0
  8.         clsLen = GetClassName(tmpWnd, clsName, 100)
  9.         If Left(clsName, clsLen) = "TrayClockWClass" Then
  10.             trayClock = tmpWnd
  11.             Exit Do
  12.         End If
  13.         tmpWnd = GetWindow(tmpWnd, GW_HWNDNEXT)
  14.     Loop
  15. End If
it works just fine. In fact, the first child of TrayNotifyWnd (the system tray) is the SysTray clock. Any idea why the first didn't work? (P.S. trayClock is a Public variable and I'm 100% positive that the SysTray clock's class name is TrayClockWClass, thanks to a "WindowSpy" example program I have)