1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| Option Explicit
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindow& Lib "user32" (ByVal hWnd&, ByVal wCmd&)
Private Declare Function GetWindowLong& Lib "user32" _
Alias "GetWindowLongA" (ByVal hWnd&, ByVal nIndex&)
Private Declare Function GetWindowText& Lib "user32" Alias _
"GetWindowTextA" (ByVal hWnd&, ByVal lpString$, ByVal aint&)
Private Const mconMAXLEN = 255
Public Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare PtrSafe Function CloseWindow Lib "user32" (ByVal hWnd As Long) As Long
Public Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long
Public Declare PtrSafe Function FindWindowEx Lib "user32" _
Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, _
ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Const BM_CLICK As Long = &HF5
Sub AxelActivate()
Dim hWnd&, Style&, Title$, i&
Dim Nom As String
Dim hWndApp, hWndButton As Long
hWnd = GetWindow(GetDesktopWindow(), 5)
'
Do While hWnd
Title = GetCaption(hWnd)
If Len(Title) Then
'
If GetWindowLong(hWnd, -16) And &H10000000 Then
If InStr(1, Title, "Axel", 1) Then
AppActivate Title
SendKeys "~"
Application.Wait Time + TimeSerial(0, 0, 2)
Exit Sub
End If
End If
End If
hWnd = GetWindow(hWnd, 2)
hWndApp = FindWindow(vbNullString, "Axel")
If hWndApp Then hWndButton = FindWindowEx(hWndApp, 0&, vbNullString, "Déclarer incident")
If hWndButton Then Call SendMessage(hWndButton, BM_CLICK, 0, 0)
Loop
MsgBox "Vérifier si l'application Axel est ouverte !", vbCritical, "ERROR"
End Sub
Private Function GetCaption(hWnd&) As String
Dim i%, Buffer$: Buffer = String$(254, 0)
i = GetWindowText(hWnd, Buffer, 255)
If i Then GetCaption = Left$(Buffer, i)
End Function |
Partager