HexEdit/GridCtrl_src/GridCtrl.cpp
void CGridCtrl::ResetScrollBars()
{
    // Force a refresh. 
    m_idTopLeftCell.row = -1;

    if (!m_bAllowDraw || !::IsWindow(GetSafeHwnd())) 
        return;

    CRect rect;

    // This would have caused OnSize event - Brian 
    //EnableScrollBars(SB_BOTH, FALSE); 

    GetClientRect(rect);

    if (rect.left == rect.right || rect.top == rect.bottom)
        return;

    if (IsVisibleVScroll())
        rect.right += GetSystemMetrics(SM_CXVSCROLL) + GetSystemMetrics(SM_CXBORDER);

    if (IsVisibleHScroll())
        rect.bottom += GetSystemMetrics(SM_CYHSCROLL) + GetSystemMetrics(SM_CYBORDER);

    rect.left += GetFixedColumnWidth();
    rect.top += GetFixedRowHeight();


    if (rect.left >= rect.right || rect.top >= rect.bottom)
    {
        EnableScrollBarCtrl(SB_BOTH, FALSE);
        return;
    }

    CRect VisibleRect(GetFixedColumnWidth(), GetFixedRowHeight(), rect.right, rect.bottom);
    CRect VirtualRect(GetFixedColumnWidth(), GetFixedRowHeight(), GetVirtualWidth(), GetVirtualHeight());


    // Removed to fix single row scrollbar problem (Pontus Goffe)
    // CCellRange visibleCells = GetUnobstructedNonFixedCellRange();
    // if (!IsValid(visibleCells)) return;

    //TRACE(_T("Visible: %d x %d, Virtual %d x %d.  H %d, V %d\n"), 
    //      VisibleRect.Width(), VisibleRect.Height(),
    //      VirtualRect.Width(), VirtualRect.Height(),
    //      IsVisibleHScroll(), IsVisibleVScroll());

    // If vertical scroll bar, horizontal space is reduced
    if (VisibleRect.Height() < VirtualRect.Height())
        VisibleRect.right -= ::GetSystemMetrics(SM_CXVSCROLL);
    // If horz scroll bar, vert space is reduced
    if (VisibleRect.Width() < VirtualRect.Width())
        VisibleRect.bottom -= ::GetSystemMetrics(SM_CYHSCROLL);

    // Recheck vertical scroll bar
    //if (VisibleRect.Height() < VirtualRect.Height())
    // VisibleRect.right -= ::GetSystemMetrics(SM_CXVSCROLL);

    if (VisibleRect.Height() < VirtualRect.Height())
    {
        EnableScrollBars(SB_VERT, TRUE); 
        m_nVScrollMax = VirtualRect.Height() - 1;
    }
    else
    {
        EnableScrollBars(SB_VERT, FALSE); 
        m_nVScrollMax = 0;
    }

    if (VisibleRect.Width() < VirtualRect.Width())
    {
        EnableScrollBars(SB_HORZ, TRUE); 
        m_nHScrollMax = VirtualRect.Width() - 1;
    }
    else
    {
        EnableScrollBars(SB_HORZ, FALSE); 
        m_nHScrollMax = 0;
    }

    ASSERT(m_nVScrollMax < INT_MAX && m_nHScrollMax < INT_MAX); // This should be fine

    /* Old code - CJM
    SCROLLINFO si;
    si.cbSize = sizeof(SCROLLINFO);
    si.fMask = SIF_PAGE;
    si.nPage = (m_nHScrollMax>0)? VisibleRect.Width() : 0;
    SetScrollInfo(SB_HORZ, &si, FALSE); 
    si.nPage = (m_nVScrollMax>0)? VisibleRect.Height() : 0;
    SetScrollInfo(SB_VERT, &si, FALSE);

    SetScrollRange(SB_VERT, 0, m_nVScrollMax, TRUE);
    SetScrollRange(SB_HORZ, 0, m_nHScrollMax, TRUE);
    */

    // New code - Paul Runstedler 
    SCROLLINFO si;
    si.cbSize = sizeof(SCROLLINFO);
    si.fMask = SIF_PAGE | SIF_RANGE;
    si.nPage = (m_nHScrollMax>0)? VisibleRect.Width() : 0;
    si.nMin = 0;
    si.nMax = m_nHScrollMax;
    SetScrollInfo(SB_HORZ, &si, TRUE);

    si.fMask |= SIF_DISABLENOSCROLL;
    si.nPage = (m_nVScrollMax>0)? VisibleRect.Height() : 0;
    si.nMin = 0;
    si.nMax = m_nVScrollMax;
    SetScrollInfo(SB_VERT, &si, TRUE);
}
// If resizing or cell counts/sizes change, call this - it'll fix up the scroll bars

