Solved

Listing all top-level windows

Posted on 1998-05-31
2
159 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
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

770 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