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. scollbar in CStatic

scollbar in CStatic

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
7 Posts 2 Posters 0 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.
  • K Offline
    K Offline
    kk tvm
    wrote on last edited by
    #1

    Hi Friends I have created a class CImageViewer from CStatic. I also need scrolling of image in horizontal and vertical. I set scrollinfo for both scrolls and scrollbars (both) shown in my control. But it does not work. How can i solve this problem thanks in advance

    -kk.tvm-

    C 1 Reply Last reply
    0
    • K kk tvm

      Hi Friends I have created a class CImageViewer from CStatic. I also need scrolling of image in horizontal and vertical. I set scrollinfo for both scrolls and scrollbars (both) shown in my control. But it does not work. How can i solve this problem thanks in advance

      -kk.tvm-

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      Please explain what you mean by "it does not work" and provide relevant code snippet.

      Cédric Moonen Software developer
      Charting control [v3.0] OpenGL game tutorial in C++

      K 1 Reply Last reply
      0
      • C Cedric Moonen

        Please explain what you mean by "it does not work" and provide relevant code snippet.

        Cédric Moonen Software developer
        Charting control [v3.0] OpenGL game tutorial in C++

        K Offline
        K Offline
        kk tvm
        wrote on last edited by
        #3

        Hi Cédric Moonen, Basically my class is subclass of CStatic. I set scrollinfo using below code

        void CImageViewer::PreSubclassWindow()
        {
        CRect rect;
        GetClientRect( &rect );

        // set horizontal scroll bar
        SCROLLINFO si;
        ZeroMemory( &si, sizeof( SCROLLINFO ));
        si.cbSize = sizeof( SCROLLINFO );
        si.fMask = SIF\_ALL;
        si.nMin = 0;
        si.nMax = nScrWidth;
        si.nPage = rect.Width();
        si.nPos = 0;
        si.nTrackPos = 0;
        SetScrollInfo( SB\_HORZ, &si );
        CStatic::PreSubclassWindow();
        

        }

        and handled OnHScroll Message

        void CImageViewer::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
        {
        SCROLLINFO si;
        int nScrollPos = nPos;
        pScrollBar->GetScrollInfo( &si );
        int nCurPos = si.nPos;
        int nMin = si.nMin;
        int nMax = si.nMax;

        switch( nSBCode )
        {
        	case SB\_THUMBPOSITION:
        	case SB\_THUMBTRACK:
        		nScrollPos = si.nTrackPos;
        		break;
        	case SB\_LEFT:
        		nScrollPos = nMin;
        		break;
        	case SB\_RIGHT:
        		nScrollPos = nMax;
        		break;
        	case SB\_LINELEFT:
        		nScrollPos = nCurPos - 2;
        		break;
        	case SB\_LINERIGHT:
        		nScrollPos = nCurPos + 2;
        		break;
        	case SB\_PAGELEFT:
        		nScrollPos = nCurPos - 5;
        		break;
        	case SB\_PAGERIGHT:
        		nScrollPos = nCurPos + 5;
        		break;
        	case SB\_ENDSCROLL:
        		nScrollPos = nCurPos;
        		break;
        }
        
        if(nScrollPos < nMin) nScrollPos = nMin;
        else if(nScrollPos > nMax) nScrollPos = nMax;
        pScrollBar->SetScrollPos( nScrollPos );
        Invalidate();
        CStatic::OnHScroll(nSBCode, nPos, pScrollBar);
        

        }

        After this a scroll bar appears with my control. But i can't change scroll position.

        -kk.tvm-

        C 1 Reply Last reply
        0
        • K kk tvm

          Hi Cédric Moonen, Basically my class is subclass of CStatic. I set scrollinfo using below code

          void CImageViewer::PreSubclassWindow()
          {
          CRect rect;
          GetClientRect( &rect );

          // set horizontal scroll bar
          SCROLLINFO si;
          ZeroMemory( &si, sizeof( SCROLLINFO ));
          si.cbSize = sizeof( SCROLLINFO );
          si.fMask = SIF\_ALL;
          si.nMin = 0;
          si.nMax = nScrWidth;
          si.nPage = rect.Width();
          si.nPos = 0;
          si.nTrackPos = 0;
          SetScrollInfo( SB\_HORZ, &si );
          CStatic::PreSubclassWindow();
          

          }

          and handled OnHScroll Message

          void CImageViewer::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
          {
          SCROLLINFO si;
          int nScrollPos = nPos;
          pScrollBar->GetScrollInfo( &si );
          int nCurPos = si.nPos;
          int nMin = si.nMin;
          int nMax = si.nMax;

          switch( nSBCode )
          {
          	case SB\_THUMBPOSITION:
          	case SB\_THUMBTRACK:
          		nScrollPos = si.nTrackPos;
          		break;
          	case SB\_LEFT:
          		nScrollPos = nMin;
          		break;
          	case SB\_RIGHT:
          		nScrollPos = nMax;
          		break;
          	case SB\_LINELEFT:
          		nScrollPos = nCurPos - 2;
          		break;
          	case SB\_LINERIGHT:
          		nScrollPos = nCurPos + 2;
          		break;
          	case SB\_PAGELEFT:
          		nScrollPos = nCurPos - 5;
          		break;
          	case SB\_PAGERIGHT:
          		nScrollPos = nCurPos + 5;
          		break;
          	case SB\_ENDSCROLL:
          		nScrollPos = nCurPos;
          		break;
          }
          
          if(nScrollPos < nMin) nScrollPos = nMin;
          else if(nScrollPos > nMax) nScrollPos = nMax;
          pScrollBar->SetScrollPos( nScrollPos );
          Invalidate();
          CStatic::OnHScroll(nSBCode, nPos, pScrollBar);
          

          }

          After this a scroll bar appears with my control. But i can't change scroll position.

          -kk.tvm-

          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #4

          kk.tvm wrote:

          But i can't change scroll position.

          Do you mean that the scroll is displayed properly and that you can use it correctly but it doesn't have any effect on your drawing ? That's what I would guess by seeing your code, since you do not do anything with the scroll position (it's a local variable). What you need to do is remember the scroll position and use it when you draw your picture: you have to apply it as an offset to the picture. It's not because you added a scroll bar to a control that it will magically move when you use the scrollbar. You have to do that yourself by shifting the picture when the scroll is moved.

          Cédric Moonen Software developer
          Charting control [v3.0] OpenGL game tutorial in C++

          K 1 Reply Last reply
          0
          • C Cedric Moonen

            kk.tvm wrote:

            But i can't change scroll position.

            Do you mean that the scroll is displayed properly and that you can use it correctly but it doesn't have any effect on your drawing ? That's what I would guess by seeing your code, since you do not do anything with the scroll position (it's a local variable). What you need to do is remember the scroll position and use it when you draw your picture: you have to apply it as an offset to the picture. It's not because you added a scroll bar to a control that it will magically move when you use the scrollbar. You have to do that yourself by shifting the picture when the scroll is moved.

            Cédric Moonen Software developer
            Charting control [v3.0] OpenGL game tutorial in C++

            K Offline
            K Offline
            kk tvm
            wrote on last edited by
            #5

            Hi Cédric Moonen ok, i want to write code to scroll the image. what i mean.... Scrollbar is properly shown with control. But when i press arrow heads (left or right) or thumb it does not move or changed, like disabled. thanks in advance

            -kk.tvm-

            C 1 Reply Last reply
            0
            • K kk tvm

              Hi Cédric Moonen ok, i want to write code to scroll the image. what i mean.... Scrollbar is properly shown with control. But when i press arrow heads (left or right) or thumb it does not move or changed, like disabled. thanks in advance

              -kk.tvm-

              C Offline
              C Offline
              Cedric Moonen
              wrote on last edited by
              #6

              Perhaps your increments are too small compared to the full lenght of the scroll bar. Did you check with the debugger to see the values nMin, nMax, ... to see if everything seems correct ? And compare them to the -2/+2 you add when you click the arrow. I guess they are neglectable compared to nMax.

              Cédric Moonen Software developer
              Charting control [v3.0] OpenGL game tutorial in C++

              K 1 Reply Last reply
              0
              • C Cedric Moonen

                Perhaps your increments are too small compared to the full lenght of the scroll bar. Did you check with the debugger to see the values nMin, nMax, ... to see if everything seems correct ? And compare them to the -2/+2 you add when you click the arrow. I guess they are neglectable compared to nMax.

                Cédric Moonen Software developer
                Charting control [v3.0] OpenGL game tutorial in C++

                K Offline
                K Offline
                kk tvm
                wrote on last edited by
                #7

                Hi Cédric Moonen Thanks a lot of your valuable reply

                -kk.tvm-

                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