如何得到一个子窗口在其父窗口上的RECT?使用GetWindowRect和GetClientRect都不对啊

解决方案 »

  1.   

    GetWindowRect
    然后
    ScreenToClient
    试一试
      

  2.   

    CRect rect;
    pChild->GetWindowRect(&rect);
    pParent->ScreenToClient(&rect);
    如果是客户区:
    CRect rect;
    pChild->GetClientRect(&rect);
    pChild->ClientToScreen(&rect);
    pParent->ScreenToClient(&rect);
      

  3.   

    BOOL GetWindowRect( HWND hWnd, LPRECT lpRect );
    BOOL ScreenToClient( HWND hWnd, LPPOINT lpPoint);
      

  4.   

    GetWindowRect
    GetParent()->ScreenToClient
      

  5.   

    // 把屏幕坐标转换成当前客户区坐标
    void ScreenToClient(HWND hWnd, RECT *pRect)
    {
      ::ScreenToClient(hWnd, (LPPOINT)pRect);
      ::ScreenToClient(hWnd, ((LPPOINT)pRect) + 1);
    }// 获取hWnd在父窗口上的RECT
    RECT Rect;
    ::GetWindowRect(hWnd, &Rect);
    ::ScreenToClient(::GetParent(hWnd), &Rect);刚才随手写的,没测试过