Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SetCursorPos function (User32) question.

Posted on 1998-05-14
7
Medium Priority
?
747 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

721 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