Solved

SetCursorPos function (User32) question.

Posted on 1998-05-14
7
726 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Run Program using VBScript 3 85
How and where to get Business Intelligence Development Studio? 2 111
Having a different time zone on your task bar 3 83
SSRS troubles 4 106
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
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…

751 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