Convert Mouse positions

vb6 Hungary
  • 11 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.

    -Viki-

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

  • 11 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

    -Viki-

  • 11 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

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


    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
            Get
              Return New Drawing.PointF(Me.X, Me.Y)
            End Get
          End Property
          Public ReadOnly Property toSizeF() As Drawing.SizeF
            Get
              Return New Drawing.SizeF(Me.X, Me.Y)
            End Get
          End Property
          Public ReadOnly Property toPoint() As Drawing.Point
            Get
              Return New Drawing.Point(Me.X, Me.Y)
            End Get
          End Property
          Public ReadOnly Property toSize() As Drawing.Size
            Get
              Return New Drawing.Size(Me.X, Me.Y)
            End Get
          End Property
          Public ReadOnly Property toText$()
            Get
              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
            Else
              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
              Else
                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).

Contribute

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.

“I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone” - Bjarne Stroustrup