|
-
Sep 30th, 2002, 03:31 PM
#1
Thread Starter
New Member
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!
-
Oct 1st, 2002, 09:12 AM
#2
Software Eng.
To get a list of all open windows, use the EnumWindows function.
-
Oct 1st, 2002, 09:33 AM
#3
If you are after a list of open processes, try this
VB Code:
'in a module
Public Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Const MAX_LEN = 260
Public Function EnumWinProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim lRet As Long
Dim strBuffer As String
If IsWindowVisible(hwnd) Then
strBuffer = Space(MAX_LEN)
lRet = GetWindowText(hwnd, strBuffer, Len(strBuffer))
If lRet Then
Form1.List1.AddItem Left(strBuffer & " " & hwnd, lRet)
End If
End If
EnumWinProc = 1
End Function
'on a form with a listbox and command button
Private Sub cmdListProcesses_Click()
Call EnumWindows(AddressOf EnumWinProc, 0)
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.
-
Oct 2nd, 2002, 07:35 PM
#4
Thread Starter
New Member
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!
-
Oct 2nd, 2002, 10:42 PM
#5
Fanatic Member
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 
-
Oct 3rd, 2002, 08:52 AM
#6
Software Eng.
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.
-
Nov 28th, 2002, 05:40 AM
#7
Addicted Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|