Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Listing all top-level windows

Posted on 1998-05-31
2
Medium Priority
?
163 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 400 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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

660 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