[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Get handle to "clock window" in system tray

Posted on 2004-10-28
6
Medium Priority
?
1,778 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
Comment
Question by:dbrckovi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 16

Expert Comment

by:jimbobmcgee
ID: 12432023
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
ID: 12432159
0
 
LVL 11

Author Comment

by:dbrckovi
ID: 12432220
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Author Comment

by:dbrckovi
ID: 12432280
>> 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:
EDDYKT earned 800 total points
ID: 12432673
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
ID: 12432730
Thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…
Suggested Courses

650 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