CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2002
    Location
    Athens , Greece
    Posts
    151

    RESOLVED-Convert Long to Single for the GetCursorPos function

    Hello
    i am using the getcursorpos function to get the correct position
    of the mouse.
    the problem is it does not seem to show correct position.

    the getcursorpos returns a POINTAPI type which has a X as long and Y as long.

    I want the X,Y to get converted to Single.

    i tried form1.scalex(point.x,vblong,vbsingle)
    but it did not work.

    instead i used xsingle=15*xlong and it seems to quite work but not 100%.

    also how to i convert from twips to single ??

    thanks !!
    Last edited by alexr123; April 2nd, 2003 at 09:55 AM.

  2. #2
    Join Date
    Dec 2001
    Posts
    6,332
    API's work in pixels. You can convert the coords by using Screen.TwipsPerPixelX and Y in your calculations. It does not matter that they are Long instead of Single. The values are whole numbers anyway.

  3. #3
    Join Date
    Aug 2002
    Location
    Athens , Greece
    Posts
    151
    well i got a ruler control .
    it has a function like that

    I want to set X,Y which are of long type (POINTAPI) to single

    Public Sub RenderTrackLine(X As Single, Y As Single)
    If mvarMouseTrackingOn = True Then
    RenderControl
    'Optionaly render Mouse tracking line
    Select Case Orientation
    Case orHorizontal
    Line (X, 0)-(X, ScaleHeight)
    Case orVertical
    Line (0, Y)-(ScaleWidth, Y)
    End Select
    End If
    End Sub


    when i try to just make
    GetcursorPos Point
    ruler.rendertrackline point.x,point.y

    it fails

    i also tried to do this but it said 'Type Mismatch'

    GetCursorPos point
    kokox = point.X
    kokoy = point.Y

    webbrowser.ClientToWindow kokox, kokoy

  4. #4
    Join Date
    Jun 2001
    Location
    Mi
    Posts
    1,249
    You try casting your points using like Clng()?

  5. #5
    Join Date
    Dec 2001
    Posts
    6,332
    Ah!

    Then declare two variables as Single, and set them to the values returned in the Point structure. Another way would be like this:
    Code:
    Public Sub RenderTrackLine(ByVal X As Single, ByVal Y As Single)
    or
    Code:
    ruler.rendertrackline CSng(point.x), CSng(point.y)

  6. #6
    Join Date
    Aug 2002
    Location
    Athens , Greece
    Posts
    151
    thanks guys ! i solved it

    Public Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long

    Dim point As POINTAPI

    GetCursorPos point


    Call ScreenToClient(Form1.hwnd, point)
    kx = point.X
    ky = point.Y

    ruler_horiz.RenderTrackLine ScaleX(kx, vbPixels, vbTwips) - wbrowser.Left, ScaleY(ky, vbPixels, vbTwips) - wbrowser.TOp
    ruler_verti.RenderTrackLine ScaleX(kx, vbPixels, vbTwips) - wbrowser.Left, ScaleY(ky, vbPixels, vbTwips) - wbrowser.TOp

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured