void CScrollHelper::UpdateScrollInfo() { if (m_attachWnd == nullptr) return; // Get the width/height of the attached wnd that includes the area // covered by the scrollbars (if any). The reason we need this is // because when scrollbars are present, both cx/cy and GetClientRect() // when accessed from OnSize() do not include the scrollbar covered // areas. In other words, their values are smaller than what you would // expect. CRect rect; GetClientRectSB(m_attachWnd, rect); CSize windowSize(rect.Width(), rect.Height()); // Update horizontal scrollbar. CSize deltaPos(0, 0); UpdateScrollBar(SB_HORZ, windowSize.cx, m_displaySize.cx, m_pageSize.cx, m_scrollPos.cx, deltaPos.cx); // Update vertical scrollbar. UpdateScrollBar(SB_VERT, windowSize.cy, m_displaySize.cy, m_pageSize.cy, m_scrollPos.cy, deltaPos.cy); // See if we need to scroll the window back in place. // This is needed to handle the case where the scrollbar is // moved all the way to the right for example, and controls // at the left side disappear from the view. Then the user // resizes the window wider until scrollbars disappear. Without // this code below, the controls off the page will be gone forever. if (deltaPos.cx != 0 || deltaPos.cy != 0) { m_attachWnd->ScrollWindow(deltaPos.cx, deltaPos.cy); } }
void CSampleDialogScrollHelper::UpdateScrollInfo() { if (0 == m_pWnd) return; CRect rect; GetClientRectSB(m_pWnd, rect); //GetClientRectSB_Ex( m_pWnd, m_display_size, rect ); CSize window_size(rect.Width(), rect.Height()); CSize delta_pos(0, 0); UpdateScrollBar(SB_HORZ, window_size.cx, m_display_size.cx, m_page_size.cx, m_scroll_pos.cx, delta_pos.cx); UpdateScrollBar(SB_VERT, window_size.cy, m_display_size.cy, m_page_size.cy, m_scroll_pos.cy, delta_pos.cy); if (delta_pos.cx != 0 || delta_pos.cy != 0) m_pWnd->ScrollWindow(delta_pos.cx, delta_pos.cy); }