Download a free copy of NetMon - Your Internet Performance Monitor at http://www.codeoftheweek.com/netmon/index.html
Subscribe to Code of the Week for only $14.95 (regularly $19.95). Just jump to our SECRET order page at http://www.codeoftheweek.com/orderforms/annual1495.html
In this issue we are introducing a class module that shows an how to retrieve some window information, such as the class name and caption.
This source code is designed for VB 4.0 32-bit and up. Questions? Email us at email@example.com.
The cWindowInfo class provides an easy way to gather some important information about a window.
If you have any questions about using or creating this control, let us know at firstname.lastname@example.org
Public Property Let Handle(lHandle As Long) Public Property Get Handle() As Long
Every window has a unique handle that identifies it. When you set this property is causes the class to gather all the information it can about the window.
Public Caption As String
The caption of the window specified by Handle.
Public ClassName As String
The class name of the window specified by Handle. A class name is used to create all windows. Finding the class name is sometimes useful for the FindWindow call.
Public Style As Long
The style bits of the window specified by Handle.
Public IDNumber As Long
The id number of the window specified by Handle.
Public ParentHandle As Long
The handle of the parent window. You can use this handle to retrieve additional information about the parent window by creating another instance of this class and setting the Handle property.
Public Function WindowByMouse() As Boolean
Retrieves the handle that is located under the mouse pointer. It returns True is the window below the cursor is different than the last time this function was called. It returns False when the same window is below the cursor as the last call. This is useful to put into a timer function (see the sample code below).
No return values in this class except for the WindowByMouse method (see above).
The below sample describes how to use the cWindowInfo class. It assumes you have a form with a Timer control called tmrMouse.
Dim WinInfo As New cWindowInfo Dim ParentWin As New cWindowInfo Sub tmrMouse_Timer() If WinInfo.WindowByMouse Then Cls Print "Window Handle: &H"; Hex(WinInfo.Handle) Print "Window Text: "; WinInfo.Caption Print "Window Class Name: "; WinInfo.ClassName Print "Window Style: &H"; Hex(WinInfo.Style) ParentWin.Handle = WinInfo.ParentHandle If ParentWin.Handle <> 0 Then Print "Parent Window Handle: &H"; Hex(WinInfo.ParentHandle) Print "Window ID Number: &H"; Hex(WinInfo.IDNumber) Print "Parent Window Text: " & ParentWin.Caption Print "Parent Window Class Name: "; ParentWin.ClassName Else Print "Window ID Number: N/A" Print "Parent Window Handle: N/A" Print "Parent Window Text : N/A" Print "Parent Window Class Name: N/A" End If End If End Sub
To see the source code for this issue you must be a subscriber to Code of the Week. If you are a subscriber the source code is available at the following address: http://www.codeoftheweek.com/membersonly/bi/0075.html