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 make transparent Text-Labels in CDialog ?

How to make transparent Text-Labels in CDialog ?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
6 Posts 4 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.
  • V Offline
    V Offline
    vgrigor
    wrote on last edited by
    #1

    I Load and draw Picture in OnEraseBkgnd(CDC* pDC), I than need label to not overdraw background, and do HBRUSH cWaitDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); pDC->SetBkMode(TRANSPARENT); return hbr; } Why backgound is overdrawn? thanks you.

    S 1 Reply Last reply
    0
    • V vgrigor

      I Load and draw Picture in OnEraseBkgnd(CDC* pDC), I than need label to not overdraw background, and do HBRUSH cWaitDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); pDC->SetBkMode(TRANSPARENT); return hbr; } Why backgound is overdrawn? thanks you.

      S Offline
      S Offline
      Steve S
      wrote on last edited by
      #2

      Try return (HBRUSH)GetStockObject(NULL_BRUSH); instead of return hbr; Steve S

      N N V 3 Replies Last reply
      0
      • S Steve S

        Try return (HBRUSH)GetStockObject(NULL_BRUSH); instead of return hbr; Steve S

        N Offline
        N Offline
        Nathan R
        wrote on last edited by
        #3

        if you donot like 'stock object' try this :laugh:. It should work. LOGBRUSH lb; lb.lbStyle = BS_HOLLOW; return CreateBrushIndirect(&lb);

        1 Reply Last reply
        0
        • S Steve S

          Try return (HBRUSH)GetStockObject(NULL_BRUSH); instead of return hbr; Steve S

          N Offline
          N Offline
          Nathan_RR
          wrote on last edited by
          #4

          if you dont like using 'stock objects', try using this :-D It should work LOGBRUSH lb; lb.lbStyle = BS_HOLLOW; CreateBrushIndirect(&lb);

          S 1 Reply Last reply
          0
          • S Steve S

            Try return (HBRUSH)GetStockObject(NULL_BRUSH); instead of return hbr; Steve S

            V Offline
            V Offline
            vgrigor
            wrote on last edited by
            #5

            Beter if you explain ... Code that work: hbr = NULL; { if( CTLCOLOR_STATIC == nCtlColor ) { hbr = (HBRUSH)GetStockObject( HOLLOW_BRUSH ); pDC->SetBkMode( TRANSPARENT ); } else { hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); } return hbr; } thanks you for response.

            1 Reply Last reply
            0
            • N Nathan_RR

              if you dont like using 'stock objects', try using this :-D It should work LOGBRUSH lb; lb.lbStyle = BS_HOLLOW; CreateBrushIndirect(&lb);

              S Offline
              S Offline
              Steve S
              wrote on last edited by
              #6

              Problem with non-stock object approach is that you may inadvertently leak GDI objects, unless you track them in the parent CDialog. Another approach would be to derive from CStatic, use message reflection so that the object handles it's own WM_CTLCOLORSTATIC, and returns a singleton hollow brush. The stock object null/hollow brush could be used there too, and you'd use control variables to associated dialog members to the appropriate control(s). Steve S

              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