Question

I need to fill a rectangular region with semi-transparent color/brush in mfc. How can I achieve that?

Was it helpful?

Solution 2

I found the solution. To fill the rectangle region with semi-transparent brush, we need to use GdiPlus objects.

Here is the Sample Code:

void FillSemiTransparentRegion(CDC *pDC, CRect rc)
{
    if (pDC == NULL || rc.IsRectEmpty() || rc.IsRectNull())
        return;

    Graphics gr(pDC->GetSafeHdc());

    SolidBrush br(Color(100, 0, 0, 0));    // Alpha, Red, Blue, Green

    gr.FillRectangle(&br, rc.left, rc.right, rc.Width(), rc.Height());
}

OTHER TIPS

You can't just fill a rectangle with a semi-transparent brush, you'll need to use something like AlphaBlend or TransparentBlt to create the effect.

An example is available here:

http://www.codeproject.com/Articles/286/Using-the-AlphaBlend-function

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top