1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xpoint As Long, ByVal ypoint As Long) As Long
'exercice 1:- le hwnd obtenu en plaçant le curseur tout contre (très légèrement en dessous et très légèrement à droite) de l'angle supérieur droit de la barre de titre de ton "userform" apparent
'exercice 2:- le hwnd obtenu en plaçant le curseur sur le "userform apparent", juste en dessous le sa barre de titre
'exercice 3:- le hwnd de l'userform réel (obtenu, LUI, par FINDWINDOWS et non par Windowfrompoint, hein ...
Sub testunparia()
'ppx=
With CreateObject("WScript.Shell"): ppx = .RegRead("HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics\AppliedDPI") / 72: End With
With Application: .Left = 50: .Top = 100: End With
With UserForm1: .Show 0: .Left = 10: .Top = 20: End With
'hwnd par findwindow
handle1 = FindWindow(vbNullString, UserForm1.Caption)
'on place le curseur selon l'exercice 1
SetCursorPos (UserForm1.Left + UserForm1.Width) * ppx + 5, (UserForm1.Top * ppx - 10)
exercice1 = WindowFromPoint((UserForm1.Left + UserForm1.Width) * ppx + 5, (UserForm1.Top * ppx - 10))
SetCursorPos (UserForm1.Left + UserForm1.Width) * ppx - 10, (UserForm1.Top * ppx - 25)
exercice2 = WindowFromPoint((UserForm1.Left + UserForm1.Width) * ppx - 10, (UserForm1.Top * ppx - 25))
exercice3 = FindWindow(vbNullString, UserForm1.Caption)
MsgBox "exercice1 handle obtenu = " & exercice1 & vbCrLf & "exercice2 handle obtenu = " & exercice2 & vbCrLf & "exercice3 handle obtenu = " & exercice3
End Sub |
Partager