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. Transparent checkbox text?

Transparent checkbox text?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
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.
  • M Offline
    M Offline
    madmax0001
    wrote on last edited by
    #1

    Hi, I need to know how to draw the checkbox button text background transparent. Thanks

    M R 2 Replies Last reply
    0
    • M madmax0001

      Hi, I need to know how to draw the checkbox button text background transparent. Thanks

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      You could try the usual tricks - the WS_EX_TRANSPARENT flag, handling WM_ERASEBKGND, etc. but I suspect they won't work on checkboxes. You can always render the text yourself :)

      M 1 Reply Last reply
      0
      • M Mark Salsbery

        You could try the usual tricks - the WS_EX_TRANSPARENT flag, handling WM_ERASEBKGND, etc. but I suspect they won't work on checkboxes. You can always render the text yourself :)

        M Offline
        M Offline
        madmax0001
        wrote on last edited by
        #3

        Hi, I have tried to handle WM_ERASEBKGND and I have also set WS_EX_TRANSPARENT for my CButton derived control, but the background still is not transparent. How can I render the text only? I don't want to draw the box and the checkmark myself. Thanks

        M 1 Reply Last reply
        0
        • M madmax0001

          Hi, I have tried to handle WM_ERASEBKGND and I have also set WS_EX_TRANSPARENT for my CButton derived control, but the background still is not transparent. How can I render the text only? I don't want to draw the box and the checkmark myself. Thanks

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          Yeah... most, if not all, of the standard controls use opaque background on their text. You can draw it yourself using something like DrawText(). Obtain the checkbox rect in OnInitDialog() and set the controls text to an empty string (you could get the text first so you have the text string). In OnPaint(), call the base class OnPaint() then get a DC for the window and select a pen of the text color into it, set its background mode to transparent, and use DrawText() to render the string. The Microsoft recommended method is owner draw. Mark

          1 Reply Last reply
          0
          • M madmax0001

            Hi, I need to know how to draw the checkbox button text background transparent. Thanks

            R Offline
            R Offline
            Ralf Lohmueller
            wrote on last edited by
            #5

            Did you try it with ON_WM_CTLCOLOR_REFLECT ? for my purposes, it worked... class CTransparentCheckbox : public CButton { public: CTransparentCheckbox(); //{{AFX_VIRTUAL(CTransparentCheckbox) //}}AFX_VIRTUAL virtual ~CTransparentCheckbox(); protected: //{{AFX_MSG(CButtonEx) afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; ////////////////////////////////////////////////////// // CTransparentCheckbox CTransparentCheckbox::CTransparentCheckbox() { } CTransparentCheckbox::~CTransparentCheckbox() { } BEGIN_MESSAGE_MAP(CTransparentCheckbox, CButton) //{{AFX_MSG_MAP(CTransparentCheckbox) ON_WM_CTLCOLOR_REFLECT() //}}AFX_MSG_MAP END_MESSAGE_MAP() // Handler for WM_CTLCOLOR reflected message (see message map) HBRUSH CTransparentCheckbox::CtlColor(CDC* pDC, UINT nCtlColor) { ASSERT(nCtlColor == CTLCOLOR_STATIC); // Set transparent drawing mode pDC->SetBkMode(TRANSPARENT); return (HBRUSH)GetStockObject(NULL_BRUSH); } greetings, ralf.

            M 1 Reply Last reply
            0
            • R Ralf Lohmueller

              Did you try it with ON_WM_CTLCOLOR_REFLECT ? for my purposes, it worked... class CTransparentCheckbox : public CButton { public: CTransparentCheckbox(); //{{AFX_VIRTUAL(CTransparentCheckbox) //}}AFX_VIRTUAL virtual ~CTransparentCheckbox(); protected: //{{AFX_MSG(CButtonEx) afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; ////////////////////////////////////////////////////// // CTransparentCheckbox CTransparentCheckbox::CTransparentCheckbox() { } CTransparentCheckbox::~CTransparentCheckbox() { } BEGIN_MESSAGE_MAP(CTransparentCheckbox, CButton) //{{AFX_MSG_MAP(CTransparentCheckbox) ON_WM_CTLCOLOR_REFLECT() //}}AFX_MSG_MAP END_MESSAGE_MAP() // Handler for WM_CTLCOLOR reflected message (see message map) HBRUSH CTransparentCheckbox::CtlColor(CDC* pDC, UINT nCtlColor) { ASSERT(nCtlColor == CTLCOLOR_STATIC); // Set transparent drawing mode pDC->SetBkMode(TRANSPARENT); return (HBRUSH)GetStockObject(NULL_BRUSH); } greetings, ralf.

              M Offline
              M Offline
              madmax0001
              wrote on last edited by
              #6

              Hi Ralf, your tip works perfectly for me! Thank you very much !!! Greetings

              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