-
April 2nd, 2003, 08:54 AM
#1
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.
-
April 2nd, 2003, 09:01 AM
#2
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.
-
April 2nd, 2003, 09:09 AM
#3
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
-
April 2nd, 2003, 09:17 AM
#4
You try casting your points using like Clng()?
-
April 2nd, 2003, 09:19 AM
#5
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)
-
April 2nd, 2003, 09:53 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|