1. 程式人生 > >MFC自繪視窗的時候,OnSize

MFC自繪視窗的時候,OnSize

void CDialogEx::OnSize(UINT nType, int cx, int cy)
{
    CDialog::OnSize(nType, cx, cy);

    //計算偏移
    INT nYPos=1;
    INT nXPos=cx-nCloseWidth;

    //設定位置
    m_rcButton[BST_CLOSE].SetRect(nXPos,nYPos,nXPos+nCloseWidth,nYPos+31);
    m_rcButton[BST_MAX_SIZE].SetRect(nXPos-nMaxWidth,nYPos,nXPos,nYPos+31);
    m_rcButton[BST_MIN_SIZE].SetRect(nXPos-nMaxWidth-nMaxWidth,nYPos,nXPos-nMaxWidth,nYPos+31);
}

Onsize cx 和 cy是新視窗的長寬

此處需要設定非客戶區的關閉,最小化,最大化這三個按鈕的位置。