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. CHtmlView & ScrollBar

CHtmlView & ScrollBar

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 Posts 2 Posters 1 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.
  • J Offline
    J Offline
    jeremysay
    wrote on last edited by
    #1

    Hello, In MDI project, i work with CHtmlView and i want to add scrollbar to my childs windows. so i do :

    BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
    {
    	cs.style = WS_VSCROLL | WS_HSCROLL |WS_OVERLAPPEDWINDOW;
    	m_HScroll.Create(SBS_BOTTOMALIGN ,CRect(0,0,0,0),this,ID_HSCROLL);
    }
    
    int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
            m_HScroll.SetScrollRange(0,50,TRUE);
            m_HScroll.SetScrollPos(0,TRUE);
    }
    

    When the prorgram start, i have scrollbars in my child window, greats ! I can detect :

    void CChildFrame::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
    void CChildFrame::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
    

    but when i do a m_HScroll.SetScrollPos(10,TRUE); the ScrollBar don't move it is always in the left. the user can use the scrollbar (it always stay in left position), i can detect when the user click on it and i can move my view, but i can't move my scrollbar. if i do m_HScroll.SetScrollPos(10,TRUE); and int toto = m_HScroll.GetScrollPos() toto == 10 ! but "at the screen" the scrollbar stay in the left. Have you any idea ? PS: excuse for bad english

    M 1 Reply Last reply
    0
    • J jeremysay

      Hello, In MDI project, i work with CHtmlView and i want to add scrollbar to my childs windows. so i do :

      BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
      {
      	cs.style = WS_VSCROLL | WS_HSCROLL |WS_OVERLAPPEDWINDOW;
      	m_HScroll.Create(SBS_BOTTOMALIGN ,CRect(0,0,0,0),this,ID_HSCROLL);
      }
      
      int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
      {
              m_HScroll.SetScrollRange(0,50,TRUE);
              m_HScroll.SetScrollPos(0,TRUE);
      }
      

      When the prorgram start, i have scrollbars in my child window, greats ! I can detect :

      void CChildFrame::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
      void CChildFrame::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
      

      but when i do a m_HScroll.SetScrollPos(10,TRUE); the ScrollBar don't move it is always in the left. the user can use the scrollbar (it always stay in left position), i can detect when the user click on it and i can move my view, but i can't move my scrollbar. if i do m_HScroll.SetScrollPos(10,TRUE); and int toto = m_HScroll.GetScrollPos() toto == 10 ! but "at the screen" the scrollbar stay in the left. Have you any idea ? PS: excuse for bad english

      M Offline
      M Offline
      Mike Upton
      wrote on last edited by
      #2

      I think the problem is that m_hScroll isn't actually the scroll-bar that you see in the window. When you set the style (cs.style() in PreCreateWindow to WS_VSCROLL | WS_HSCROLL the window creates its own scrollbars, and you need to use the member functions of CWnd to access them. For example, to get and set the position of the horizontal scroll-bar

      void CChildFrame::some_function(int sb_pos)
      {
      //Setting the horizontal scroll position
      SetScrollPos(SB_HORZ, sb_pos, TRUE);
      //Getting the horizontal scroll position
      int current_pos = GetScrollPos(SB_HORZ);
      ASSERT(current_pos==sb_pos);
      }

      You'll also need to change your OnCreate function:

      int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
      {
      SetScrollRange(SB_HORZ, 0, 50,TRUE);
      SetScrollPos(SB_HORZ, 0,TRUE);
      }

      And take out the m_hScroll from your window. Hope that helps (and I hope it's right too!)


      "We are the knights who say Ni" (The Knights Who Say Ni)

      J 1 Reply Last reply
      0
      • M Mike Upton

        I think the problem is that m_hScroll isn't actually the scroll-bar that you see in the window. When you set the style (cs.style() in PreCreateWindow to WS_VSCROLL | WS_HSCROLL the window creates its own scrollbars, and you need to use the member functions of CWnd to access them. For example, to get and set the position of the horizontal scroll-bar

        void CChildFrame::some_function(int sb_pos)
        {
        //Setting the horizontal scroll position
        SetScrollPos(SB_HORZ, sb_pos, TRUE);
        //Getting the horizontal scroll position
        int current_pos = GetScrollPos(SB_HORZ);
        ASSERT(current_pos==sb_pos);
        }

        You'll also need to change your OnCreate function:

        int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
        {
        SetScrollRange(SB_HORZ, 0, 50,TRUE);
        SetScrollPos(SB_HORZ, 0,TRUE);
        }

        And take out the m_hScroll from your window. Hope that helps (and I hope it's right too!)


        "We are the knights who say Ni" (The Knights Who Say Ni)

        J Offline
        J Offline
        jeremysay
        wrote on last edited by
        #3

        I have only one word to say thank !!!! now I use the scrollbars which I see . thx again

        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