我用GetCursorPos 的到的坐标好象是屏幕的坐标 , 我现在想要得到某窗口内的坐标 请问该如何实现

解决方案 »

  1.   

    用下面的API转换就行了
    Public Declare Function ScreenToClient Lib "user32" Alias "ScreenToClient" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
      

  2.   

    看看这个代码。
    Private Type RECT
        left As Long
        top As Long
        right As Long
        bottom As Long
    End Type
    Private Type POINT
        x As Long
        y As Long
    End Type
    Private Declare Sub ClipCursor Lib "user32" (lpRect As RECT)
    Private Declare Sub GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT)
    Private Declare Sub ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINT)
    Private Declare Sub OffsetRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long)
    Private Declare Function ClipCursorBynum& Lib "user32" Alias "ClipCursor" (ByVal lpRect As Long)Public Sub LockMouse()
        'Limits the Cursor movement to within the form.
        Dim client As RECT
        Dim upperleft As POINT
        'Get information about our wndow
        GetClientRect me.hwnd, client
        upperleft.x = client.left
        upperleft.y = client.top
        ClientToScreen me.hwnd, upperleft
        OffsetRect client, upperleft.x, upperleft.y
        ClipCursor client
    End Sub
    Public Sub UpMouse()
    ClipCursorBynum& 0
    End Sub