Un setCursorPos pas a sa place

argentin7 Messages postés 125 Date d'inscription vendredi 10 août 2007 Statut Membre Dernière intervention 14 juillet 2008 - 2 déc. 2007 à 09:38
argentin7 Messages postés 125 Date d'inscription vendredi 10 août 2007 Statut Membre Dernière intervention 14 juillet 2008 - 2 déc. 2007 à 14:15
bonjour tous le monde

voila un code qui ne donne pas le resultat escompté a savoir placer le curseur a l'extremité de la ligne LINE1

Private Declare Function SetCursorPos Lib "user32.dll" (ByVal x As Long, ByVal y As Long) As Long

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)

If ((Line1.X1 - x) ^ 2 + (Line1.Y1 - y) ^ 2) ^ (0.5) < 8 Then

Shape1.Top = Line1.Y1 - Shape1.Height / 2
Shape1.Left = Line1.X1 - Shape1.Width / 2
SetCursorPos Line1.X1, Line1.Y1
End If

End Sub

SVP jettez un coup d'oeil

merci d'avance

9 réponses

cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 131
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
0
argentin7 Messages postés 125 Date d'inscription vendredi 10 août 2007 Statut Membre Dernière intervention 14 juillet 2008
2 déc. 2007 à 10:30
Merci beaucoup
je vais cherché cette fonction et voir ce que va donner
0
argentin7 Messages postés 125 Date d'inscription vendredi 10 août 2007 Statut Membre Dernière intervention 14 juillet 2008
2 déc. 2007 à 11:01
je n'ai pas encore trouvé la reponse
0
cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 131
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
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
2 déc. 2007 à 12:28
... alors pourquoi avoir validé le topic?!
http://www.vbfrance.com/infomsg_PLACER-SOURIS_1042594.aspx

bizarre, on dit tous la même chose....
(salut DKS)
Prenez un instant pour répondre à [infomsg_SONDAGE-POP3-POUR-CS_769706.aspx ce sondage] svp
0
argentin7 Messages postés 125 Date d'inscription vendredi 10 août 2007 Statut Membre Dernière intervention 14 juillet 2008
2 déc. 2007 à 13:59
PCPT> pourquoi validé le topic?
c'est simple parceque marques m'a montré la fonction que je dois utilisé

et si t'as bien remarqué (je suppose) j'ai mis reponse acceptée pour la reponse de jmfmarques
0
argentin7 Messages postés 125 Date d'inscription vendredi 10 août 2007 Statut Membre Dernière intervention 14 juillet 2008
2 déc. 2007 à 14:04
merci beaucoup DARKSIDIOUS
j'ai trouvé un exemple similaire au tien

je pense qu'il faut surtout ne pas oublier le me.scalemode=vbpixel

je remercie aussi ""PCPT"" grace a lui j'ai connu le twipperpixel
0
cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 131
2 déc. 2007 à 14:09
Salut PCPT,

De toute façon, y'a pas 40 000 façons de faire cà
______________________________________
DarK Sidious
0
argentin7 Messages postés 125 Date d'inscription vendredi 10 août 2007 Statut Membre Dernière intervention 14 juillet 2008
2 déc. 2007 à 14:15
t'as raison mais
il suffit juste de le faire une fois pour s'en souvenir toute la vie

merci pour l'aide
0
Rejoignez-nous