Menu

CResizer and restoring a minimized dailog

Help
DarkAkuma
2013-03-03
2014-02-26
  • DarkAkuma

    DarkAkuma - 2013-03-03

    For several windows in my project I use modeless dialogs and CResizer with them. But there exists an issue that when you minimize such a dialog then restore it, everything is off a bit with empty space added on the bottom and the right of the dialog. I believe it has to do with the scrollbars, as the width and height of them would match up. But this happens with the dialog no matter what size it is before and after its minimized.

    Manually resizing the window fixes it visually. But I would love to know of a code fix for it. Either repairing the problem or a workaround.

     
  • David

    David - 2014-02-26

    I've submitted a fix for this problem. It involved a slight modification to CResizer::RecalcLayout. It turns out that the calls to SetScrollInfo sometimes changed the size of the dialog's client area.

    CRisizer::RecalcLayout now looks like this:

    void inline CResizer::RecalcLayout()
    // Repositions the child windows. Call this function when handling
    // the WM_SIZE message in the parent window.
    {
        assert (m_rcInit.Width() > 0 && m_rcInit.Height() > 0);
        assert (NULL != m_pParent);
    
        CRect rcCurrent = m_pParent->GetClientRect();
    
        // Adjust the scrolling if required
        m_xScrollPos = MIN(m_xScrollPos, MAX(0, m_rcMin.Width()  - rcCurrent.Width() ) );
        m_yScrollPos = MIN(m_yScrollPos, MAX(0, m_rcMin.Height() - rcCurrent.Height()) );
        SCROLLINFO si = {0};
        si.cbSize = sizeof(si);
        si.fMask  = SIF_RANGE | SIF_PAGE | SIF_POS;
        si.nMax   = m_rcMin.Width();
        si.nPage  = rcCurrent.Width();
        si.nPos   = m_xScrollPos;
        m_pParent->SetScrollInfo(SB_HORZ, si, TRUE);
        si.nMax   = m_rcMin.Height();
        si.nPage  = rcCurrent.Height();
        si.nPos   = m_yScrollPos;
        m_pParent->SetScrollInfo(SB_VERT, si, TRUE);
    
        // Note: calls to SetScrollInfo may have changed the client rect, so
        // we get it again.
        rcCurrent = m_pParent->GetClientRect();
    
        // etc
    

    You can download the updated code using SVN, or simply make the modification listed above.

    Best regards,
    David

     

    Last edit: David 2014-02-26

Log in to post a comment.

MongoDB Logo MongoDB