|
-
May 27th, 2001, 03:05 PM
#1
Thread Starter
Hyperactive Member
Mouse Pos Relative to The form..
Hey, I am using the GETCURSORPOS on the computer.. and It gets the mouse's pos relative to the screen..
I need it so if the mouse is over the top left of the form, it'll be 0,0
bottomright would be width,height
I need to use this.. because the X,Y of the form itself.. just wouldn't always capture if another control was under the mouse..
then I also needed so it would capture the points AROUND the form..
anyhelp is good help =)
-
May 27th, 2001, 03:42 PM
#2
Thread Starter
Hyperactive Member
I have a bad headache so this is hard to figure out..
Code:
Public Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long
Type PointAPI
X As Long
Y As Long
End Type
Dim Pos As PointAPI
GetCursorPos Pos
Me.Cls
'Space from the form
Me.Print Pos.X & "<>" & Me.Left + 3 'FROM LEFT
Me.Print Pos.X & "<>" & (Me.Left + Me.ScaleWidth) - 3 'FROMRIGHT
Me.Print Pos.Y & "<>" & Me.Top + 3 'FROM TOP
Me.Print Pos.Y & "<>" & Me.Top + 19 'FROM BOTTOM
Anyways: this works FINE if the Form's TOP and LEFT = 0
but if it doesn't, then it doesn't work too good
anybody know what i am missing?
-
May 27th, 2001, 03:44 PM
#3
So Unbanned
Subtract the left and top from the x and y, if it's negative it's left of, or above the form, and postive it's below the upper edge, or right of the left edge.
I think you get it.
(if you get weird measurements times x and y by screen.twipsperpixel)
May the force be with you?
-
May 27th, 2001, 03:53 PM
#4
Thread Starter
Hyperactive Member
I can't get it to work correctly ..
ehhhhh
-
May 27th, 2001, 03:55 PM
#5
So Unbanned
I was feeling nice:
Code:
Private Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long
Private Type PointAPI
X As Long
Y As Long
End Type
Private Pos As PointAPI
Private Sub Timer1_Timer()
GetCursorPos Pos
Caption = Pos.X - (Left / Screen.TwipsPerPixelX) & "," & Pos.Y - (Top / Screen.TwipsPerPixelY)
End Sub
By the way, you can put all that in Form1, you don't need a bas when you declare as Private.
-
May 27th, 2001, 03:59 PM
#6
Thread Starter
Hyperactive Member
Will that return the X,Y of the screen into PIXELS?
-
May 27th, 2001, 04:00 PM
#7
Frenzied Member
All right, here it is:
Code:
'Declarations
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
'Code
Dim MyPoint As POINTAPI
GetCursorPos MyPoint
ScreenToClient Me.hwnd, MyPoint
X_Pos = MyPoint.X - 5
Y_Pos = MyPoint.Y - 5
Not sure about the -5 stuff, they were with the code I found but I'm not sure if they're needed.
Hope that helped
-
May 27th, 2001, 04:13 PM
#8
Thread Starter
Hyperactive Member
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
|