Solved

Listing all top-level windows

Posted on 1998-05-31
2
154 Views
Last Modified: 2012-08-13
I need to put all top-level windows into a listbox in VB5, Pro.

I do not want to use custom controls, and need VB5 source code!  And, please don't refer me to other sources!  I have looked at them all and am still confused.  What I want is source code.
0
Comment
Question by:travisstar
2 Comments
 
LVL 1

Expert Comment

by:Cardo
Comment Utility
The handles or titles?

All the top level windows?? Or just the running applications?

Cardo.
0
 
LVL 4

Accepted Solution

by:
yowkee earned 200 total points
Comment Utility
Here's a example to put all top level windows' text(caption) and their classname to listbox:

In a standard module, declare the needed win32 api and enumwindowproc function for api EnumWindows:
--
Declare Function EnumWindows Lib "user32" _
(ByVal lpEnumFunc As Long, _
 ByVal lParam As Long) As Long
 
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long

' EnumWinProc is a CALLBACK function which use by EnumWindows or
' EnumDesktopWindows
Function EnumWinProc(ByVal hWnd As Long, lParam As Long) As Long
    Dim sCaption As String
    Dim sClass As String
    Dim lRtn As Long
   
    sCaption = String(255, " ")
    sClass = String(255, " ")
   
    lRtn = GetWindowText(hWnd, sCaption, 255)
    If lRtn > 0 Then
        sCaption = Left$(sCaption, lRtn)
    End If
   
    lRtn = GetClassName(hWnd, sClass, 255)
    If lRtn > 0 Then
        sClass = Left$(sClass, lRtn)
    End If
   
    Form1.List1.AddItem "Caption: " + sCaption
    Form1.List1.AddItem "Class: " + sClass
    Form1.List1.AddItem "--------------"
    EnumWinProc = True
End Function


In Form1, put a command button(command1) and a list box(list1):
--

Private Sub Command1_Click()
    Dim lRtn As Long
    'EnumWindows will enum all top level windows, and
    'pass the hwnd of the window to callback function
    'EnumWinProc
    lRtn = EnumWindows(AddressOf EnumWinProc, 0)
End Sub
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

728 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

9 Experts available now in Live!

Get 1:1 Help Now