Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Listing all top-level windows

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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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

824 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