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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. TransparentBlt

TransparentBlt

Scheduled Pinned Locked Moved C / C++ / MFC
4 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
    _T No name
    wrote on last edited by
    #1

    hi, i have made a derived class from CDialog to customize it with my bitmaps in which some pixels need to be transparent. I am using TransparentBlt() for the same in OnEraseBkgnd() in derived class after calling CDialog::OnEraseBkgnd(). the thing is happening is those pixels are either coming grey so white sometime. not becoming transparent. Can anyone suggest where i am doing wrong !!! thanx

    N 1 Reply Last reply
    0
    • _ _T No name

      hi, i have made a derived class from CDialog to customize it with my bitmaps in which some pixels need to be transparent. I am using TransparentBlt() for the same in OnEraseBkgnd() in derived class after calling CDialog::OnEraseBkgnd(). the thing is happening is those pixels are either coming grey so white sometime. not becoming transparent. Can anyone suggest where i am doing wrong !!! thanx

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      _T("No name") wrote:

      I am using TransparentBlt() for the same in OnEraseBkgnd()

      without seeing the code hard to say... hope you calls the CDialog::OnEraseBkgnd() before doing the TransparentBlt().

      nave [My Articles] [My Blog]

      _ 1 Reply Last reply
      0
      • N Naveen

        _T("No name") wrote:

        I am using TransparentBlt() for the same in OnEraseBkgnd()

        without seeing the code hard to say... hope you calls the CDialog::OnEraseBkgnd() before doing the TransparentBlt().

        nave [My Articles] [My Blog]

        _ Offline
        _ Offline
        _T No name
        wrote on last edited by
        #3

        i am calling it before the TransparentBlt() only.. CDialog::OnEraseBkgnd(pDC); CRect rcClient; GetClientRect(rcClient); CDC memDC; memDC.CreateCompatibleDC(pDC); /* TODO : Draw according to state */ /* Title left */ memDC.SelectObject(&m_bmpTitleLeft); pDC->TransparentBlt(rcClient.left,rcClient.top,10,31,&memDC,0,0,10,31,CLR_TRANSPARENT); /* Title Middle */ int i = 0; memDC.SelectObject(&m_bmpTitleMiddle); pDC->StretchBlt(rcClient.left+10,rcClient.top,rcClient.right-10,31,&memDC,0,0,1,31,SRCCOPY); /*Title Right*/ memDC.SelectObject(&m_bmpTitleRight); pDC->TransparentBlt(rcClient.right-10,rcClient.top,10,31,&memDC,0,0,10,31,CLR_TRANSPARENT); /* set Title text */ pDC->SetBkMode(TRANSPARENT); CSize szTitle = pDC->GetTextExtent(m_strTitle); CRect rcTitle(rcClient.left+14,rcClient.top+15-(szTitle.cy/2),rcClient.left+14+szTitle.cx,rcClient.top+15+(szTitle.cy)/2); pDC->DrawText(m_strTitle,-1,&rcTitle,DT_CENTER || DT_SINGLELINE); /* set title box rectangle */ CRect rcTitleBox(rcClient.left,rcClient.top,rcClient.right,rcClient.top+31); m_rcTitleBox = rcTitleBox; /* set main view rectangle */ CRect rcViewDlg(rcClient.left,rcTitle.bottom,rcClient.right,rcClient.bottom); m_rcViewDlg = rcViewDlg; /* Middle right and left area */ memDC.SelectObject(&m_bmpMiddleLeft); pDC->StretchBlt(rcClient.left,rcClient.top+31,10,rcClient.bottom-10,&memDC,0,0,10,1,SRCCOPY); memDC.SelectObject(&m_bmpMiddleRight); pDC->StretchBlt(rcClient.right-10,rcClient.top+31,10,rcClient.bottom-10,&memDC,0,0,10,1,SRCCOPY); /* Middle ares is done by fill rectangle as drawing bitmap in loops makes it slow */ /* Middle area */ CRect rcMiddle(rcClient.left+10,rcClient.top+31+1,rcClient.right-10,rcClient.bottom-10); CBrush brushMiddle(RGB(219,230,244)); pDC->FillRect(&rcMiddle,&brushMiddle); /* Bottom left area */ memDC.SelectObject(&m_bmpBottomLeft); pDC->BitBlt(rcClient.left,rcClient.bottom-50,10,50,&memDC,0,0,SRCCOPY); /* Bottom middle area */ memDC.SelectObject(&m_bmpBottomMiddle); pDC->StretchBlt(rcClient.left+10,rcClient.bottom-50,rcClient.right-10,50,&memDC,0,0,1,50,SRCCOPY); /* Bottom right area */ memDC.SelectObject(&m_bmpBottomRight); pDC->BitBlt(rcClient.right-10,rcClient.bottom-50,10,50

        R 1 Reply Last reply
        0
        • _ _T No name

          i am calling it before the TransparentBlt() only.. CDialog::OnEraseBkgnd(pDC); CRect rcClient; GetClientRect(rcClient); CDC memDC; memDC.CreateCompatibleDC(pDC); /* TODO : Draw according to state */ /* Title left */ memDC.SelectObject(&m_bmpTitleLeft); pDC->TransparentBlt(rcClient.left,rcClient.top,10,31,&memDC,0,0,10,31,CLR_TRANSPARENT); /* Title Middle */ int i = 0; memDC.SelectObject(&m_bmpTitleMiddle); pDC->StretchBlt(rcClient.left+10,rcClient.top,rcClient.right-10,31,&memDC,0,0,1,31,SRCCOPY); /*Title Right*/ memDC.SelectObject(&m_bmpTitleRight); pDC->TransparentBlt(rcClient.right-10,rcClient.top,10,31,&memDC,0,0,10,31,CLR_TRANSPARENT); /* set Title text */ pDC->SetBkMode(TRANSPARENT); CSize szTitle = pDC->GetTextExtent(m_strTitle); CRect rcTitle(rcClient.left+14,rcClient.top+15-(szTitle.cy/2),rcClient.left+14+szTitle.cx,rcClient.top+15+(szTitle.cy)/2); pDC->DrawText(m_strTitle,-1,&rcTitle,DT_CENTER || DT_SINGLELINE); /* set title box rectangle */ CRect rcTitleBox(rcClient.left,rcClient.top,rcClient.right,rcClient.top+31); m_rcTitleBox = rcTitleBox; /* set main view rectangle */ CRect rcViewDlg(rcClient.left,rcTitle.bottom,rcClient.right,rcClient.bottom); m_rcViewDlg = rcViewDlg; /* Middle right and left area */ memDC.SelectObject(&m_bmpMiddleLeft); pDC->StretchBlt(rcClient.left,rcClient.top+31,10,rcClient.bottom-10,&memDC,0,0,10,1,SRCCOPY); memDC.SelectObject(&m_bmpMiddleRight); pDC->StretchBlt(rcClient.right-10,rcClient.top+31,10,rcClient.bottom-10,&memDC,0,0,10,1,SRCCOPY); /* Middle ares is done by fill rectangle as drawing bitmap in loops makes it slow */ /* Middle area */ CRect rcMiddle(rcClient.left+10,rcClient.top+31+1,rcClient.right-10,rcClient.bottom-10); CBrush brushMiddle(RGB(219,230,244)); pDC->FillRect(&rcMiddle,&brushMiddle); /* Bottom left area */ memDC.SelectObject(&m_bmpBottomLeft); pDC->BitBlt(rcClient.left,rcClient.bottom-50,10,50,&memDC,0,0,SRCCOPY); /* Bottom middle area */ memDC.SelectObject(&m_bmpBottomMiddle); pDC->StretchBlt(rcClient.left+10,rcClient.bottom-50,rcClient.right-10,50,&memDC,0,0,1,50,SRCCOPY); /* Bottom right area */ memDC.SelectObject(&m_bmpBottomRight); pDC->BitBlt(rcClient.right-10,rcClient.bottom-50,10,50

          R Offline
          R Offline
          Ramon F Mendes
          wrote on last edited by
          #4

          _T("No name") wrote:

          CDialog::OnEraseBkgnd(pDC);

          When you call the OnEraseBkgnd base method MFC calls the DefWndProc which will fill the dialog with its associated background brush, so remove this line. Also, make sure to set the transparent style of the dialog to TRUE

          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