SolidBrush Class
The SolidBrush class defines a brush of a single, solid color used for filling graphics shapes.
Namespace
Gdiplus
Declaration
class SolidBrush : public Brush {
public:
SolidBrush(const Color &color);
~SolidBrush();
Color GetColor() const;
void SetColor(const Color &color);
};
Inheritance
Brush → SolidBrush
Properties
Methods
Example
Properties
| Name | Type | Description |
|---|---|---|
| Color | Color | Gets or sets the brush color. |
Methods
| Signature | Description |
|---|---|
SolidBrush(const Color &color) | Initializes a new instance of the SolidBrush class with the specified color. |
~SolidBrush() | Releases all resources used by the SolidBrush object. |
Color GetColor() const | Returns the current color of the brush. |
void SetColor(const Color &color) | Sets the brush to a new color. |
Example
#include <windows.h>
#include <gdiplus.h>
using namespace Gdiplus;
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, nullptr);
HWND hwnd = CreateWindow(L"STATIC", L"SolidBrush Demo",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
400, 300, nullptr, nullptr, nullptr, nullptr);
ShowWindow(hwnd, SW_SHOW);
HDC hdc = GetDC(hwnd);
Graphics graphics(hdc);
SolidBrush brush(Color(255, 0, 120, 215)); // A semi‑transparent blue
Pen pen(Color(255, 0, 0, 0));
graphics.FillEllipse(&brush, 50, 50, 200, 150);
graphics.DrawEllipse(&pen, 50, 50, 200, 150);
ReleaseDC(hwnd, hdc);
MSG msg;
while (GetMessage(&msg, nullptr, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
GdiplusShutdown(gdiplusToken);
return 0;
}
Run the program to see a blue ellipse drawn with a solid brush.