Private Sub Command1_Click()
Dim process As String
Dim i As Integer
process = 'Sans titre - Bloc-notes'
Call GetWinHandles
For i = 0 To UBound(atabwhnd)
If atabwhnd(i) = process Then
MsgBox atabwhnd(i)
End If
Next
End Sub
Dans un module
Public Declare Function EnumWindows& Lib 'user32' (ByVal lpEnumFunc As Long, _
ByVal lParam 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 Declare Function GetClassName Lib 'user32' Alias 'GetClassNameA' (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public atabwhnd()
Public iWnd As Integer
Public Sub GetWinHandles()
' permet de connaitre toutes les applications en cours
Dim lonstatus As Long
Dim londummy As Long
iWnd = 0&
lonstatus = EnumWindows&(AddressOf EnumWindowsproc, ByVal iWnd)
End Sub
Function EnumWindowsproc(ByVal addhWnd As Long, ByVal optparam As Long) As Long
' extrait les proccess en cours
Dim st As String
Dim cc As Long
Dim x As Long
Dim y
Dim z As Long
Dim sclass As String
sclass = String(250, ' ')
y = addhWnd
cc = 250
st = Space(250)
x = GetWindowText(addhWnd&, st, cc)
If Asc(Left(st, 1)) > 0 Then
If iWnd > 0 Then
ReDim Preserve atabwhnd(iWnd)
Else
ReDim Preserve atabwhnd(1)
iWnd = 1
End If
z = GetClassName(addhWnd&, sclass, 250)
atabwhnd(iWnd) = Left(st, x)
iWnd = iWnd + 1
End If
EnumWindowsproc = True
End Function
Le code du form peut etre transformé en fonction
Function IsProcess(process) as boolean
isprocess=false
dim i as integer
for i=0 to ubound(atabwhnd)
if atabwhnd(i)=process then
IsProcess=true
exit for
endif
next
Dans le code qui recherche
If isProcess('Sans titre - Bloc-notes') then
' code
else
' code
ebdif