gratifiant > microsoft.* > microsoft.vb

yann (07/09/2004, 12h11)
Bonjour,
Est-il possible de savoir si un exe est en cours de
marche?

Merci
le_troll (07/09/2004, 13h25)
Bonjour,

Oui, on peut le savoir, voici:

' Form1
'****************************************
' OBJETS = List1 (Sorted = True) + Text1 = 2 objets
' ***************************************
' form1 tous les handles
'
Private Declare Function GetForegroundWindow Lib "user32" () As Long
'hwnd (handle de la forme)
'
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 EnumWindows Lib "user32" _
(ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
'
Sub Form_Load() ' LIST1 + TEXT1
Dim hwnd
'
List1.Clear
GetWindowsList
'
' handle de cette form
hwnd = GetForegroundWindow
Text1 = "Handle en cours : " & hwnd
End Sub

Private Function EnumWindowsProc(ByVal lgHwnd As Long, ByVal lgParam As
Long) As Long
Dim stTmp As String, lgTmp As Long, lgRet As Long
'
stTmp = Space$(120)
lgTmp = 119
lgRet = GetWindowText(lgHwnd, stTmp, lgTmp)
If Len(stTmp) > 1 And lgRet <> 0 Then
Form1.List1.AddItem Format(lgHwnd, "00000000") & " : " & stTmp
End If
EnumWindowsProc = 1
End Function

'********************
' Module1
'********************
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA"
_
(ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As
Long
'
Public Declare Function EnumWindows Lib "user32" _
(ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
'

Public Function GetWindowsList()
Dim lgRep As Long
'
stGetWindowsList = vbNullString
lgRep = EnumWindows(AddressOf EnumWindowsProc, 0)
End Function

Public Function EnumWindowsProc(ByVal lgHwnd As Long, ByVal lgParam As Long)
As Long
Dim stTmp As String, lgTmp As Long, lgRet As Long
'
stTmp = Space$(120)
lgTmp = 119
lgRet = GetWindowText(lgHwnd, stTmp, lgTmp)
If Len(stTmp) > 1 And lgRet <> 0 Then
Form1.List1.AddItem Format(lgHwnd, "00000000") & " : " & stTmp
End If
EnumWindowsProc = 1
End Function
Discussions similaires