|
-
Dec 12th, 2007, 11:28 AM
#1
Thread Starter
Junior Member
Get All Open windows
Is it possible to use the windows api to get a list of all windows that are currently open ? I want to be able to run a function that gets a list of all open windows and depending on which are open I then call seperate routines. I would need to be able to check if there were windows or popups. Any help would be appreciated.
-
Dec 12th, 2007, 12:43 PM
#2
Re: Get All Open windows
Are you talking about a Task Manager type of list?
What development language are you using?
-
Dec 12th, 2007, 02:42 PM
#3
Lively Member
Re: Get All Open windows
See "Creating a task list" here: http://vb.mvps.org/articles/ap199902.pdf
After that see "Obtaining the alt-tab order" here: http://vb.mvps.org/articles/ap200003.asp
-
Dec 12th, 2007, 11:56 PM
#4
Re: Get All Open windows
For just the windows, and not the process itself, you could use the GetWindow function with the constants that have the prefix GW_.
Use AnyPopup to determine if a popup window exists anywhere on the screen.
Use GetLastActivePopup to obtain the handle of the most recently used popup window for a given parent window. returns a handle to most recently used popup window.
Use ShowOwnedPopups to show or hide all popup windows owned by the specified window.
If you need a demo, I can whip one up for ya.
-
Dec 13th, 2007, 04:30 AM
#5
Thread Starter
Junior Member
Re: Get All Open windows
I am using VBScript. I don't need the list of processes from the task manager just what windows are currently open. I am very new to using winapi and would appreciate it if anyone could point me to some code examples. Thanks for the suggestions so far.
-
Dec 13th, 2007, 06:25 AM
#6
Re: Get All Open windows
I wrote up a demo in VB.NET 2005 as close to vbscriptious as I could get.
This makes a list of the open programs that have a title.
You can check for popups in here if you want.
Code:
Const GW_HWNDNEXT As Integer = 2
Private Declare Function apiGetWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Integer, ByVal wCmd As Integer) As Integer
Private Declare Function apiGetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer
Private Declare Function apiGetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Integer) As Integer
Private Declare Function apiGetTopWindow Lib "user32" Alias "GetTopWindow" (ByVal hwnd As Integer) As Integer
Private Declare Function apiGetDesktopWindow Lib "user32" Alias "GetDesktopWindow" () As Integer
Private Declare Function apiShowOwnedPopups Lib "user32" Alias "ShowOwnedPopups" (ByVal hWnd As Integer, ByVal fShow As Integer) As Integer
Private Declare Function apiAnyPopup Lib "user32" Alias "AnyPopup" () As Integer
Private Declare Function apiGetLastActivePopup Lib "user32" Alias "GetLastActivePopup" (ByVal hWndOwnder As Integer) As Integer 'Obtains the handle of the most recently used popup window for a given parent window. returns a Handle to most recently used popup window. hWndOwner if no popup was found.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show(GetWindows())
End Sub
Private Function GetWindows() As String
On Error Resume Next
Dim hwnd As Integer
Dim s1 As String
Dim s2 As String
hwnd = apiGetTopWindow(apiGetDesktopWindow)
s1 = ""
s2 = ""
Do
s2 = GetWindowName(hwnd)
If s2 = "AppTitle" Then
'Do Something here
End If
s1 = s1 & " - " & s2
hwnd = apiGetWindow(hwnd, GW_HWNDNEXT)
If hwnd = 0 Then
GetWindows = s1
Exit Do
End If
Loop
End Function
Public Function GetWindowName(ByVal hWnd As Integer) As String
On Error Resume Next
Dim tLength As Integer
Dim rValue As Integer
Dim wName As String
tLength = apiGetWindowTextLength(hWnd) + 4
wName = ""
wName = wName.PadLeft(tLength) 'add buffer
rValue = apiGetWindowText(hWnd, wName, tLength)
wName = wName.Substring(0, rValue) 'strip buffer
GetWindowName = wName
End Function
-
Dec 13th, 2007, 06:30 AM
#7
Re: Get All Open windows
You can't call native API functions from VBScript.
-
Dec 13th, 2007, 06:42 AM
#8
Re: Get All Open windows
You could have your vbscript run a VB 6 executable that would call the API calls like TTn posted.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 13th, 2007, 06:44 AM
#9
Re: Get All Open windows
Or a COM DLL, but both would dramatically reduce the portability of the script, which is the main reason one would use VBScript in the first place.
The language and the task are simply incompatible. Use something else if at all possible.
-
Dec 13th, 2007, 06:45 AM
#10
Re: Get All Open windows
I know but he said he's very new to the windows API, so I figured I'd write it as vbscriptious as possible so he'd be able to read it.
Maybe he is using vbscript.
-
Dec 13th, 2007, 06:47 AM
#11
Re: Get All Open windows
From post #5:
 Originally Posted by Railay29
I am using VBScript.
-
Dec 13th, 2007, 06:52 AM
#12
Re: Get All Open windows
Yes but,
In post one:
Is it possible to use the windows api..
In post 5:
I am very new to using winapi...
Either way it should help him
-
Dec 13th, 2007, 08:04 AM
#13
Re: Get All Open windows
Not if he is using VBScript.
Would you be trying to run this from a web page?
-
Dec 13th, 2007, 08:07 AM
#14
Re: Get All Open windows
Either running vbscript in a webpage or some other source, the best solution would be to use VB 6 code in a dll or exe file and call from vbscript.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 14th, 2007, 04:10 AM
#15
Thread Starter
Junior Member
Re: Get All Open windows
Hi all and thanks for all the help. Just to add some detail to what I am doing, I am using an automation tool called Quick Test Professional which uses VBScript as its coding language. I working on automating the actions of a browser based application and unfortunately the tool doesn't pick up which browsers are open particularly well. Thats why I thought I could use a winapi call to get the open windows so that I can then interact with them.
-
Dec 14th, 2007, 01:56 PM
#16
Re: Get All Open windows
Maybe you could use VB 6 executable to find the browser you need and set it as the active window. Then in vbscript maybe their function will pickup the active browser window first?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
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
|