|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Mouse PointerHi:
Does anyone know if Visual Basic has a command that positions the mouse pointer to a specific location on a form? Thanks KAB > Does anyone know if Visual Basic has a command that positions the mouse VB doesn't natively, however by using the ScreenToClient() and > pointer to a specific location on a form? 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/ 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/ > > > |
|||||||||||||||||||||||