问题
I need to fill a rectangular region with semi-transparent color/brush in mfc. How can I achieve that?
回答1:
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
回答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());
}
来源:https://stackoverflow.com/questions/22479272/how-to-fill-a-rectangle-region-with-semi-transparent-brush-in-mfc