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 70 71 72 73 74 75 76 77 78 79
| Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) _
As Long
Private Declare Function GetClassName Lib "user32" _
Alias "GetClassNameA" _
(ByVal hwnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long
Public Declare Function EnumChildWindows Lib "user32" _
(ByVal hWndParent As Long, _
ByVal lpEnumFunc As Long, _
ByVal lparam As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
lparam As Any) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
(ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) _
As Long
Public mdp_boucle, login_boucle As Long
Sub Administrateur()
Dim ret As Long
ret = FindWindow(vbNullString, "ma fenetre")
mdp_boucle = 1
login_boucle = 1
If ret <> 0 Then
Call EnumChildWindows(ret, AddressOf EnumChildProc, &H0)
End If
End Sub
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lparam As Long) As Long
Const BM_SETSTATE = &HF3
Const WM_LBUTTONDOWN = &H201
Const WM_LBUTTONUP = &H202
Const WM_SETTEXT = &HC
Dim sClass As String
Dim sTitle As String
Dim l As Long
sClass = Space$(255)
sTitle = Space$(255)
l = GetClassName(hwnd, sClass, 255)
sClass = Left$(sClass, l)
If sClass = "ComboBoxEx32" And login_boucle = 4 Then
SendMessage hwnd, WM_SETTEXT, 0&, ByVal "login"
End If
l = GetClassName(hwnd, sClass, 255)
sClass = Left$(sClass, l)
If sClass = "Edit" And mdp_boucle = 8 Then
SendMessage hwnd, WM_SETTEXT, 0&, ByVal "mdp"
End If
l = 0 'ici faire point d'arrêt pour lister les objets
mdp_boucle = mdp_boucle + 1
login_boucle = login_boucle + 1
l = GetWindowText(hwnd, sTitle, 255)
sTitle = Left$(sTitle, l)
If InStr(1, sTitle, "OK", vbTextCompare) Then
Call SendMessage(hwnd, WM_LBUTTONDOWN, 0, ByVal 0&)
Call SendMessage(hwnd, WM_LBUTTONUP, 0, ByVal 0&)
Call SendMessage(hwnd, BM_SETSTATE, 1, ByVal 0&)
End If
EnumChildProc = 1
End Function |
Partager