Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Horizontal scroll and vertical scroll--difference ?

Horizontal scroll and vertical scroll--difference ?

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BeakX
    wrote on last edited by
    #1

    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); }

    E 1 Reply Last reply
    0
    • B BeakX

      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); }

      E Offline
      E Offline
      EXTEIDE
      wrote on last edited by
      #2

      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

      B 1 Reply Last reply
      0
      • E EXTEIDE

        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

        B Offline
        B Offline
        BeakX
        wrote on last edited by
        #3

        sorry i have to ask this...but how do i calculate it ? Thanks

        E 1 Reply Last reply
        0
        • B BeakX

          sorry i have to ask this...but how do i calculate it ? Thanks

          E Offline
          E Offline
          EXTEIDE
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups