Mouse tracker

Description

Bon voila un ptit prog vite fait qui indique la position du curseur en le faisant suivre pas des lignes, attention sa vous paraitra peut etre faut les mesure mais c'est pk en fait il y a un cdre qui en vrai delimite les borts du curseur.

Donc il vous faut :

1 Form (Form1)
1 Module (Module1)
4 lignes (line1, line2, line3, line4)
1 label (label1)
1 timer (timer1)
2 frame l'une dans l'autre (frame1, frame2)
6 option butons (option1(0), option1(1), option1(2) (dans la frame1), option2(0), option2(1), option2(2) (dans la frame2))
2 checkbox (check1 (dans la frame2), check2 (dans la frame1))

Bon vous foutez tout sa en vrac sur la form et sa s'organize tout seul !!
Si vous voulez pas telecharger le zip
Par contre il y a une partie a metre dans un module et une autre dans la form

Source / Exemple :


'A METRE DANS UN MODULE :
Option Explicit

Declare Function ClipCursor Lib "user32" (lpRect As RECT) As Long
Declare Function GetCursorPos Lib "user32" (lpPoint As POINT_TYPE) As Long
Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long

Public Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type
Type POINT_TYPE
  X As Long
  Y As Long
End Type

Public Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Public Declare Function OpenDriver Lib "winmm.dll" Alias "OpenDriverA" (ByVal DriverName As String) As Long

'A METRE DANS LA FORM
Option Explicit
Dim p As POINT_TYPE
Dim i As Variant
Dim OK As Boolean
Dim XX, YY As Long
Private Sub Form_Load()
'Positionement et configuration des objets
Me.Height = 6825
Me.Width = 8640
Me.Left = (Screen.Width - Me.Width) / 2
Me.Top = (Screen.Height - Me.Height) / 2
Label1.AutoSize = True
Label1.Top = 0
Label1.Left = (Me.Width - Label1.Width) / 2
Label1.BackColor = vbWhite
Label1.ForeColor = vbRed
Option1(0).Caption = "Contours"
Option1(2).Caption = "Pointeur"
Option1(1).Caption = "Milieu"
For i = 0 To 2
Option1(i).Top = 240
Option2(i).Caption = Option1(i).Caption
Option2(i).Enabled = False
Option2(i).Top = 240
Next i
Option1(0).Left = 120
Option1(1).Left = 1080
Option1(2).Left = 1920
Option2(0).Left = 120
Option2(1).Left = 1200
Option2(2).Left = 2040
Timer1.Enabled = True
Timer1.Interval = 1
Frame1.Height = 1575
Frame1.Width = 3735
Frame1.Left = 4800
Frame1.Top = 5160
Frame1.Caption = "Options"
Frame2.Height = 615
Frame2.Width = 3495
Frame2.Left = 120
Frame2.Top = 480
Check1.Caption = "Bords"
Check1.Top = 0
Check1.Left = 120
Check2.Caption = "Lignes en pointiés"
Check2.Top = 1200
Check2.Left = 120
Command1.Caption = "x"
Command1.Left = 8400
Command1.Top = 0
Command1.Width = 135
Command1.Height = 135
End Sub
'!
'!Code de Deplacement d'une Form a partir d'un objet, par OverDarck
Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
OK = True
XX = X
YY = Y
End Sub
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If OK = True Then
Call mov(X, Y, Button)
End If
End Sub
Private Sub Label1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
OK = False
If Me.Top < 0 Then Me.Top = 0
If Me.Left < 0 Then Me.Left = 0
If Me.Top > Screen.Height - Me.Height Then Me.Top = Screen.Height - Me.Height
If Me.Left > Screen.Width - Me.Width Then Me.Left = Screen.Width - Me.Width
XX = 0
YY = 0
End Sub
Private Sub mov(X As Single, Y As Single, Button As Integer)
If Not Button = 1 Then Exit Sub
Form1.Move X + Form1.Left - XX, Y + Form1.Top - YY
End Sub
'!Fin du code
'!
Private Sub Check2_Click()
If Check2.Value = 0 Then
Line1.BorderStyle = 1
Line2.BorderStyle = 1
Line3.BorderStyle = 1
Line4.BorderStyle = 1
ElseIf Check2.Value = 1 Then
Line1.BorderStyle = 3
Line2.BorderStyle = 3
Line3.BorderStyle = 3
Line4.BorderStyle = 3
End If
End Sub
Private Sub Option1_Click(Index As Integer)
Timer1.Enabled = False
If Option1(Index).Value = True Then
    Check1.Value = 0
    For i = 0 To 2
    Option2(i).Enabled = False
    Next i
