Link to home
Start Free TrialLog in
Avatar of LSILes
LSILes

asked on

SetCursorPos function (User32) question.

I'm having a small problem with SetCursorPos...  whenever I call it, it seems to just set my cursor the 0,0.  That's all it does...  here's my code:

In General - Declarations:

Private Type Point
    X As Long
    Y As Long
End Type
Private Type Rect
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Private Declare Function GetCursorPos Lib "User32" (ByRef ptPoint As Point) As Boolean
Private Declare Function SetCursorPos Lib "User32" (ByRef X, Y As Integer) As Boolean
Private Declare Function ClipCursor Lib "User32" (ByRef Rectangle As Rect) As Boolean

--------------------------------------------------------------------------------------

Private Sub Command1_Click()
    Dim MyRect As Rect
    Dim HoldX, Temp
    Dim ptMouse As Point

    MyRect.Left = 0
    MyRect.Top = 0
    MyRect.Right = 800
    MyRect.Bottom = 600
    ClipCursor MyRect
    GetCursorPos ptMouse
    HoldX = CVar(ptMouse.X + 100)
    Do Until ptMouse.X = HoldX
        ptMouse.X = ptMouse.X + 1
       
    Loop
    SetCursorPos CInt(HoldX), CInt(ptMouse.Y)
End Sub

--------------------------------------------------------------------------------------

Oh, by the way...  I'm using VB 5.0, programming in Win 95.  Screen resolution is set to 800 x 600.  Any ideas ladies and gentlemen?  If so, please let me know A.S.A.P.  Thank you!

---LSILes
les@livingscriptures.com
Avatar of nietod
nietod

I'm not sure of hte VB syntax, but it looks like you are passing the X and Y values by reference.  They should be passed by value.
Avatar of LSILes

ASKER

Good thought...  that did occur to me before I asked the question, and I tried it, but I found out that it can only be passed ByRef.  I would change it, but again, it's a User32 function, so I have no idea how to.  The message I get when I did try to change it to ByVal was:

Run-time error '49':

Bad DLL calling convention

And it ends the program for me.  Have any more ideas?  Or should I use something other than ByVal?  Please let me know... thanks!

---LSILes
les@livingscriptures.com
The problem probly is both the reference part AND the fact that you specify them as integers not long  (I'm guessing here, but is an integer 16 bits?  these should be 32 bits.)  Try passing them by value and as long.  

By the way I'm not answering this becuase I'm leaving town for a few days and hate to lock a question and dissappear.
This is the correct declaration of SetCursorPos:


Declare Function SetCursorPos Lib "user32" Alias "SetCursorPos" (ByVal x As Long, ByVal y As Long) As Long

Avatar of LSILes

ASKER

Works for me...  just send it to me as an answer and it's all yers!  Thanks!

---LSILes
les@livingscriptures.com
ASKER CERTIFIED SOLUTION
Avatar of MikeP090797
MikeP090797

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LSILes

ASKER

Thanks Mike!

---LSILes
les@livingscriptures.com