Horizontal scroll and vertical scroll--difference ?
-
i am using the code below which i copied from somewhere for an application which uses a vertical scrollable child. now i realise my application need a horizontal scroll also.....can i use back the same code ? void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { int nDelta; int nMaxPos = m_rcOriginalRect.Height() - m_nCurHeight; switch (nSBCode) { case SB_LINEDOWN: if (m_nScrollPos >= nMaxPos) return; nDelta = min(max(nMaxPos/20,5),nMaxPos-m_nScrollPos); break; case SB_LINEUP: if (m_nScrollPos <= 0) return; nDelta = -min(max(nMaxPos/20,5),m_nScrollPos); break; case SB_PAGEDOWN: if (m_nScrollPos >= nMaxPos) return; nDelta = min(max(nMaxPos/10,5),nMaxPos-m_nScrollPos); break; case SB_THUMBTRACK: case SB_THUMBPOSITION: nDelta = (int)nPos - m_nScrollPos; break; case SB_PAGEUP: if (m_nScrollPos <= 0) return; nDelta = -min(max(nMaxPos/10,5),m_nScrollPos); break; default: return; } m_nScrollPos += nDelta; SetScrollPos(SB_VERT,m_nScrollPos,TRUE); ScrollWindow(0,-nDelta); CDialog::OnVScroll(nSBCode, nPos, pScrollBar); }
-
i am using the code below which i copied from somewhere for an application which uses a vertical scrollable child. now i realise my application need a horizontal scroll also.....can i use back the same code ? void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { int nDelta; int nMaxPos = m_rcOriginalRect.Height() - m_nCurHeight; switch (nSBCode) { case SB_LINEDOWN: if (m_nScrollPos >= nMaxPos) return; nDelta = min(max(nMaxPos/20,5),nMaxPos-m_nScrollPos); break; case SB_LINEUP: if (m_nScrollPos <= 0) return; nDelta = -min(max(nMaxPos/20,5),m_nScrollPos); break; case SB_PAGEDOWN: if (m_nScrollPos >= nMaxPos) return; nDelta = min(max(nMaxPos/10,5),nMaxPos-m_nScrollPos); break; case SB_THUMBTRACK: case SB_THUMBPOSITION: nDelta = (int)nPos - m_nScrollPos; break; case SB_PAGEUP: if (m_nScrollPos <= 0) return; nDelta = -min(max(nMaxPos/10,5),m_nScrollPos); break; default: return; } m_nScrollPos += nDelta; SetScrollPos(SB_VERT,m_nScrollPos,TRUE); ScrollWindow(0,-nDelta); CDialog::OnVScroll(nSBCode, nPos, pScrollBar); }
Yes you do as same way in OnHScroll handler. But ratio would be different so you have to calc it. Enjoy:rose:
Anderson Sheen Reduce a time to develop your environment. It's a free! http://www.exteide.com
-
Yes you do as same way in OnHScroll handler. But ratio would be different so you have to calc it. Enjoy:rose:
Anderson Sheen Reduce a time to develop your environment. It's a free! http://www.exteide.com
-
there are several way to calc it. it depends on what kind of coordinate system you are using. you have to consider whether absolute or relative, whether integer or float, whether zoom in/out feature will be added or not, and etc. scrollbar control has its absolute coordinate like 'range' like 0~255 or 0~32767. this is physical coordinate. So your logical coordinate in your mind has to be matched to physical coordinate as correct ratio. for example, if the maximum size of logical map is 327680 pixel and physical scroll range is 0~32767, then current pixel position to draw to screen has to be scrollbar position * 10. so if the scrollbar position is 16384 (1/2 of range), then current map position is 16384 * 10 = 163840. and you also have to consider view window width, height. anyway, scroll bar controling is a little complex and i'd like to suggest you to research formal way. there are lectures on the internet. Enjoy:rose:
Anderson Sheen Reduce a time to develop your IDE. It's a free! http://www.exteide.com