majasoft
Nov 16th, 2000, 02:40 AM
Hi, I use SetCursorPos for my Game, but I use a PictureBox with the BitBlt-API, the SetCursorPos-Function set the cursor on the x and y coordinates of the screen-object, how can I put the cursor on the position (where I have clicked) in the PictureBox and hold the cursor on that x and y coordinates (Cursor not movable) - or how can I set the cursor on MouseMove in the PictureBox the (clicked) x and y coordinates.
Thanx for help and replies, MAJA.
takko
Nov 16th, 2000, 01:36 PM
You can use the ClipCursor api to lock the mouse pointer to a specific area.
Mad Compie
Nov 16th, 2000, 01:48 PM
You have to recalculate X and Y again, because the picturebox is a client window of it's owner window.
Option Explicit
'This Form needs a picturebox...
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lppoint As POINTAPI) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim lppoint As POINTAPI
Private Sub Form_Load()
Me.BorderStyle = 0
Picture1.BorderStyle = 0
Me.Caption = ""
Me.Appearance = 0
Picture1.Appearance = 0
Picture1.BackColor = &HC0FFFF
Me.BackColor = &HC0C0C0
Me.ScaleMode = vbPixels
Picture1.ScaleMode = vbPixels
Picture1.AutoRedraw = True
Me.AutoRedraw = True
Me.Line (0, 0)-(Me.ScaleWidth - 1, Me.ScaleHeight - 1), &HFF, B
Picture1.Line (0, 10)-(Picture1.ScaleWidth, 10), &HFF
Picture1.CurrentX = 0
Picture1.CurrentY = 50
Picture1.Print "Click me..."
Picture1.AutoRedraw = False
Me.AutoRedraw = False
End Sub
Private Sub Picture1_Click()
Dim i As Integer
For i = 0 To Picture1.ScaleWidth - 1
SetCursorPos i, 20 'NOT GOOD!
Sleep 20
Next i
For i = 0 To Picture1.ScaleWidth - 1
SetCursorPos ScaleX(Me.Left, vbTwips, vbPixels) + Picture1.Left + i, ScaleY(Me.Top, vbTwips, vbPixels) + Picture1.Top + 10
Sleep 10
Next i
End Sub