Results 1 to 3 of 3

Thread: SetCursorPos ??

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2000
    Posts
    29

    Question

    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.
    VB and Java are great - ja, so ist es !! To my software programming site: http://www.majasoft-games.de .

  2. #2
    New Member
    Join Date
    Oct 2000
    Posts
    4

    Lightbulb ClipCursor

    You can use the ClipCursor api to lock the mouse pointer to a specific area.
    //MVH takko

  3. #3
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    You have to recalculate X and Y again, because the picturebox is a client window of it's owner window.
    Code:
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width