Solved

Get handle to "clock window" in system tray

Posted on 2004-10-28
1,752 Views
Last Modified: 2008-01-09
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
'----------------------------------------------
0
Question by:dbrckovi
    6 Comments
     
    LVL 16

    Expert Comment

    by:jimbobmcgee
    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
     
    LVL 6

    Expert Comment

    by:Amritpal Singh
    0
     
    LVL 11

    Author Comment

    by:dbrckovi
    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
     
    LVL 11

    Author Comment

    by:dbrckovi
    >> 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
     
    LVL 26

    Accepted Solution

    by:
    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
     
    LVL 11

    Author Comment

    by:dbrckovi
    Thanks!
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Shellfire Box VPN + Lifetime Subscription

    The Shellfire Box easily connects all of your devices, even those that don't offer the possibility to establish a safe vpn connection. Access blocked content and surf safely, no matter where in the world you are located.

    Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    933 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now