Solved

Listing all top-level windows

Posted on 1998-05-31
2
162 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
[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
2 Comments
 
LVL 1

Expert Comment

by:Cardo
ID: 1462150
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
ID: 1462151
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

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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
Course of the Month7 days, 17 hours left to enroll

617 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