Convert Mouse positions

vb6 Hungary
  • 13 years ago

    Hello all

    I want convert mouse position from API 'getcursorpos' and use in mousedown of same control but dont understand how to do this.

    getcursorpos return x and y in different scale to the control 'mousedown' and 'mouseup'. 

    I have now:

    Private Sub MyControl_DblClick(Index As Integer)
    Dim Pt As POINTAPI
    GetCursorPos Pt
    ' returns PT.x and PT.y
    Call MyControl_MouseUp(Index, vbRightButton, 0, PT.x, PT.y)
    End Sub

    How do I convert before pass routine please?

    Sorry if English bad.


  • 13 years ago
    Can you pass me some comparable data from both routines?

  • 13 years ago

    konikula wrote:
    Can you pass me some comparable data from both routines?

    I not sure which you meaning.

    I try explain:  I have listview with 4 columns.   Mouse inside each column execute diffrent part of procedure.   This is easy when calling mouseup with X and Y is predefine variables in procedure as you know.  the X and Y of

    Private Sub mylist_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)

    Inside my mouseup procedure I check position of mouse, use simple if 

    If X>1950 and X<2450 then...

    This tell me mouse is over column 2 because listview widths are fixed.

    This part is good.  I think form scale is look like Twips


    But if I call from another function or procedure I want and must pass exact mouse position so the correct part of procedure is execute.   So I need to know position of mouse BEFORE I call.   I use API procedure but the postion it give is not Twips, but unknown scale.

    I use standard API procedure from library. 

    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

    Private Type POINTAPI
    X As Long
    Y As Long
    End Type


    I call using

    GetCursorPos Pt

    So I get pt.x = horizontal and pt.y = vertical.  I not use vertical.

    The API pt.x  is a very low number compare to mousup x


    I hope you understand me.  Sorry for bad english


  • 13 years ago
    I tried it. I think, that api getcurpos returns physical pixel position of cursor related to screen [0,0],
    and MouseUp point returned is related to its event control

    API::[264,490] (= = EVT Position + Its Control Position)

    So I think these 2 values are comparable...

    Here I flipped code I used to test it

    Declare Function GetCursorPos& Lib "user32" (ByRef lpPoint As apiPt)

    Shared Function GetCursorPos() As apiPt
     Dim rp As cApi.apiPt
     Dim ret& = lApi.user32.GetCursorPos(rp)
     Return rp
    End Function

        Public Structure apiPt
          Public X%, Y%

          Public ReadOnly Property toPointF() As Drawing.PointF
              Return New Drawing.PointF(Me.X, Me.Y)
            End Get
          End Property
          Public ReadOnly Property toSizeF() As Drawing.SizeF
              Return New Drawing.SizeF(Me.X, Me.Y)
            End Get
          End Property
          Public ReadOnly Property toPoint() As Drawing.Point
              Return New Drawing.Point(Me.X, Me.Y)
            End Get
          End Property
          Public ReadOnly Property toSize() As Drawing.Size
              Return New Drawing.Size(Me.X, Me.Y)
            End Get
          End Property
          Public ReadOnly Property toText$()
              Return lGraphics.Human.wPoint(Me.toPoint)
            End Get
          End Property
          Public Overloads Function Equals(ByVal o As Object) As Boolean
            If o Is Nothing Then
              Return False
              Dim ot As System.Type = o.GetType
              If ot.Equals(GetType(apiPt)) Then
                With CType(o, apiPt) : Return (Me.X = .X) And (Me.Y = .Y) : End With
              ElseIf ot.Equals(GetType(Drawing.Point)) Then
                With CType(o, Drawing.Point) : Return (Me.X = .X) And (Me.Y = .Y) : End With
              ElseIf ot.Equals(GetType(Drawing.PointF)) Then
                With CType(o, Drawing.PointF) : Return (Me.X = .X) And (Me.Y = .Y) : End With
                Return o.Equals(Me)
              End If
            End If
          End Function
          Public Sub New(ByVal X_%, ByVal Y_%)
            Me.X = X_
            Me.Y = Y_
          End Sub
        End Structure

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Never trust a programmer in a suit.” - Anonymous