Home All Groups Group Topic Archive Search About
Author
4 Feb 2006 6:01 PM
KAB
Hi:

Does anyone know if Visual Basic has a command that positions the mouse
pointer to a specific location on a form? 

Thanks
KAB

Author
5 Feb 2006 12:01 AM
Mike D Sutton
> Does anyone know if Visual Basic has a command that positions the mouse
> pointer to a specific location on a form?

VB doesn't natively, however by using the ScreenToClient() and
SetCursorPos() API calls you can achieve the same effect:

'***
Private Declare Function ClientToScreen Lib "User32.dll" (ByVal hWnd As
Long, ByRef lpPoint As PointAPI) As Long
Private Declare Function SetCursorPos Lib "User32.dll" (ByVal X As Long,
ByVal Y As Long) As Long

Private Type PointAPI
    X As Long
    Y As Long
End Type

Private Sub Form_Load()
    ' Move cursor to top-left of form
    Call SetWindowCursorPos(Me.hWnd, 0, 0)
End Sub

Private Function SetWindowCursorPos(ByVal inWnd As Long, _
    ByVal inX As Long, ByVal inY As Long) As Boolean
    Dim CurPos As PointAPI

    CurPos.X = inX
    CurPos.Y = inY

    If (ClientToScreen(inWnd, CurPos)) Then
        Call SetCursorPos(CurPos.X, CurPos.Y)
        SetWindowCursorPos = True
    End If
End Function
'***

Hope this helps,

    Mike


- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Author
5 Feb 2006 1:51 PM
KAB
Thanks Mike:
Your response is a little bit above me, but I'll give it a try.  I really
appreciate your response.
Kurt



Show quoteHide quote
"Mike D Sutton" wrote:

> > Does anyone know if Visual Basic has a command that positions the mouse
> > pointer to a specific location on a form?
>
> VB doesn't natively, however by using the ScreenToClient() and
> SetCursorPos() API calls you can achieve the same effect:
>
> '***
> Private Declare Function ClientToScreen Lib "User32.dll" (ByVal hWnd As
> Long, ByRef lpPoint As PointAPI) As Long
> Private Declare Function SetCursorPos Lib "User32.dll" (ByVal X As Long,
> ByVal Y As Long) As Long
>
> Private Type PointAPI
>     X As Long
>     Y As Long
> End Type
>
> Private Sub Form_Load()
>     ' Move cursor to top-left of form
>     Call SetWindowCursorPos(Me.hWnd, 0, 0)
> End Sub
>
> Private Function SetWindowCursorPos(ByVal inWnd As Long, _
>     ByVal inX As Long, ByVal inY As Long) As Boolean
>     Dim CurPos As PointAPI
>
>     CurPos.X = inX
>     CurPos.Y = inY
>
>     If (ClientToScreen(inWnd, CurPos)) Then
>         Call SetCursorPos(CurPos.X, CurPos.Y)
>         SetWindowCursorPos = True
>     End If
> End Function
> '***
>
> Hope this helps,
>
>     Mike
>
>
>  - Microsoft Visual Basic MVP -
> E-Mail: ED***@mvps.org
> WWW: Http://EDais.mvps.org/
>
>
>