GetCursorPos VB声明 
Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long 
说明 
获取鼠标指针的当前位置 
返回值 
Long,非零表示成功,零表示失败。会设置GetLastError 
参数表 
参数 类型及说明 
lpPoint POINTAPI,随同指针在屏幕像素坐标中的位置载入的一个结构 先得到屏幕坐标,再计算不就可以了吗??

解决方案 »

  1.   

    Private Declare Function SetCapture Lib "user32" Alias "SetCapture" (ByVal hwnd As Long) As Long
    http://ygyuan.go.163.com/
    http://ygyuan.3322.net/
      

  2.   


    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
    Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    Private Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End TypePrivate Type POINTAPI
            x As Long
            y As Long
    End Type
    Private Sub Label1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
        Dim lPos As POINTAPI
        Dim lhWnd As Long
        Dim lRect As RECT
        Dim lX As Long, lY As Long
        GetCursorPos lPos
        lhWnd = WindowFromPoint(lPos.x, lPos.y)
        GetWindowRect lhWnd, lRect
        lX = lPos.x - lRect.Left
        lY = lPos.y - lRect.Top
        Debug.Print lX, lY
    End Sub
      

  3.   

    GetcursorPos(point) 得到全屏幕的坐标.
    ScreenToClient(hwnd,point) 得到全屏幕的坐标对应在具体窗口的坐标.
      

  4.   

    这太麻烦了,这是得到象素的坐标值啊
    和VB中的单位怎么换算?
    而且,如果MSHFlexGrid有滚动条
    那么如何才能知道鼠标右键放开的时候究竟是在哪个单元格上方呢?
    我需要知道的就是鼠标右键放开的时候究竟是在哪个单元格上方。
      

  5.   

    上例是拖到任何控件上都可以,如果只是MSFlexGrid,参考下例
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
    Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    Private Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End TypePrivate Type POINTAPI
            x As Long
            y As Long
    End Type
    Private Sub Label1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
        Dim lPos As POINTAPI
        Dim lhWnd As Long
        Dim lRect As RECT
        Dim lX As Long, lY As Long
        GetCursorPos lPos
        lhWnd = WindowFromPoint(lPos.x, lPos.y)
        If lhWnd = MSFlexGrid1.hwnd Then 'changed
            GetWindowRect lhWnd, lRect
            lX = lPos.x - lRect.Left
            lY = lPos.y - lRect.Top
            MsgBox (Str(lX) + "," + Str(lY))
        End If
            
    End Sub
      

  6.   

    Private Sub MSHFlexGrid1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    MsgBox x+ "," + y
    End Sub