Results 1 to 7 of 7

Thread: GetWindowClass?

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Location
    Mpls, MN
    Posts
    8

    GetWindowClass?

    I was wondering if someone would be so kind as to help me out with some code using GetWindowClass (or whatever it may be) to get the name of all the windows currently open. I'm actually using Visual Basic in Excel 2000 because I'm at work, but I should be able to ajust any code as necessary... Thanks!

    Also, I considered downloading and using one of those programs that give you the title/class/handle/etc when the Mouse is over the window, but I can't run exectuables on these comptures...

    Thanks everyone for your assistance!

  2. #2
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    To get a list of all open windows, use the EnumWindows function.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    If you are after a list of open processes, try this
    VB Code:
    1. 'in a module
    2. Public Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
    3. Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    4. Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    5. Public Const MAX_LEN = 260
    6.  
    7. Public Function EnumWinProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
    8.     Dim lRet As Long
    9.     Dim strBuffer As String
    10.    
    11.     If IsWindowVisible(hwnd) Then
    12.         strBuffer = Space(MAX_LEN)
    13.         lRet = GetWindowText(hwnd, strBuffer, Len(strBuffer))
    14.         If lRet Then
    15.             Form1.List1.AddItem Left(strBuffer & "  " & hwnd, lRet)
    16.         End If
    17.     End If
    18.    
    19.     EnumWinProc = 1
    20. End Function
    21.  
    22. 'on a form with a listbox and command button
    23. Private Sub cmdListProcesses_Click()
    24. Call EnumWindows(AddressOf EnumWinProc, 0)
    25. End Sub
    I've never done any development in Excel, so I don't know if this will work on that platform, but it works just fine using VB.

  4. #4

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Location
    Mpls, MN
    Posts
    8
    Thanks Hack, that works great in Excel. However I am not only looking for the title of open windows, but the class-name as well... I'm going to try and modify this code a bit, but is there a way to add to this to get the class name too? Thanks again for your help!

  5. #5
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    Using EnumWindows as they previously said, all you'd have to do use use GetClassName() inside the EnumWindowsProc(), which is the user defined callback you make for EnumWindows(). In Hack's example it's EnumWinProc().
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

  6. #6
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    I have some code that does this, but it's on my home PC (I'm at work right now). I'll post when I get home.

  7. #7
    Addicted Member
    Join Date
    Sep 2000
    Location
    London, UK
    Posts
    137

    Question useful but......

    I'm playing with Hacks code above and have a question based on it.

    The GetWindowText returns the window name as well as the name of the active file open in it 'Microsoft Excel - Book3' & the hwnd'

    I'm only trying to capture the App name and hwnd how would I be able to do this...

    Not used these api's before and need a bit of direction....

    Many thanks,
    Rocks
    join me in the platinum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width