Question : What am I missing with this AlphaBlend?

VC++ 6.0 and MFC, question is contained via comments:

void COverlay::DrawOverlayRegion(HDC a_hDC)
{
   ASSERT(a_hDC);
   CDC* pDC = CDC::FromHandle(a_hDC);

   CBrush br1;
   VERIFY( br1.CreateSolidBrush( OVERLAY_COLOR ) );  

   // the following line, when uncommented out, properly draws
   // a border around the region on the device context specified by a_hDC
   //pDC->FrameRgn(m_pOverlayRegion, &br1, 1,1);

   // But,  I want to fill the region with a semi-transparent color rather than simply outline it.
   CDC memdc;
   memdc.CreateCompatibleDC(pDC);
   memdc.FillRgn(m_pOverlayRegion, &br1);

   BLENDFUNCTION bf;                  
   bf.BlendOp = AC_SRC_OVER;
   bf.BlendFlags = 0;
   bf.SourceConstantAlpha = 120;
   bf.AlphaFormat = 0;

   CRect RegionRect;
   m_pViewedFrameRegion->GetRgnBox(RegionRect);

   int iWidth, iHeight;
   iWidth = RegionRect.Width();
   iHeight = RegionRect.Height();

   // perform an alpha blend
   BOOL bResult = AlphaBlend(a_hDC, 0,0, iWidth, iHeight, memdc, 0,0,iWidth, iHeight,bf);

   // bResult ends up true, but I see nothing?
}

Answer : What am I missing with this AlphaBlend?

You need to load a bitmap into the DC before you call fill-region.  All DCs, upon creation, are 1x1 pixel B&W images.

Try changing teh setup code to

   CDC memdc;
   CBitmap bmMem, *pbmOld;
   memdc.CreateCompatibleDC(pDC);
   bmMem.CreateCompatibeBitmap(pDC, iWidth, iHeight);
   pbmOld = memdc.SelectObject(&bmMem);
   memdc.FillRgn(m_pOverlayRegion, &br1);

   ... to end of function

    memdc.SelectObject(pbmOld);


Don't forget to move the region calculation code to above the bitmap creation so that you knwo how big to make it.

Hope this helps.
Random Solutions  
 
programming4us programming4us