Solved

SetCursorPos function (User32) question.

Posted on 1998-05-14
7
707 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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 50 total points
ID: 1401735
k
0
 

Author Comment

by:LSILes
ID: 1401736
Thanks Mike!

---LSILes
les@livingscriptures.com
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now