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. Coloring scrollbar with DrawThemeBackground

Coloring scrollbar with DrawThemeBackground

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

    I am struggling for some while to coloring a control scrollbar, with DrawThemeBackground. (any control, no matter what) ... here is the trial:

    void CMyControl::OnDraw(CDC* pDC)
    {
    // draw control
    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, 0, 0));
    HRESULT hResult = DrawThemeBackground(hTheme, pDC->GetSafeHdc(), SBP_LOWERTRACKVERT, SCRBS_NORMAL, &rect, NULL);
    if(S_OK == hResult)
    TRACE("ok\n");
    else
    TRACE("not ok !\n");
    }
    CloseThemeData(hTheme);
    }
    }

    And I always get not ok ! ... What I'am doing wrong here ? The scrollbar rectangle are ok, I verified ... can you help me ? Thank you.

    J CPalliniC 2 Replies Last reply
    0
    • _ _Flaviu

      I am struggling for some while to coloring a control scrollbar, with DrawThemeBackground. (any control, no matter what) ... here is the trial:

      void CMyControl::OnDraw(CDC* pDC)
      {
      // draw control
      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, 0, 0));
      HRESULT hResult = DrawThemeBackground(hTheme, pDC->GetSafeHdc(), SBP_LOWERTRACKVERT, SCRBS_NORMAL, &rect, NULL);
      if(S_OK == hResult)
      TRACE("ok\n");
      else
      TRACE("not ok !\n");
      }
      CloseThemeData(hTheme);
      }
      }

      And I always get not ok ! ... What I'am doing wrong here ? The scrollbar rectangle are ok, I verified ... can you help me ? Thank you.

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

      Print the HRESULT code upon failure. It may help to identify the error source (e.g. by printing the corresponding error message using FormatMessage or searching for the code in WinError.h).

      _ 1 Reply Last reply
      0
      • _ _Flaviu

        I am struggling for some while to coloring a control scrollbar, with DrawThemeBackground. (any control, no matter what) ... here is the trial:

        void CMyControl::OnDraw(CDC* pDC)
        {
        // draw control
        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, 0, 0));
        HRESULT hResult = DrawThemeBackground(hTheme, pDC->GetSafeHdc(), SBP_LOWERTRACKVERT, SCRBS_NORMAL, &rect, NULL);
        if(S_OK == hResult)
        TRACE("ok\n");
        else
        TRACE("not ok !\n");
        }
        CloseThemeData(hTheme);
        }
        }

        And I always get not ok ! ... What I'am doing wrong here ? The scrollbar rectangle are ok, I verified ... can you help me ? Thank you.

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #3

        I would check the exact value of hResult, however the documentation page is not encouraging (see the comment at the bottom of the page)[^].

        In testa che avete, signor di Ceprano?

        _ 1 Reply Last reply
        0
        • J Jochen Arndt

          Print the HRESULT code upon failure. It may help to identify the error source (e.g. by printing the corresponding error message using FormatMessage or searching for the code in WinError.h).

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

          I cheked:

          E_FAIL Unspecified failure 0x80004005

          I am stuck :( P.S. But I would try FormatMessage too ...

          J 1 Reply Last reply
          0
          • _ _Flaviu

            I cheked:

            E_FAIL Unspecified failure 0x80004005

            I am stuck :( P.S. But I would try FormatMessage too ...

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

            Flaviu2 wrote:

            But I would try FormatMessage too

            That would not help because it will print something similar ("Unspecified error") in the current Windows system language. I'm sorry, but I have no other ideas.

            _ 2 Replies Last reply
            0
            • J Jochen Arndt

              Flaviu2 wrote:

              But I would try FormatMessage too

              That would not help because it will print something similar ("Unspecified error") in the current Windows system language. I'm sorry, but I have no other ideas.

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

              Thank you for your interest, it's weird that I haven't see any example of how to use DrawThemeBackground function ...

              1 Reply Last reply
              0
              • CPalliniC CPallini

                I would check the exact value of hResult, however the documentation page is not encouraging (see the comment at the bottom of the page)[^].

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

                I have checked for the first time, but I formatted as int (%d), that's why I saw noise there, not real error returned ... so tricky this DrawThemeBackground function ...

                1 Reply Last reply
                0
                • J Jochen Arndt

                  Flaviu2 wrote:

                  But I would try FormatMessage too

                  That would not help because it will print something similar ("Unspecified error") in the current Windows system language. I'm sorry, but I have no other ideas.

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

                  I have tried also:

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

                  // 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));
                  HRESULT hRes = DrawThemeBackground(
                  hTheme,
                  pDC->GetSafeHdc(),
                  SBP_UPPERTRACKVERT,
                  SCRBS_NORMAL,
                  &rect,
                  NULL);
                  TRACE("HRESULT: %d|%d: OK ? %d\n", hRes, S_OK, hRes == S_OK);
                  }
                  CloseThemeData(hTheme);
                  }

                  And the result are S_OK now, which is good, however, I have seen nothing colored ... strange ...

                  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