-
Apr 6th, 2024, 10:22 AM
#1
Thread Starter
Hyperactive Member
Global Mouse Position Over My Form
I need to get the mouse XY coordinates while over a form with several controls visible.
I use this to get the global mouse position.
Form scalemode is vbTwips.
Form is 2 - Sizable
Form has no control box or min max. Not a toolbar.
Form has a Caption showing.
SystemMetricsGet = GetSystemMetrics(eMetric)
Coords X, Y ' just shows the values, X, Y are Variants in Coords
Code:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim fCapHeight As Single
Dim fFrmBorderWidth As Single
' Get position
GetCursorPos RECT ' API
fCapHeight = ScaleY(SystemMetricsGet(SM_CYCAPTION), vbPixels, vbTwips)
fFrmBorderWidth = ScaleX(SystemMetricsGet(SM_CXDLGFRAME), vbPixels, vbTwips)
Coords csCursorXY, ScaleX(RECT.x, vbPixels, Units) - ScaleX(Me.Left + fFrmBorderWidth, vbTwips, Units), _
ScaleY(RECT.y, vbPixels, Units) - ScaleY(Me.Top + fCapHeight, vbTwips, Units)
' Position via Mouse_Move
Coords csPanelCoordXY, x, y ' show cursor position for local X Y
The XY of the two are off a little. What's wrong with my code ?
-
Apr 6th, 2024, 11:34 AM
#2
Re: Global Mouse Position Over My Form
I think I'm missing something.
What's wrong with GetCursorPos?
Code:
Option Explicit
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim MousePos As POINTAPI
GetCursorPos MousePos
Debug.Print "Mouse Position On Desktop (in Pixels):"
Debug.Print " x="; MousePos.X
Debug.Print " y="; MousePos.Y
End Sub
Or, are you asking a question about something? If so, you've posted in the codebank, and need to contact the moderators to have it moved to the Q&A section.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Apr 6th, 2024, 12:48 PM
#3
Thread Starter
Hyperactive Member
Re: Global Mouse Position Over My Form
First I am having trouble identifying where I am posting sometimes. Where on the web page does it show if I am in the Codebank or in the Forum ?
Thank you !
My code is trying to get the XY position of the mouse on the form (in my "Units") not the screen XY.
Units may be Inch or mm or whatever.
I need that XY of the form while hovering the mouse over objects (picturebox etc.) on the form.
If not over any object, then mouse_move gives form XY. If I move the object, then form mouse_move should give the same coordinates in Units as does a computer form XY from GetCursorPos.
-
Apr 8th, 2024, 08:41 AM
#4
Re: Global Mouse Position Over My Form
 Originally Posted by LorinM
First I am having trouble identifying where I am posting sometimes. Where on the web page does it show if I am in the Codebank or in the Forum ?
There is always the breadcrumbs at the top of the page just under the menu. Does it say VB6 and Earlier or Codebank - VB6 and Earlier? Post in the former if you have a question and the latter if you have a solution you'd like to share.
-
Apr 16th, 2024, 04:22 PM
#5
Thread Starter
Hyperactive Member
Re: Global Mouse Position Over My Form
Got it !
Also how do I or a moderator say when satisfied and done ?
Is you code as buggy as your posts ? LOL
Even years later I find a bug in mine.
-
Apr 16th, 2024, 05:37 PM
#6
Re: Global Mouse Position Over My Form
Thread Tools > Marked as Resolved
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
|