Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Get the list of applications which are running

How to use (for example, Windows API) to obtain a list of the applications which are running? (I need a list of file names.

Thank you very much in advance

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Get the list of applications which are running

I forgot where I obtained this code so I'm unable to
acknowledge its author (my apologies to whomever)



Private Declare Function GetWindow Lib "user32" (ByVal
hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" ()
As Long
Private Declare Function GetWindowLW Lib "user32"
Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex
As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal
hwnd As Long) As Long
Private Declare Function GetClassName Lib "user32"
Alias "GetClassNameA" (ByVal hwnd As Long, ByVal
lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetWindowText Lib "user32"
Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString
As String, ByVal cch As Long) As Long

Private Declare Function ShowWindow32 Lib "user32"
Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As
Long) As Long
Private Declare Function SetForegroundWindow32
Lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As
Long) As Long

Private Const GWL_ID = (-12)
Private Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5



'FindWindowLike
' - Finds the window handles of the windows matching
the specified
' parameters
'
'hwndArray()
' - An integer array used to return the window handles
'
'hWndStart
' - The handle of the window to search under.
' - The routine searches through all of this window's
children and their
' children recursively.
' - If hWndStart = 0 then the routine searches through
all windows.
'
'WindowText
' - The pattern used with the Like operator to compare
window's text.
'
'ClassName
' - The pattern used with the Like operator to compare
window's class
' name.
'
'ID
' - A child ID number used to identify a window.
' - Can be a decimal number or a hex string.
' - Prefix hex strings with "&H" or an error will occur.
' - To ignore the ID pass the Visual Basic Null
function.
'
'Returns
' - The number of windows that matched the parameters.
' - Also returns the window handles in hWndArray()
'
'-------------------------------------------------------
---------------
Private Function FindWindowLike(hWndArray() As Long, ByVal
hWndStart As Long, _
WindowText As String, Classname As String, ID) As Long
Dim hwnd As Long
Dim r As Long
' Hold the level of recursion:
Static level As Long
' Hold the number of matching windows:
Static iFound As Long
Dim sWindowText As String
Dim sClassname As String
Dim sID

' Initialize if necessary:
If level = 0 Then
iFound = 0
ReDim hWndArray(0 To 0)
If hWndStart = 0 Then hWndStart = GetDesktopWindow
()
End If
' Increase recursion counter:
level = level + 1
' Get first child window:
hwnd = GetWindow(hWndStart, GW_CHILD)
Do While hwnd < 0
DoEvents ' Not necessary

' Search children by recursion:
r = FindWindowLike(hWndArray(), hwnd, WindowText,
Classname, ID)
' Get the window text and class name:
sWindowText = Space(255)
r = GetWindowText(hwnd, sWindowText, 255)
sWindowText = Left(sWindowText, r)
sClassname = Space(255)
r = GetClassName(hwnd, sClassname, 255)
sClassname = Left(sClassname, r)
' If window is a child get the ID:
If GetParent(hwnd) < 0 Then
r = GetWindowLW(hwnd, GWL_ID)
sID = CLng("&H" & Hex(r))
Else
sID = Null
End If
' Check that window matches the search parameters:
If sWindowText Like WindowText And sClassname Like
Classname Then
If IsNull(ID) Then
' If find a match, increment counter and
' add handle to array:
iFound = iFound + 1
ReDim Preserve hWndArray(0 To iFound)
hWndArray(iFound) = hwnd
ElseIf Not IsNull(sID) Then
If CLng(sID) = CLng(ID) Then
' If find a match increment counter and
' add handle to array:
iFound = iFound + 1
ReDim Preserve hWndArray(0 To iFound)
hWndArray(iFound) = hwnd
End If
End If
' Debug.Print "Window Found: "
' Debug.Print " Window Text : " & sWindowText
' Debug.Print " Window Class : " & sClassname
' Debug.Print " Window Handle: " & CStr(hwnd)
End If
' Get next child window:
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
Loop
' Decrement recursion counter:
level = level - 1
' Return the number of windows found:
FindWindowLike = iFound
End Function


Kevin Beckham

-----Original Message-----
How to use (for example, Windows API) to obtain a list of

the applications which are running? (I need a list of file
names.)

Thank you very much in advance!

.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
keeping a running list [email protected] Excel Discussion (Misc queries) 5 February 26th 08 11:12 PM
Subtotaling by date in a running list Jeff S New Users to Excel 2 January 18th 08 05:09 PM
running a macro from a list rufusf Excel Worksheet Functions 0 February 22nd 06 04:38 PM
Workbooks in multiple running Excel applications wbl Excel Programming 3 January 5th 04 02:47 PM
Running other applications from Excel VB Mervyn Thomas[_3_] Excel Programming 0 September 8th 03 05:36 PM


All times are GMT +1. The time now is 03:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"