-
Nov 12th, 2003, 01:22 PM
#1
Thread Starter
Addicted Member
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:
Option Explicit
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Sub Form_Load()
Me.Top = 0
Me.Left = 0
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim p As POINTAPI
Call GetCursorPos(p)
MsgBox "X: " & x & vbNewLine & _
"Y: " & y & vbNewLine & _
"PX: " & p.x & vbNewLine & _
"PY: " & p.y & vbNewLine & _
"NX: " & x / Screen.TwipsPerPixelX & vbNewLine & _
"NY: " & y / Screen.TwipsPerPixelY
End Sub
Last edited by finn0013; Nov 12th, 2003 at 01:56 PM.
-
Nov 12th, 2003, 01:23 PM
#2
Thread Starter
Addicted Member
sorry - meant to say PX = NX and PY = NY
-
Nov 12th, 2003, 01:27 PM
#3
Thread Starter
Addicted Member
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?
-
Nov 12th, 2003, 01:55 PM
#4
Thread Starter
Addicted Member
Here is the fix:
VB Code:
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim p As POINTAPI
Dim sw As Long
Dim sh As Long
Call GetCursorPos(p)
sw = ((Left + Width - ScaleWidth) / Screen.TwipsPerPixelX) - 4
sh = ((Top + Height - ScaleHeight) / Screen.TwipsPerPixelY) - 4
MsgBox "X: " & x & vbNewLine & _
"Y: " & y & vbNewLine & _
"PX: " & p.x & vbNewLine & _
"PY: " & p.y & vbNewLine & _
"NX: " & x / Screen.TwipsPerPixelX & vbNewLine & _
"NY: " & y / Screen.TwipsPerPixelY & vbNewLine & _
"SX: " & (x / Screen.TwipsPerPixelX) + sw & vbNewLine & _
"SY: " & (y / Screen.TwipsPerPixelY) + sh
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|