改变客户区位置,并用NcHitTest实现没有caption的窗口也能方便移动,且窗口大小可改变

UINT CPane::OnNcHitTest(CPoint point)
{
    // TODO: Add your message handler code here and/or call default
    CRect rc;
    GetWindowRect(&rc);
    rc.InflateRect(-m_nEdgeWidth,-m_nEdgeWidth);
    if (rc.PtInRect(point))
    {
        return   HTCAPTION;
    }
    else
    {
        return  CWnd::OnNcHitTest(point);
    }
}



void CPane::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
{
    // TODO: Add your message handler code here and/or call default
    
    CWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
}

LRESULT CPane::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
    // TODO: Add your specialized code here and/or call the base class
    LPNCCALCSIZE_PARAMS pncc = (LPNCCALCSIZE_PARAMS)lParam;
    switch(message)
    {
    case WM_NCCALCSIZE:
        {
            int nEdgeWidth = m_nEdgeWidth + 4;
            pncc->rgrc[0].top += nEdgeWidth;
            pncc->rgrc[0].bottom -= nEdgeWidth;
            pncc->rgrc[0].left += nEdgeWidth;
            pncc->rgrc[0].right -= nEdgeWidth;
        }
    break;
    default:
        break;

    }
    return CWnd::DefWindowProc(message, wParam, lParam);
}

void CPane::OnNcPaint()
{
    // TODO: Add your message handler code here
    CWindowDC dc(this);
    CRect rc;
    GetWindowRect(rc);
    int w = rc.Width();
    int h = rc.Height();
    rc.left = 0;
    rc.top = 0;
    rc.bottom = h;
    rc.right = w;
    dc.FillSolidRect(rc, RGB(255,0,0));
    // Do not call CWnd::OnNcPaint() for painting messages
}

你可能感兴趣的:(改变客户区位置,并用NcHitTest实现没有caption的窗口也能方便移动,且窗口大小可改变)