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. How to draw static controls and check box buttons transparently ?

How to draw static controls and check box buttons transparently ?

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
4 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.
  • R Offline
    R Offline
    rrrado
    wrote on last edited by
    #1

    I'd like to have my tabbed dialog application using XP themes like "My Computer-> properties" in the win XP - the dialog inside the TAB control should use gradient background. My problem is that static controls and check box buttons are not drawn properly -> background of the text is erased by default dialog background color (text background has OPAQUE mode). I've tried to handle the WM_CTLCOLOR message in the dialog, but this solved only the problem with text static controls, not with the group rectangle static box (it's text was drawn over the rectangle line when I've set text background mode to TRANSPARENT). I hope there is some easier way than to code my own owner drawn controls, when windows GUI is using this. Any suggestions ? Thanks !


    rrrado

    Y 1 Reply Last reply
    0
    • R rrrado

      I'd like to have my tabbed dialog application using XP themes like "My Computer-> properties" in the win XP - the dialog inside the TAB control should use gradient background. My problem is that static controls and check box buttons are not drawn properly -> background of the text is erased by default dialog background color (text background has OPAQUE mode). I've tried to handle the WM_CTLCOLOR message in the dialog, but this solved only the problem with text static controls, not with the group rectangle static box (it's text was drawn over the rectangle line when I've set text background mode to TRANSPARENT). I hope there is some easier way than to code my own owner drawn controls, when windows GUI is using this. Any suggestions ? Thanks !


      rrrado

      Y Offline
      Y Offline
      YoSilver
      wrote on last edited by
      #2

      Looks strange because when an XP theme is active, all text labels are drawn transparently; in fact, no WM_CTLCOLOR handling is necessary. Does your app have a manifest resource in it that enables theming (the XP look) when a theme is active? The gradient that you see in "My Computer-> properties" is NOT a feature of a themed Tab control, it's how the theme handles property sheets - it applies a gradient background to each of the dialog in the sheet. If you create your own tabbed dialog, you can do it by handling WM_ERASEBKGND in each of your dialogs. Consider the following code excerpt; perhaps you will get some ideas on your group boxes (BTW, they belong to window class BUTTON, not STATIC):

      BOOL myGroupBox::OnEraseBkgnd(CDC* pDC)
      {
      CRect rcCtrl;
      GetClientRect(rcCtrl);

      if (GetUXThemeState().IsThemeActive())
          pDC->FillSolidRect(rcCtrl, ColorAdjustLuma(afxData.clrBtnFace, 750, TRUE));
      else
          pDC->FillSolidRect(rcCtrl, afxData.clrBtnFace);
      
      PrintClient(pDC, PRF\_CLIENT);
      
      return 1;
      

      }

      void myGroupBox::OnPaint()
      {
      // validates the invalid area to prevent the infinite paint loop
      PAINTSTRUCT ps = {0};
      ::BeginPaint(m_hWnd, &ps);
      ::EndPaint(m_hWnd, &ps);
      }

      One always gets the deserved.
      http://www.silveragesoftware.com/hffr.html
      Update your source code with my tool HandyFile Find And Replace!

      R 1 Reply Last reply
      0
      • Y YoSilver

        Looks strange because when an XP theme is active, all text labels are drawn transparently; in fact, no WM_CTLCOLOR handling is necessary. Does your app have a manifest resource in it that enables theming (the XP look) when a theme is active? The gradient that you see in "My Computer-> properties" is NOT a feature of a themed Tab control, it's how the theme handles property sheets - it applies a gradient background to each of the dialog in the sheet. If you create your own tabbed dialog, you can do it by handling WM_ERASEBKGND in each of your dialogs. Consider the following code excerpt; perhaps you will get some ideas on your group boxes (BTW, they belong to window class BUTTON, not STATIC):

        BOOL myGroupBox::OnEraseBkgnd(CDC* pDC)
        {
        CRect rcCtrl;
        GetClientRect(rcCtrl);

        if (GetUXThemeState().IsThemeActive())
            pDC->FillSolidRect(rcCtrl, ColorAdjustLuma(afxData.clrBtnFace, 750, TRUE));
        else
            pDC->FillSolidRect(rcCtrl, afxData.clrBtnFace);
        
        PrintClient(pDC, PRF\_CLIENT);
        
        return 1;
        

        }

        void myGroupBox::OnPaint()
        {
        // validates the invalid area to prevent the infinite paint loop
        PAINTSTRUCT ps = {0};
        ::BeginPaint(m_hWnd, &ps);
        ::EndPaint(m_hWnd, &ps);
        }

        One always gets the deserved.
        http://www.silveragesoftware.com/hffr.html
        Update your source code with my tool HandyFile Find And Replace!

        R Offline
        R Offline
        rrrado
        wrote on last edited by
        #3

        Thank you very much for your response. I'll try your code. I don't use property sheets besause of it's limitations. I have tab control which has child dialogs. I'm handling the child dialog's onEraseBackgroud where I do nothing, so oridinal tab control's background remains. I have manifest file in my resources, so all buttons, group boxes, etc. looks like in Win XP theme. So I don't know why my static controls are not drawn transparently by default :confused: I'm also calling InitCommonControls(); in the app's InitInstance() as recommended ...


        rrrado

        Y 1 Reply Last reply
        0
        • R rrrado

          Thank you very much for your response. I'll try your code. I don't use property sheets besause of it's limitations. I have tab control which has child dialogs. I'm handling the child dialog's onEraseBackgroud where I do nothing, so oridinal tab control's background remains. I have manifest file in my resources, so all buttons, group boxes, etc. looks like in Win XP theme. So I don't know why my static controls are not drawn transparently by default :confused: I'm also calling InitCommonControls(); in the app's InitInstance() as recommended ...


          rrrado

          Y Offline
          Y Offline
          YoSilver
          wrote on last edited by
          #4

          Could you make a small screenshot of the text label portion of a group box and give a link? this can make the native Windows drawing procedure more clear. Oh... I think all you have to do is give your group boxes sensible ID's (other than -1 /IDC_STATIC/), check them in the WM_CTLCOLOR handler, call pdc->SetBkColor() for these ID's and return a brush of a proper color. Do not set the background mode to TRANSPARENT. One always gets the deserved.
          http://www.silveragesoftware.com/hffr.html
          Update your source code with my tool HandyFile Find And Replace!

          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