Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SetCursorPos function (User32) question.

Posted on 1998-05-14
7
Medium Priority
?
760 Views
Last Modified: 2013-12-03
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
0
Comment
Question by:LSILes
  • 3
  • 2
  • 2
7 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1401730
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.
0
 

Author Comment

by:LSILes
ID: 1401731
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
0
 
LVL 22

Expert Comment

by:nietod
ID: 1401732
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.
0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
LVL 8

Expert Comment

by:MikeP090797
ID: 1401733
This is the correct declaration of SetCursorPos:


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

0
 

Author Comment

by:LSILes
ID: 1401734
Works for me...  just send it to me as an answer and it's all yers!  Thanks!

---LSILes
les@livingscriptures.com
0
 
LVL 8

Accepted Solution

by:
MikeP090797 earned 100 total points
ID: 1401735
k
0
 

Author Comment

by:LSILes
ID: 1401736
Thanks Mike!

---LSILes
les@livingscriptures.com
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question