Results 1 to 4 of 4

Thread: Cursor Position - **RESOLVED**

Hybrid View

  1. #1

    Thread Starter
    Addicted Member finn0013's Avatar
    Join Date
    Jan 2001
    Location
    Charleston, SC
    Posts
    222

    Angry Cursor Position - **RESOLVED**

    This is driving me nuts - I can not get X to equal NX or Y to equal NY. It all looks right to me, however I am just spinning my wheels now - just paste this in a form and run:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    4.  
    5. Private Type POINTAPI
    6.     x As Long
    7.     y As Long
    8. End Type
    9.  
    10. Private Sub Form_Load()
    11.     Me.Top = 0
    12.     Me.Left = 0
    13. End Sub
    14.  
    15. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    16.  
    17.     Dim p As POINTAPI
    18.    
    19.     Call GetCursorPos(p)
    20.  
    21.     MsgBox "X: " & x & vbNewLine & _
    22.            "Y: " & y & vbNewLine & _
    23.            "PX: " & p.x & vbNewLine & _
    24.            "PY: " & p.y & vbNewLine & _
    25.            "NX: " & x / Screen.TwipsPerPixelX & vbNewLine & _
    26.            "NY: " & y / Screen.TwipsPerPixelY
    27. End Sub
    Last edited by finn0013; Nov 12th, 2003 at 01:56 PM.

  2. #2

    Thread Starter
    Addicted Member finn0013's Avatar
    Join Date
    Jan 2001
    Location
    Charleston, SC
    Posts
    222
    sorry - meant to say PX = NX and PY = NY

  3. #3

    Thread Starter
    Addicted Member finn0013's Avatar
    Join Date
    Jan 2001
    Location
    Charleston, SC
    Posts
    222
    Seems the difference between PX and NX is always 4 and the difference between PY and NY is always 30.

    I could hard code to account for this however I am reluctant to do so as this may be something that could change from system to system.

    Any ideas why this is doing this?

  4. #4

    Thread Starter
    Addicted Member finn0013's Avatar
    Join Date
    Jan 2001
    Location
    Charleston, SC
    Posts
    222
    Here is the fix:

    VB Code:
    1. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    2.  
    3.     Dim p As POINTAPI
    4.     Dim sw As Long
    5.     Dim sh As Long
    6.    
    7.     Call GetCursorPos(p)
    8.  
    9.     sw = ((Left + Width - ScaleWidth) / Screen.TwipsPerPixelX) - 4
    10.     sh = ((Top + Height - ScaleHeight) / Screen.TwipsPerPixelY) - 4
    11.            
    12.     MsgBox "X: " & x & vbNewLine & _
    13.            "Y: " & y & vbNewLine & _
    14.            "PX: " & p.x & vbNewLine & _
    15.            "PY: " & p.y & vbNewLine & _
    16.            "NX: " & x / Screen.TwipsPerPixelX & vbNewLine & _
    17.            "NY: " & y / Screen.TwipsPerPixelY & vbNewLine & _
    18.            "SX: " & (x / Screen.TwipsPerPixelX) + sw & vbNewLine & _
    19.            "SY: " & (y / Screen.TwipsPerPixelY) + sh
    20.        
    21. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width