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

x
?
Solved

VB6 - Listing all Windows that are opne on the desktop

Posted on 2006-06-27
8
Medium Priority
?
1,031 Views
Last Modified: 2012-08-13
Does anyone know of a method/api in VB6 that can list all the Windows that are currently open on the Windows desktop?

i.e. Applications, Prpoerty Windows etc etc
0
Comment
Question by:RobertEnglish
[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
  • 3
  • 2
  • 2
  • +1
8 Comments
 

Author Comment

by:RobertEnglish
ID: 16991036
I've tried using the FindWindow API but of the 25 windows/apps it returns 13 return nothing from GetWindowText API
0
 
LVL 5

Assisted Solution

by:lunchbyte
lunchbyte earned 750 total points
ID: 16991648
0
 
LVL 3

Expert Comment

by:fullcontact
ID: 16991902
Here is a nice little project.

http://www.freevbcode.com/source/dFreeze.zip
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 16995145
The best way to do this is to first use API. You will need

OpenDesktop
CloseDesktop
EnumDesktopWindows

First you call OpenDesktop to get a handle to the current desktop, you then pass this handle to the EnumDesktopWindows API. Then you use the EnumWIndowsProc procedure to set up the callback. This is where your window handles will be enumerated.
0
 
LVL 29

Accepted Solution

by:
nffvrxqgrcfqvvc earned 750 total points
ID: 16996797
Here is a simple example I put together


'--------- Module1.bas ----------


Option Explicit

Private Declare Function OpenInputDesktop Lib "user32" ( _
    ByVal dwFlags As Long, _
    ByVal fInherit As Boolean, _
    ByVal dwDesiredAccess As Long) As Long
   
Private Declare Function CloseDesktop Lib "user32" ( _
    ByVal hDesktop As Long) As Long

Private Declare Function EnumDesktopWindows Lib "user32" ( _
    ByVal hDesktop As Long, _
    ByVal lpfn As Long, _
    ByVal lParam As Long) As Long

Private Declare Function GetWindowTextW Lib "user32" ( _
    ByVal hwnd As Long, _
    ByVal lpString As Long, _
    ByVal cch As Long) As Long

Dim hDesk As Long

Private Function WindowCaption(prochWnd As Long) As String
    Dim rLen    As Long
    Dim b(512)  As Byte
    rLen = GetWindowTextW(prochWnd, ByVal VarPtr(b(0)), 512)
        If rLen Then
            WindowCaption = Left$(b, rLen)
        Else
            WindowCaption = vbNullString
        End If
    Erase b
End Function

Public Sub WindowsOnDesktop()
    hDesk = OpenInputDesktop(0, False, 0)
    If hDesk Then
        EnumDesktopWindows hDesk, AddressOf EnumWindowsProc, 0&
        hDesk = CloseDesktop(hDesk)
    End If
End Sub

Public Function EnumWindowsProc( _
    ByVal hwnd As Long, ByVal lParam As Long) As Boolean
   
    Dim Caption As String
   
    Caption = WindowCaption(hwnd)
    If LenB(Caption) Then
        Debug.Print Caption
    End If
   
    'Continue enumeration
    EnumWindowsProc = True

End Function



'------- Form1 -------'

Private Sub Command1_Click()

Call WindowsOnDesktop

End Sub
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 16999422
These answeres weren't good enough for you?
0
 

Author Comment

by:RobertEnglish
ID: 16999458
<< These answeres weren't good enough for you? >>

I've just given out points - so if they haven't been allocated then experts-exhcange is up-the spout
0
 
LVL 5

Expert Comment

by:lunchbyte
ID: 17000277
>><< These answeres weren't good enough for you? >>
>>I've just given out points - so if they haven't been allocated then experts-exhcange is up-the spout

egl1044 meant why B instead of A?
But in any event glad you got the help you need.
0

Featured Post

Industry Leaders: 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

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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

664 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