void CSampleDialogScrollHelper::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { if (0 == m_pWnd) return; const int line_offset = 60; int delta_pos = 0; switch (nSBCode) { case SB_LINEUP: delta_pos = -line_offset; break; case SB_LINEDOWN: delta_pos = line_offset; break; case SB_PAGEUP: delta_pos = -m_page_size.cy; break; case SB_PAGEDOWN: delta_pos = m_page_size.cy; break; case SB_THUMBTRACK: delta_pos = Get32BitScrollPos(SB_VERT, pScrollBar) - m_scroll_pos.cy; break; case SB_THUMBPOSITION: delta_pos = Get32BitScrollPos(SB_VERT, pScrollBar) - m_scroll_pos.cy; break; default: return; } int new_scroll_pos = m_scroll_pos.cy + delta_pos; if (new_scroll_pos < 0) delta_pos = -m_scroll_pos.cy; int max_scroll_pos = m_display_size.cy - m_page_size.cy; if (new_scroll_pos > max_scroll_pos) delta_pos = max_scroll_pos - m_scroll_pos.cy; if (delta_pos != 0) { m_scroll_pos.cy += delta_pos; m_pWnd->SetScrollPos(SB_VERT, m_scroll_pos.cy, TRUE); m_pWnd->ScrollWindow(0, -delta_pos); } }
void CScrollHelper::OnVScroll(UINT nSBCode, UINT /*nPos*/, CScrollBar* pScrollBar) { if (m_attachWnd == nullptr) return; const int lineOffset = 60; // Compute the desired change or delta in scroll position. int deltaPos = 0; switch (nSBCode) { case SB_LINEUP: // Up arrow button on scrollbar was pressed. deltaPos = -lineOffset; break; case SB_LINEDOWN: // Down arrow button on scrollbar was pressed. deltaPos = lineOffset; break; case SB_PAGEUP: // User clicked inbetween up arrow and thumb. deltaPos = -m_pageSize.cy; break; case SB_PAGEDOWN: // User clicked inbetween thumb and down arrow. deltaPos = m_pageSize.cy; break; case SB_THUMBTRACK: // Scrollbar thumb is being dragged. deltaPos = Get32BitScrollPos(SB_VERT, pScrollBar) - m_scrollPos.cy; break; case SB_THUMBPOSITION: // Scrollbar thumb was released. deltaPos = Get32BitScrollPos(SB_VERT, pScrollBar) - m_scrollPos.cy; break; default: // We don't process other scrollbar messages. return; } // Compute the new scroll position. int newScrollPos = m_scrollPos.cy + deltaPos; // If the new scroll position is negative, we adjust // deltaPos in order to scroll the window back to origin. if (newScrollPos < 0) deltaPos = -m_scrollPos.cy; // If the new scroll position is greater than the max scroll position, // we adjust deltaPos in order to scroll the window precisely to the // maximum position. int maxScrollPos = m_displaySize.cy - m_pageSize.cy; if (newScrollPos > maxScrollPos) deltaPos = maxScrollPos - m_scrollPos.cy; // Scroll the window if needed. if (deltaPos != 0) { m_scrollPos.cy += deltaPos; m_attachWnd->SetScrollPos(SB_VERT, m_scrollPos.cy, TRUE); m_attachWnd->ScrollWindow(0, -deltaPos); } }
void CScrollHelper::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { if ( m_attachWnd == NULL ) return; const int lineOffset = 60; // Compute the desired change or delta in scroll position. int deltaPos = 0; switch( nSBCode ) { case SB_LINELEFT: // Left scroll arrow was pressed. deltaPos = -lineOffset; break; case SB_LINERIGHT: // Right scroll arrow was pressed. deltaPos = lineOffset; break; case SB_PAGELEFT: // User clicked inbetween left arrow and thumb. deltaPos = -m_pageSize.cx; break; case SB_PAGERIGHT: // User clicked inbetween thumb and right arrow. deltaPos = m_pageSize.cx; break; case SB_THUMBTRACK: // Scrollbar thumb is being dragged. deltaPos = Get32BitScrollPos(SB_HORZ, pScrollBar) - m_scrollPos.cx; break; case SB_THUMBPOSITION: // Scrollbar thumb was released. deltaPos = Get32BitScrollPos(SB_HORZ, pScrollBar) - m_scrollPos.cx; break; default: // We don't process other scrollbar messages. return; } // Compute the new scroll position. int newScrollPos = m_scrollPos.cx + deltaPos; // If the new scroll position is negative, we adjust // deltaPos in order to scroll the window back to origin. if ( newScrollPos < 0 ) deltaPos = -m_scrollPos.cx; // If the new scroll position is greater than the max scroll position, // we adjust deltaPos in order to scroll the window precisely to the // maximum position. int maxScrollPos = m_displaySize.cx - m_pageSize.cx; if ( newScrollPos > maxScrollPos ) deltaPos = maxScrollPos - m_scrollPos.cx; // Scroll the window if needed. if ( deltaPos != 0 ) { m_scrollPos.cx += deltaPos; m_attachWnd->SetScrollPos(SB_HORZ, m_scrollPos.cx, TRUE); DoTheScroll(-deltaPos, 0); } }