Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)End Sub
不能用吗?

解决方案 »

  1.   

    GetCursorPos
    The GetCursorPos function retrieves the cursor's position, in screen coordinates. BOOL GetCursorPos(
      LPPOINT lpPoint   // cursor position
    );
    Parameters
    lpPoint 
    [out] Pointer to a POINT structure that receives the screen coordinates of the cursor. 
    Return Values
    If the function succeeds, the return value is nonzero.If the function fails, the return value is zero. To get extended error information, call GetLastError.Res
    The cursor position is always specified in screen coordinates and is not affected by the mapping mode of the window that contains the cursor. The calling process must have WINSTA_READATTRIBUTES access to the window station. Example Code
    For an example, see Using the Keyboard to Move the Cursor. Requirements 
      Windows NT/2000/XP: Included in Windows NT 3.1 and later.
      Windows 95/98/Me: Included in Windows 95 and later.
      Header: Declared in Winuser.h; include Windows.h.
      Library: Use User32.lib.See Also
    Cursors Overview, Cursor Functions, ClipCursor, GetCursorInfo, POINT, SetCursor, SetCursorPos, ShowCursor 
      

  2.   

    Public formX, formY As Double
    Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Public Type POINTAPI
            x As Long
            y As Long
    End Type使用时:
              Dim mouseP As POINTAPI
              Call GetCursorPos(mouseP)
              formX = mouseP.X 
              formY = mouseP.Y 
      

  3.   

    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Type POINTAPI
            x As Long
            y As Long
    End Type
    Private Sub Form_Load()
    Dim iPos As POINTAPI
    Call GetCursorPos(iPos)
    MsgBox iPos.x
    MsgBox iPos.yEnd Sub
      

  4.   

    GetCursorPos VB声明 
    Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long 
    说明 
    获取鼠标指针的当前位置 
    返回值 
    Long,非零表示成功,零表示失败。会设置GetLastError 
    参数表 
    参数 类型及说明 
    lpPoint POINTAPI,随同指针在屏幕像素坐标中的位置载入的一个结构 POINTAPI 
    类型定义 
    Type POINTAPI
    x As Long
    y As Long
    End Type 
    说明 
    POINTAPI结构对应于windows的POINT结构,在vb中定义为POINTAPI,从而避免与vb的Point关键字冲突,用于描叙一个位置(即屏幕点),与RECT结构相同,x和y字段的单位取决于准备使用的对象与api函数  
      

  5.   

    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Type POINTAPI
            x As Long
            y As Long
    End Type Dim mPt As POINTAPI
        GetCursorPos mPt
        xx = mPt.x * Screen.TwipsPerPixelX 
        yy = mPt.y * Screen.TwipsPerPixelY
      

  6.   

    Dim TempP as pointapi
    Dim TempRect as rectGetCursorPos TempP
    GetWindowRect form1.hWnd, TempRect'if 想得到基于窗体的坐标 Then
    TempP.x=TempP.x-TempRect.Left
    TempP.y=TempP.y-TempRect.Top'ElseIf 想得到基于窗体客户区的坐标 Then
    ScreenToClient TempP'End If坐标x=TempP.x '* Screen.TwipsPerPixelX '如果想得到Twips为单位的坐标,就要乘以 Screen.TwipsPerPixelX
    坐标y=TempP.y * Screen.TwipsPerPixelY '如果想得到Twips为单位的坐标,就要乘以 Screen.TwipsPerPixelY