Results 1 to 7 of 7

Thread: Cursor Position

  1. #1
    Guest
    hey there everybody... umm... quick question...
    i know how to get the raw cursor position on the
    screen with an API call... but is it possible to
    get cursor position _relative_ to a form or
    control, such as a picture box?

    Dubious, 2K

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    There's a api called clienttowindow, look here:
    http://forums.vb-world.net/showthrea...threadid=20557
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Guest
    Add the following to a Form with a Timer.
    Code:
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
    Private Type POINTAPI
        x As Long
        y As Long
    End Type
    
    Private Sub Form_Load()
        Timer1.Interval = 1
    End Sub
    
    Private Sub Timer1_Timer()
        Dim PT As POINTAPI
        GetCursorPos PT
        
        Cls
        Print PT.x - (Me.Left / Screen.TwipsPerPixelX) & "," & PT.y - (Me.Top / Screen.TwipsPerPixelY)
    End Sub

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    What are you trying to demonstrate meg? the declaration of ClienttoWindow but not the usage?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    Maybe I don't get the point, but for the same problem, i.e.
    getting the cursor coordinates (x,y) I'm just using standard VB stuff. The x and y will be given in the used scalemode (i.e. pixel, twips or whatever)
    /code
    sub picturebox.mouse_move
    ActualCursorX=X
    ActualCursorY=Y
    end sub
    /code
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  6. #6
    Guest

    the answer

    Private Declare Function SetCapture Lib "user32.dll" (ByVal hWnd As Long) As Long

    Private Declare Function ReleaseCapture Lib "user32.dll" (ByVal hWnd As Long) As Long

    Private Sub Command1_Click()
    SetCapture Picture1.hWnd
    End Sub

    Private Sub Command2_Click()
    ReleaseCapture Picture1.hWnd
    End Sub

    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Debug.Print X, Y
    End Sub

    by first click of the mouse the picturebox get the event and it make automaticaly a ReleasCapture

    by the next click of the mouse the right control or form get the event

  7. #7
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    if you use SetCapture & Release Capture, then other windows won't proccess clicks, it will all be sent to your program
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

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