MRM
MRM

Reputation: 571

mfc dialog button rect

I have a window with a button, and I want to anchor the button in one corner at window re-size, but somehow when I try to retrieve the button's rect, a debug assertion error is thrown.

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

    CRect winRect;
    GetWindowRect(&winRect);

    CRect buttonRect;
    m_btnAnulare.GetWindowRect(&buttonRect);

    m_btnAnulare.SetWindowPos(NULL,winRect.right - buttonRect.Width(), buttonRect.top, 0, 0, SWP_NOZORDER | SWP_NOMOVE);
}

The error is thrown at the line m_btnAnulare.GetWindowRect(&buttonRect); because it returns negative values (probably NULL).

m_btnAnulare is a CButton item declared in .h.

Upvotes: 0

Views: 1054

Answers (1)

Wolfgang Ziegler
Wolfgang Ziegler

Reputation: 1685

Most likely the CButton has not been created / subclassed yet. Did you check the m_hWnd member? Is it still nullptr. Check with GetSafeHwnd() != nullptr before accessing it.

Upvotes: 1

Related Questions