End If
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Select Case Check1.Value
Case 0
With Line1
.Y1 = -240
.Y2 = 7560
End With
With Line3
.Y1 = -240
.Y2 = 7560
End With
With Line2
.X1 = 0
.X2 = 12360
End With
With Line4
.X1 = 0
.X2 = 12360
End With
'!!
Case 1
'!!
With Line1
.Y1 = -7320
.Y2 = 480
End With
With Line3
.Y1 = 6600
.Y2 = 14400
End With
With Line2
.X1 = -12120
.X2 = 240
End With
With Line4
.X1 = 8400
.X2 = 20760
End With
For i = 0 To 2
Option1(i).Value = False
Option2(i).Enabled = True
Next i
End Select

'Position relative au deplacement du pointeur enregistre pas windob
GetCursorPos p

Label1.Caption = "Position X : " & p.X * 15 & " Y : " & p.Y * 15

If Option1(0).Value = True Then
    If Line1.Visible = False Then Line1.Visible = True
    If Line2.Visible = False Then Line2.Visible = True
    If Line3.Visible = False Then Line3.Visible = True
    If Line4.Visible = False Then Line4.Visible = True
    With Line1
    .X1 = p.X * 15 - Form1.Left
    .X2 = p.X * 15 - Form1.Left
    End With
    With Line2
    .Y1 = p.Y * 15 - Form1.Top
    .Y2 = p.Y * 15 - Form1.Top
    End With
    With Line3
    .X1 = Line1.X1 + 465
    .X2 = Line1.X2 + 465
    End With
    With Line4
    .Y1 = Line2.Y1 + 470
    .Y2 = Line2.Y1 + 470
    End With
ElseIf Option1(1).Value = True Then
    If Line3.Visible = True Then Line3.Visible = False
    If Line4.Visible = True Then Line4.Visible = False
    With Line1
    .X1 = p.X * 15 - Form1.Left + (465 / 2)
    .X2 = p.X * 15 - Form1.Left + (465 / 2)
    End With
    With Line2
    .Y1 = p.Y * 15 - Form1.Top + (470 / 2)
    .Y2 = p.Y * 15 - Form1.Top + (470 / 2)
    End With
ElseIf Option1(2).Value = True Then
    If Line3.Visible = True Then Line3.Visible = False
    If Line4.Visible = True Then Line4.Visible = False
    With Line1
    .X1 = p.X * 15 - Form1.Left
    .X2 = p.X * 15 - Form1.Left
    End With
    With Line2
    .Y1 = p.Y * 15 - Form1.Top
    .Y2 = p.Y * 15 - Form1.Top
    End With
ElseIf Option2(0).Value = True Then
    If Line3.Visible = False Then Line3.Visible = True
    If Line4.Visible = False Then Line4.Visible = True
    With Line1
    .X1 = p.X * 15 - Form1.Left
    .X2 = p.X * 15 - Form1.Left
    End With
    With Line2
    .Y1 = p.Y * 15 - Form1.Top
    .Y2 = p.Y * 15 - Form1.Top
    End With
    With Line3
    .X1 = Line1.X1 + 465
    .X2 = Line1.X2 + 465
    End With
    With Line4
    .Y1 = Line2.Y1 + 470
    .Y2 = Line2.Y1 + 470
    End With
ElseIf Option2(1).Value = True Then
        If Line3.Visible = False Then Line3.Visible = True
        If Line4.Visible = False Then Line4.Visible = True
        With Line1
        .X1 = p.X * 15 - Form1.Left + (465 / 2)
        .X2 = p.X * 15 - Form1.Left + (465 / 2)
        End With
        With Line2
        .Y1 = p.Y * 15 - Form1.Top + (470 / 2)
        .Y2 = p.Y * 15 - Form1.Top + (470 / 2)
        End With
        With Line3
        .X1 = p.X * 15 - Form1.Left + (465 / 2)
        .X2 = p.X * 15 - Form1.Left + (465 / 2)
        End With
        With Line4
        .Y1 = p.Y * 15 - Form1.Top + (470 / 2)
        .Y2 = p.Y * 15 - Form1.Top + (470 / 2)
        End With
ElseIf Option2(2).Value = True Then
        If Line3.Visible = True Then Line3.Visible = False
        If Line4.Visible = True Then Line4.Visible = False
        With Line1
        .X1 = p.X * 15 - Form1.Left
        .X2 = p.X * 15 - Form1.Left
        End With
        With Line2
        .Y1 = p.Y * 15 - Form1.Top
        .Y2 = p.Y * 15 - Form1.Top
        End With
End If
End Sub
Private Sub Command1_Click()
End
End Sub

Conclusion :


Je tient a preciser que l'optention de la position du curseur se fait grace a un bout de code d'ulysse donc Merci a ThunderGun, et le reste de mon prog sert juste a interprter cette position.
Ptetre que certain veron cette source inutile mais je pense que sa servira a certain.
Bonne Prog A tous quand même @+
OverDarck

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.