If resizing or cell counts/sizes change, call this - it'll fix up the scroll bars
If resizing or cell counts / sizes change call this - it ' ll fix up the scroll bars
void CGridCtrl::ResetScrollBars()
{
    m_idTopLeftCell.row = -1;
    if (!m_bAllowDraw || !::IsWindow(GetSafeHwnd())) 
        return;
    CRect rect;
    GetClientRect(rect);
    if (rect.left == rect.right || rect.top == rect.bottom)
        return;
    if (IsVisibleVScroll())
        rect.right += GetSystemMetrics(SM_CXVSCROLL) + GetSystemMetrics(SM_CXBORDER);
    if (IsVisibleHScroll())
        rect.bottom += GetSystemMetrics(SM_CYHSCROLL) + GetSystemMetrics(SM_CYBORDER);
    rect.left += GetFixedColumnWidth();
    rect.top += GetFixedRowHeight();
    if (rect.left >= rect.right || rect.top >= rect.bottom)
    {
        EnableScrollBarCtrl(SB_BOTH, FALSE);
        return;
    }
    CRect VisibleRect(GetFixedColumnWidth(), GetFixedRowHeight(), rect.right, rect.bottom);
    CRect VirtualRect(GetFixedColumnWidth(), GetFixedRowHeight(), GetVirtualWidth(), GetVirtualHeight());
    if (VisibleRect.Height() < VirtualRect.Height())
        VisibleRect.right -= ::GetSystemMetrics(SM_CXVSCROLL);
    if (VisibleRect.Width() < VirtualRect.Width())
        VisibleRect.bottom -= ::GetSystemMetrics(SM_CYHSCROLL);
    if (VisibleRect.Height() < VirtualRect.Height())
    {
        EnableScrollBars(SB_VERT, TRUE); 
        m_nVScrollMax = VirtualRect.Height() - 1;
    }
    else
    {
        EnableScrollBars(SB_VERT, FALSE); 
        m_nVScrollMax = 0;
    }
    if (VisibleRect.Width() < VirtualRect.Width())
    {
        EnableScrollBars(SB_HORZ, TRUE); 
        m_nHScrollMax = VirtualRect.Width() - 1;
    }
    else
    {
        EnableScrollBars(SB_HORZ, FALSE); 
        m_nHScrollMax = 0;
    }
    ASSERT(m_nVScrollMax < INT_MAX && m_nHScrollMax < INT_MAX); 
    SCROLLINFO si;
    si.cbSize = sizeof(SCROLLINFO);
    si.fMask = SIF_PAGE | SIF_RANGE;
    si.nPage = (m_nHScrollMax>0)? VisibleRect.Width() : 0;
    si.nMin = 0;
    si.nMax = m_nHScrollMax;
    SetScrollInfo(SB_HORZ, &si, TRUE);
    si.fMask |= SIF_DISABLENOSCROLL;
    si.nPage = (m_nVScrollMax>0)? VisibleRect.Height() : 0;
    si.nMin = 0;
    si.nMax = m_nVScrollMax;
    SetScrollInfo(SB_VERT, &si, TRUE);
}
void CGridCtrl :: ResetScrollBars ( ) { m_idTopLeftCell . row = -1 ; if ( ! m_bAllowDraw || ! :: IsWindow ( GetSafeHwnd ( ) ) ) return ; CRect rect ; GetClientRect ( rect ) ; if ( rect . left == rect . right || rect . top == rect . bottom ) return ; if ( IsVisibleVScroll ( ) ) rect . right += GetSystemMetrics ( SM_CXVSCROLL ) + GetSystemMetrics ( SM_CXBORDER ) ; if ( IsVisibleHScroll ( ) ) rect . bottom += GetSystemMetrics ( SM_CYHSCROLL ) + GetSystemMetrics ( SM_CYBORDER ) ; rect . left += GetFixedColumnWidth ( ) ; rect . top += GetFixedRowHeight ( ) ; if ( rect . left >= rect . right || rect . top >= rect . bottom ) { EnableScrollBarCtrl ( SB_BOTH , FALSE ) ; return ; } CRect VisibleRect ( GetFixedColumnWidth ( ) , GetFixedRowHeight ( ) , rect . right , rect . bottom ) ; CRect VirtualRect ( GetFixedColumnWidth ( ) , GetFixedRowHeight ( ) , GetVirtualWidth ( ) , GetVirtualHeight ( ) ) ; if ( VisibleRect . Height ( ) < VirtualRect . Height ( ) ) VisibleRect . right -= :: GetSystemMetrics ( SM_CXVSCROLL ) ; if ( VisibleRect . Width ( ) < VirtualRect . Width ( ) ) VisibleRect . bottom -= :: GetSystemMetrics ( SM_CYHSCROLL ) ; if ( VisibleRect . Height ( ) < VirtualRect . Height ( ) ) { EnableScrollBars ( SB_VERT , TRUE ) ; m_nVScrollMax = VirtualRect . Height ( ) - 1 ; } else { EnableScrollBars ( SB_VERT , FALSE ) ; m_nVScrollMax = 0 ; } if ( VisibleRect . Width ( ) < VirtualRect . Width ( ) ) { EnableScrollBars ( SB_HORZ , TRUE ) ; m_nHScrollMax = VirtualRect . Width ( ) - 1 ; } else { EnableScrollBars ( SB_HORZ , FALSE ) ; m_nHScrollMax = 0 ; } ASSERT ( m_nVScrollMax < INT_MAX && m_nHScrollMax < INT_MAX ) ; SCROLLINFO si ; si . cbSize = sizeof ( SCROLLINFO ) ; si . fMask = SIF_PAGE | SIF_RANGE ; si . nPage = ( m_nHScrollMax > 0 ) ? VisibleRect . Width ( ) : 0 ; si . nMin = 0 ; si . nMax = m_nHScrollMax ; SetScrollInfo ( SB_HORZ , & si , TRUE ) ; si . fMask |= SIF_DISABLENOSCROLL ; si . nPage = ( m_nVScrollMax > 0 ) ? VisibleRect . Height ( ) : 0 ; si . nMin = 0 ; si . nMax = m_nVScrollMax ; SetScrollInfo ( SB_VERT , & si , TRUE ) ; }
If resizing or cell counts/sizes change, call this - it'll fix up the scroll bars
If resizing or cell counts / sizes change call this - it ' ll fix up the scroll bars
// Force a refresh. 
 // This would have caused OnSize event - Brian 
 //EnableScrollBars(SB_BOTH, FALSE); 
 // Removed to fix single row scrollbar problem (Pontus Goffe)
 // CCellRange visibleCells = GetUnobstructedNonFixedCellRange();
 // if (!IsValid(visibleCells)) return;
 //TRACE(_T("Visible: %d x %d, Virtual %d x %d.  H %d, V %d\n"), 
 //      VisibleRect.Width(), VisibleRect.Height(),
 //      VirtualRect.Width(), VirtualRect.Height(),
 //      IsVisibleHScroll(), IsVisibleVScroll());
 // If vertical scroll bar, horizontal space is reduced
 // If horz scroll bar, vert space is reduced
 // Recheck vertical scroll bar
 //if (VisibleRect.Height() < VirtualRect.Height())
 // VisibleRect.right -= ::GetSystemMetrics(SM_CXVSCROLL);
 // This should be fine
 /* Old code - CJM
    SCROLLINFO si;
    si.cbSize = sizeof(SCROLLINFO);
    si.fMask = SIF_PAGE;
    si.nPage = (m_nHScrollMax>0)? VisibleRect.Width() : 0;
    SetScrollInfo(SB_HORZ, &si, FALSE); 
    si.nPage = (m_nVScrollMax>0)? VisibleRect.Height() : 0;
    SetScrollInfo(SB_VERT, &si, FALSE);

    SetScrollRange(SB_VERT, 0, m_nVScrollMax, TRUE);
    SetScrollRange(SB_HORZ, 0, m_nHScrollMax, TRUE);
    */ // New code - Paul Runstedler 
