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. Scroll bar question - need experts help here

Scroll bar question - need experts help here

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
6 Posts 3 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.
  • Y Offline
    Y Offline
    Yaron Nir
    wrote on last edited by
    #1

    Hi, i am trying to disable the horizontal scroll bar in list ctrl. the scroll doesn't appear until i add a lot of items in the list (it appears because the vertical scroll bar appears as well). here is the code i use void CMyListCtrl::OnStyleChanging(int nStyleType,LPSTYLESTRUCT lpStyleStruct) { if (nStyleType != GWL_STYLE) { CListCtrl::OnStyleChanging(nStyleType,lpStyleStr uct); return; } lpStyleStruct->styleNew &= ~WS_HSCROLL; SetWindowLong(m_hWnd,GWL_STYLE,lpStyleStruct->styleNew); } this indeed change the style of the list not to have WS_HSCROLL bar, but the scroll bar is still shown.... please help me i am really desperate, this is the 4th post i am asking for help thanks Yaron Ask not what the application can do for you, ask what you can do for your application

    T A 2 Replies Last reply
    0
    • Y Yaron Nir

      Hi, i am trying to disable the horizontal scroll bar in list ctrl. the scroll doesn't appear until i add a lot of items in the list (it appears because the vertical scroll bar appears as well). here is the code i use void CMyListCtrl::OnStyleChanging(int nStyleType,LPSTYLESTRUCT lpStyleStruct) { if (nStyleType != GWL_STYLE) { CListCtrl::OnStyleChanging(nStyleType,lpStyleStr uct); return; } lpStyleStruct->styleNew &= ~WS_HSCROLL; SetWindowLong(m_hWnd,GWL_STYLE,lpStyleStruct->styleNew); } this indeed change the style of the list not to have WS_HSCROLL bar, but the scroll bar is still shown.... please help me i am really desperate, this is the 4th post i am asking for help thanks Yaron Ask not what the application can do for you, ask what you can do for your application

      T Offline
      T Offline
      TyMatthews
      wrote on last edited by
      #2

      Are you trying to remove the scrollbar so it doesn't even appear when normally it would, or are you just trying to disable it so that it's shown but the user can't scroll with it?     Ty

      "The significant problems we face cannot be solved at the same level of thinking we were at when we created them." -Albert Einstein

      Y 1 Reply Last reply
      0
      • T TyMatthews

        Are you trying to remove the scrollbar so it doesn't even appear when normally it would, or are you just trying to disable it so that it's shown but the user can't scroll with it?     Ty

        "The significant problems we face cannot be solved at the same level of thinking we were at when we created them." -Albert Einstein

        Y Offline
        Y Offline
        Yaron Nir
        wrote on last edited by
        #3

        I am trying to to remove the horizontal bar so it won't ever appear.... can u help? thanks Ask not what the application can do for you, ask what you can do for your application

        T 1 Reply Last reply
        0
        • Y Yaron Nir

          I am trying to to remove the horizontal bar so it won't ever appear.... can u help? thanks Ask not what the application can do for you, ask what you can do for your application

          T Offline
          T Offline
          TyMatthews
          wrote on last edited by
          #4

          Unfortunately, there is no easy answer. Scrollbars in CListCtrl are drawn and handled internally by the list control, and aren't actually controls by themselves. Thus the only way to disable them is to derive from CListCtrl and write your own drawing routine... not a very fun thing to do. What's the cause of the scroll bar appearing in the first place? If you're trying to forcefully remove it, have you looked at fixing what causes it to appear?     Ty

          "The significant problems we face cannot be solved at the same level of thinking we were at when we created them." -Albert Einstein

          1 Reply Last reply
          0
          • Y Yaron Nir

            Hi, i am trying to disable the horizontal scroll bar in list ctrl. the scroll doesn't appear until i add a lot of items in the list (it appears because the vertical scroll bar appears as well). here is the code i use void CMyListCtrl::OnStyleChanging(int nStyleType,LPSTYLESTRUCT lpStyleStruct) { if (nStyleType != GWL_STYLE) { CListCtrl::OnStyleChanging(nStyleType,lpStyleStr uct); return; } lpStyleStruct->styleNew &= ~WS_HSCROLL; SetWindowLong(m_hWnd,GWL_STYLE,lpStyleStruct->styleNew); } this indeed change the style of the list not to have WS_HSCROLL bar, but the scroll bar is still shown.... please help me i am really desperate, this is the 4th post i am asking for help thanks Yaron Ask not what the application can do for you, ask what you can do for your application

            A Offline
            A Offline
            Atlantys
            wrote on last edited by
            #5

            I had the same issue. What I ended by doing is resizing the columns when the vertical scroll is added. So instead of hardcoding the width of column, you assign it a percentage of the listctrl's width. Then call this function whenever your listctrl needs a vertical slider. The user can still resize the column with the header control (which could cause a horizontal scrollbar to appear).

            void CMyDialogDlg::ResizeColumns(const int iPercentageOfListCtrl)
            {
            CRect rect;
            m_cListCtrl.GetClientRect(rect);
            int iNewWidth = (rect.right * iPercentageOfListCtrl / 100);
            int iOldWidth = m_cListCtrl.GetColumnWidth(0);
            if (iOldWidth != iNewWidth) {
            m_cListCtrl.SetColumnWidth(0, iNewWidth); // resize the first column
            }
            }

            This will resize the first column enough so that the list ctrl doesn't think it needs a horizontal scroll bar. Hope this helps.

            Y 1 Reply Last reply
            0
            • A Atlantys

              I had the same issue. What I ended by doing is resizing the columns when the vertical scroll is added. So instead of hardcoding the width of column, you assign it a percentage of the listctrl's width. Then call this function whenever your listctrl needs a vertical slider. The user can still resize the column with the header control (which could cause a horizontal scrollbar to appear).

              void CMyDialogDlg::ResizeColumns(const int iPercentageOfListCtrl)
              {
              CRect rect;
              m_cListCtrl.GetClientRect(rect);
              int iNewWidth = (rect.right * iPercentageOfListCtrl / 100);
              int iOldWidth = m_cListCtrl.GetColumnWidth(0);
              if (iOldWidth != iNewWidth) {
              m_cListCtrl.SetColumnWidth(0, iNewWidth); // resize the first column
              }
              }

              This will resize the first column enough so that the list ctrl doesn't think it needs a horizontal scroll bar. Hope this helps.

              Y Offline
              Y Offline
              Yaron Nir
              wrote on last edited by
              #6

              Hi, thanks for reply. when should i call this function, shall i call it when OnSize() occurs??? Yaron Ask not what the application can do for you, ask what you can do for your application

              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