Results 1 to 8 of 8

Thread: Mouse Pos Relative to The form..

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Posts
    482

    Mouse Pos Relative to The form..

    Hey, I am using the GETCURSORPOS on the computer.. and It gets the mouse's pos relative to the screen..

    I need it so if the mouse is over the top left of the form, it'll be 0,0
    bottomright would be width,height


    I need to use this.. because the X,Y of the form itself.. just wouldn't always capture if another control was under the mouse..

    then I also needed so it would capture the points AROUND the form..

    anyhelp is good help =)

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Posts
    482
    I have a bad headache so this is hard to figure out..

    Code:
    Public Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long
    Type PointAPI
            X As Long
            Y As Long
    End Type
    
    Dim Pos As PointAPI
    GetCursorPos Pos
    Me.Cls
    'Space from the form
    Me.Print Pos.X & "<>" & Me.Left + 3 'FROM LEFT
    Me.Print Pos.X & "<>" & (Me.Left + Me.ScaleWidth) - 3 'FROMRIGHT
    Me.Print Pos.Y & "<>" & Me.Top + 3 'FROM TOP
    Me.Print Pos.Y & "<>" & Me.Top + 19 'FROM BOTTOM

    Anyways: this works FINE if the Form's TOP and LEFT = 0

    but if it doesn't, then it doesn't work too good

    anybody know what i am missing?

  3. #3
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    Subtract the left and top from the x and y, if it's negative it's left of, or above the form, and postive it's below the upper edge, or right of the left edge.

    I think you get it.
    (if you get weird measurements times x and y by screen.twipsperpixel)

    May the force be with you?

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Posts
    482
    I can't get it to work correctly ..

    ehhhhh

  5. #5
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    I was feeling nice:
    Code:
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long
    Private Type PointAPI
            X As Long
            Y As Long
    End Type
    
    Private Pos As PointAPI
    
    Private Sub Timer1_Timer()
    GetCursorPos Pos
    Caption = Pos.X - (Left / Screen.TwipsPerPixelX) & "," & Pos.Y - (Top / Screen.TwipsPerPixelY)
    End Sub
    By the way, you can put all that in Form1, you don't need a bas when you declare as Private.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Posts
    482
    Will that return the X,Y of the screen into PIXELS?

  7. #7
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    All right, here it is:

    Code:
    'Declarations
    
    Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Public Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
    
    'Code
    
    Dim MyPoint As POINTAPI
    
    GetCursorPos MyPoint
    ScreenToClient Me.hwnd, MyPoint
    X_Pos = MyPoint.X - 5
    Y_Pos = MyPoint.Y - 5
    Not sure about the -5 stuff, they were with the code I found but I'm not sure if they're needed.

    Hope that helped
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Posts
    482
    Hey, it works.. thanks

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