Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1463

Global Mouse Position Over My Form

$
0
0
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 ?

Viewing all articles
Browse latest Browse all 1463

Trending Articles