Option Explicit
Public Declare Function RecupTitre Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function EnumFenetres Lib "user32" Alias "EnumWindows" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Long
Dim Etat As String
Sub test()
Dim lResult As Long
'Test si connexion
If TestDeConnexion Then
MsgBox "Vous étes connecté", vbInformation
Else
MsgBox "Vous n'étes pas connecté", vbInformation
End If
'Test si Outlook Express Actif
lResult = EnumFenetres(AddressOf Outlook_Express, 0&)
MsgBox Etat
End Sub
'Test connexion
Function TestDeConnexion() As Boolean
TestDeConnexion = InternetGetConnectedState(0&, 0&)
End Function
Public Function Outlook_Express(ByVal hWnd As Long, ByVal lgParam As Long) As Long
Dim Buffer As String
Dim Result As Long
Buffer = Space(255)
Result = RecupTitre(hWnd, Buffer, 255)
If Left(Buffer, 1) <> Chr(0) Then
If InStr(Trim(Buffer), "Outlook Express") <> 0 Then
Etat = "Outlook Express est Actif !"
Exit Function
End If
End If
Outlook_Express = 1
Etat = "Outlook Express est Inactif !"
End Function