Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleGet information about running windows
Keywordsenumerate windows, EnumWindows, window information
CategoriesWindows, Software Engineering
 
Use EnumWindows to list the windows. The program uses the following enumeration callback function to record information about each window.
 
Public Type ProcData
    AppHwnd As Long
    ClassName As String
    Title As String
    Placement As String
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type
Public ProcInfo() As ProcData
Public NumProcs As Integer

Public Function EnumProc(ByVal app_hwnd As Long, ByVal _
    lParam As Long) As Boolean
Const SW_SHOWNORMAL = 1
Const SW_SHOWMINIMIZED = 2
Const SW_SHOWMAXIMIZED = 3

Dim wp As WINDOWPLACEMENT
Dim buf As String * 1024
Dim length As Long

    NumProcs = NumProcs + 1
    ReDim Preserve ProcInfo(1 To NumProcs)
    With ProcInfo(NumProcs)
        .AppHwnd = app_hwnd

        ' Get the window's class name.
        length = GetClassName(app_hwnd, buf, Len(buf))
        .ClassName = Left$(buf, length)

        ' Get the window's title.
        length = GetWindowText(app_hwnd, buf, Len(buf))
        .Title = Left$(buf, length) & " "

        ' See where the window is.
        wp.length = Len(wp)
        GetWindowPlacement app_hwnd, wp
        Select Case wp.showCmd
            Case SW_SHOWNORMAL
                .Placement = "Normal"
            Case SW_SHOWMINIMIZED
                .Placement = "Minimized"
            Case SW_SHOWMAXIMIZED
                .Placement = "Maximized"
        End Select

        .Left = wp.rcNormalPosition.Left
        .Top = wp.rcNormalPosition.Top
        .Right = wp.rcNormalPosition.Right
        .Bottom = wp.rcNormalPosition.Bottom
    End With
    
    ' Continue searching.
    EnumProc = 1
End Function
 
After the enumeration finishes, the main program displays the results in a MSFlexGrid control.
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated