cs_DARKSIDIOUS
Messages postés15814Date d'inscriptionjeudi 8 août 2002StatutMembreDernière intervention 4 mars 2013131 2 déc. 2007 à 10:23
Salut,
Normal, le SetCursorPos est relatif à l'écran et non à ta fenêtre !
Il te faut convertir les coordonnées en coordonnées fenêtre pour cela ! (API ScreenToClient si ma mémoire est bonne).
______________________________________
DarK Sidious
cs_DARKSIDIOUS
Messages postés15814Date d'inscriptionjeudi 8 août 2002StatutMembreDernière intervention 4 mars 2013131 2 déc. 2007 à 12:16
Salut,
Voici un exemple tout droit sorti des exemples du fameux API-Guide :
'This project needs 2 Buttons
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Dim P As POINTAPI
Private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/ 'E-Mail: KPDTeam@Allapi.net
Command1.Caption = "Screen Middle"
Command2.Caption = "Form Middle"
'API uses pixels
Me.ScaleMode = vbPixels
End Sub
Private Sub Command1_Click()
'Get information about the screen's width
P.x = GetDeviceCaps(Form1.hdc, 8) / 2
'Get information about the screen's height
P.y = GetDeviceCaps(Form1.hdc, 10) / 2
'Set the mouse cursor to the middle of the screen
ret& = SetCursorPos(P.x, P.y)
End Sub
Private Sub Command2_Click()
P.x = 0
P.y = 0
'Get information about the form's left and top
ret& = ClientToScreen&(Form1.hwnd, P)
P.x = P.x + Me.ScaleWidth / 2
P.y = P.y + Me.ScaleHeight / 2
'Set the cursor to the middle of the form
ret& = SetCursorPos&(P.x, P.y)
End Sub
______________________________________
DarK Sidious
Vous n’avez pas trouvé la réponse que vous recherchez ?