Draw a slightly transparent blue rectangle in the native Win32 GDI

How to draw a blue rectangle with an alpha / transparency value of 0.5 (i.e. 50% transparency) in Native Win32 C ++?

Using a macro like RGBA () fails, I'm not sure how to specify the alpha value of the brush.

SetDCPenColor(hdc, RGBA(255,255,0,127));
SetDCBrushColor(hdc, RGBA(255,255,0,127));
Rectangle(hdc, 0, 0, width, height);
+5
source share
2 answers

I am sure you will need GDI + to do this, but it should be there with GDI:

//in rendering function
using namespace Gdiplus;
Graphics g (hdc);
SolidBrush brush (Color (127 /*A*/, 0 /*R*/, 0 /*G*/, 255 /*B*/));
g.FillRectangle (&brush, 0, 0, width, height);

GDI +, , -, , SelectObject DeleteObject.

, / GDI + Gdiplus -lgdiplus.

GDI, , , AlphaBlend, , . GDI +, , , GDI.

+6

All Articles