Private Declare Function FindWindow& Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String)
Private Declare Function SetTimer& Lib "user32" _
(ByVal hwnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long)
Private Declare Function KillTimer& Lib "user32" _
(ByVal hwnd As Long, ByVal nIDEvent As Long)
Private Declare Function GetWindowText& Lib "user32" _
Alias "GetWindowTextA" _
(ByVal hwnd As Long, ByVal lpString As String, _
ByVal cch As Long)
Private Declare Function GetWindowRect& Lib "user32" _
(ByVal hwnd As Long, lpRect As RECT)
Private Declare Function SetCursorPos& Lib "user32" _
(ByVal x As Long, ByVal y As Long)
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private OnTimer As Long
Private DECALH As Long
Private DECALV As Long
Private TITRE_MSGBOX As String
'___________________________
Private Sub API_PointeurSourisMsgBox()
Dim HwndMsgBox&
HwndMsgBox& = FindWindow(vbNullString, TITRE_MSGBOX)
Dim Ch$
Dim Tampon&
Dim reponse&
Dim R As RECT
Ch$ = Space(1024)
Tampon& = Len(Ch$)
reponse& = GetWindowText(HwndMsgBox&, Ch$, Tampon&)
Ch$ = Trim(Replace(Ch$, Chr$(0), ""))
If Ch$ = TITRE_MSGBOX Then
reponse& = GetWindowRect(HwndMsgBox&, R)
reponse& = SetCursorPos(((R.Left + R.Right) / 2) + DECALH, ((R.Top + R.Bottom) / 2) + DECALV)
Call OffTimer
End If
End Sub
'___________________________
Public Sub RunTimer(Delai&)
If OnTimer& > 0 Then OffTimer
OnTimer& = SetTimer(0, 0, ByVal Delai&, AddressOf API_PointeurSourisMsgBox)
End Sub
'___________________________
Private Sub OffTimer()
If OnTimer& > 0 Then
OnTimer& = KillTimer(0&, OnTimer&)
OnTimer& = 0
End If
End Sub
'___________________________
Public Sub PointeurSourisMsgBox(TitreMsgBox As String, DecalageH As Long, DecalageV As Long)
TITRE_MSGBOX = TitreMsgBox
DECALH = DecalageH
DECALV = DecalageV
OnTimer& = 0
Call RunTimer(Delai:=0)
End Sub