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. Get CListCtrl scrollbar rectangle

Get CListCtrl scrollbar rectangle

Scheduled Pinned Locked Moved C / C++ / MFC
questionvisual-studiocom
8 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.
  • _ Offline
    _ Offline
    _Flaviu
    wrote on last edited by
    #1

    How can I get the CListCtrl scrollbar rectangle ? Whether the scrollbar is visible or not, I tested in following way:

    if(GetStyle() & WS\_VSCROLL)
    {
    }
    

    but, in order to change the scrollbar background by DrawThemeBackground[^], I need the scrollbar rectangle ... how can I retrieve the scrollbar rectangle ?

    J 1 Reply Last reply
    0
    • _ _Flaviu

      How can I get the CListCtrl scrollbar rectangle ? Whether the scrollbar is visible or not, I tested in following way:

      if(GetStyle() & WS\_VSCROLL)
      {
      }
      

      but, in order to change the scrollbar background by DrawThemeBackground[^], I need the scrollbar rectangle ... how can I retrieve the scrollbar rectangle ?

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      Just call GetScrollBarInfo[^] passing OBJID_VSCROLL as idObject parameter.

      _ 1 Reply Last reply
      0
      • J Jochen Arndt

        Just call GetScrollBarInfo[^] passing OBJID_VSCROLL as idObject parameter.

        _ Offline
        _ Offline
        _Flaviu
        wrote on last edited by
        #3

        Thank you Jochen ... the rectangle is retrieve it ... :) I have to dig in, because it seems that something is wrong in my code, because though rectangle is correct now, the color of scrollbar is not drawn ...

        void CGridCtrlExt::OnDraw(CDC* pDC)
        {
        // draw the grid

        HTHEME hTheme = OpenThemeData(m\_hWnd, L"WINDOW");
        

        // HTHEME hTheme = OpenThemeData(m_hWnd, L"MFCGridCtrl");
        if(NULL != hTheme)
        {
        if(WS_VSCROLL & GetStyle())
        {
        SCROLLBARINFO si;
        si.cbSize = sizeof(SCROLLBARINFO);
        GetScrollBarInfo(OBJID_VSCROLL, &si);
        CRect rect(si.rcScrollBar);
        pDC->FillSolidRect(&rect, RGB(255, 255, 0));
        DrawThemeBackground(hTheme, pDC->GetSafeHdc(), WP_VERTSCROLL, VSS_NORMAL, &rect, NULL);
        }
        CloseThemeData(hTheme);
        }
        }

        J 1 Reply Last reply
        0
        • _ _Flaviu

          Thank you Jochen ... the rectangle is retrieve it ... :) I have to dig in, because it seems that something is wrong in my code, because though rectangle is correct now, the color of scrollbar is not drawn ...

          void CGridCtrlExt::OnDraw(CDC* pDC)
          {
          // draw the grid

          HTHEME hTheme = OpenThemeData(m\_hWnd, L"WINDOW");
          

          // HTHEME hTheme = OpenThemeData(m_hWnd, L"MFCGridCtrl");
          if(NULL != hTheme)
          {
          if(WS_VSCROLL & GetStyle())
          {
          SCROLLBARINFO si;
          si.cbSize = sizeof(SCROLLBARINFO);
          GetScrollBarInfo(OBJID_VSCROLL, &si);
          CRect rect(si.rcScrollBar);
          pDC->FillSolidRect(&rect, RGB(255, 255, 0));
          DrawThemeBackground(hTheme, pDC->GetSafeHdc(), WP_VERTSCROLL, VSS_NORMAL, &rect, NULL);
          }
          CloseThemeData(hTheme);
          }
          }

          J Offline
          J Offline
          Jochen Arndt
          wrote on last edited by
          #4

          This may be because the scroll bar is redrawn by the system. You may use a custom drawn scroll bar or handle WM_CTLCOLOR when you only need to change the background. Searching the web may give you some solutions. The article http://www.drdobbs.com/windows/developing-a-custom-windows-scrollbar-in/184416659[^] is rather old but contains a good introduction and shows how to implement a custom drawn scroll bar.

          _ 2 Replies Last reply
          0
          • J Jochen Arndt

            This may be because the scroll bar is redrawn by the system. You may use a custom drawn scroll bar or handle WM_CTLCOLOR when you only need to change the background. Searching the web may give you some solutions. The article http://www.drdobbs.com/windows/developing-a-custom-windows-scrollbar-in/184416659[^] is rather old but contains a good introduction and shows how to implement a custom drawn scroll bar.

            _ Offline
            _ Offline
            _Flaviu
            wrote on last edited by
            #5

            "You may use a custom drawn scroll bar or handle WM_CTLCOLOR when you only need to change the background" I already tried that ... if I override WM_CTLCOLOR I could color everything, except scrollbars ... :) "Searching the web may give you some solutions. The article http://www.drdobbs.com/windows/developing-a-custom-windows-scrollbar-in/184416659\[^\] is rather old but contains a good introduction and shows how to implement a custom drawn scroll bar." I saw that article, but is about replacing the original scrollbar with CScrollBarEx control ... well, in this case I will front with 2 issues: hiding the original scrollbar, and second, synchronize the listctrl with CScrollbarEx control ... I think that is the longest road ... and the hardest ... I thought that trying to use DrawThemeBackground I could change the scrollbars colors ... :( I am working on that for weeks ... I have to dig in ...

            1 Reply Last reply
            0
            • J Jochen Arndt

              This may be because the scroll bar is redrawn by the system. You may use a custom drawn scroll bar or handle WM_CTLCOLOR when you only need to change the background. Searching the web may give you some solutions. The article http://www.drdobbs.com/windows/developing-a-custom-windows-scrollbar-in/184416659[^] is rather old but contains a good introduction and shows how to implement a custom drawn scroll bar.

              _ Offline
              _ Offline
              _Flaviu
              wrote on last edited by
              #6

              "This may be because the scroll bar is redrawn by the system" I wonder if I put properly the scrollbar coloring code ... inside of CMyControl::OnDraw is ok ? I guess not ...

              J 1 Reply Last reply
              0
              • _ _Flaviu

                "This may be because the scroll bar is redrawn by the system" I wonder if I put properly the scrollbar coloring code ... inside of CMyControl::OnDraw is ok ? I guess not ...

                J Offline
                J Offline
                Jochen Arndt
                wrote on last edited by
                #7

                OnDraw is a CView member function. You probably mean some kind of custom / owner draw. But this won't work for the scroll bars of list controls because only the list control content can be changed by this method. The scroll bar is still drawn by the system when necessary and your drawing vanishes. If handling WM_CTLCOLOR did not work (and I believe meanwhile that it does not work with list controls), the only solution is using a complety custom drawn control or another GUI framework like Qt.

                _ 1 Reply Last reply
                0
                • J Jochen Arndt

                  OnDraw is a CView member function. You probably mean some kind of custom / owner draw. But this won't work for the scroll bars of list controls because only the list control content can be changed by this method. The scroll bar is still drawn by the system when necessary and your drawing vanishes. If handling WM_CTLCOLOR did not work (and I believe meanwhile that it does not work with list controls), the only solution is using a complety custom drawn control or another GUI framework like Qt.

                  _ Offline
                  _ Offline
                  _Flaviu
                  wrote on last edited by
                  #8

                  Thank you so much for your attention Jochen ! In the real situation, I used an CGridCtrl, and this control has CGridCtrl::OnDraw to drawing itself ... but there is no difference between this kind of control or CListCtrl, or CListBox ... I had tried to change the color of the scrollbars of these last ones and I didn't succeded ... After all, CGridCtrl is derived from CWnd, so is the same matter ... Should be a chance to move that code on some handler that is called after the system is redrawing the scrollbars ? ... who knows ... I should dig in ...

                  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