Path Class
The Gdiplus::Path class stores a series of lines and curves. It is used with Graphics::DrawPath and Graphics::FillPath to render complex shapes.
Namespace
Gdiplus
Syntax
class Path {
public:
Path();
Path(const PointF* points, const BYTE* types, INT count);
Path(const Point* points, const BYTE* types, INT count);
Path(const Path& src);
~Path();
Status AddLine(PointF pt1, PointF pt2);
Status AddLines(const PointF* points, INT count);
Status AddArc(RectF rect, REAL startAngle, REAL sweepAngle);
// ... many more members
};
Constructors
| Signature | Description |
|---|---|
Path() |
Creates an empty path. |
Path(const PointF* points, const BYTE* types, INT count) |
Creates a path from an array of points and type flags. |
Path(const Point* points, const BYTE* types, INT count) |
Creates a path from integer‑based points. |
Path(const Path& src) |
Copy constructor. |
Key Methods
| Method | Signature | Returns |
|---|---|---|
| AddLine | Status AddLine(const PointF& pt1, const PointF& pt2) |
Status::Ok on success. |
| AddLines | Status AddLines(const PointF* points, INT count) |
Status |
| AddArc | Status AddArc(const RectF& rect, REAL startAngle, REAL sweepAngle) |
Status |
| CloseFigure | Status CloseFigure() |
Status |
| Reset | Status Reset() |
Status |
| GetBounds | Status GetBounds(RectF* bounds, const Pen* pen = nullptr) const |
Status |
| SetFillMode | Status SetFillMode(FillMode fillMode) |
Status |
| GetFillMode | FillMode GetFillMode() const |
FillMode enumeration |
Properties
- FillMode – Determines how the interior of the path is filled (
FillModeAlternateorFillModeWinding). - PathData – Retrieves the raw point and type data for the path.
Remarks
A Path can contain multiple figures. Each figure can be opened with AddLine, AddBezier, or AddArc and closed with CloseFigure. If a figure is not closed, GDI+ automatically closes it when rendering.
Example
#include <windows.h>
#include <gdiplus.h>
using namespace Gdiplus;
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int nCmdShow) {
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, nullptr);
HWND hwnd = CreateWindowEx(0, L"STATIC", L"Path Demo", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 400, 300,
nullptr, nullptr, hInst, nullptr);
ShowWindow(hwnd, nCmdShow);
MSG msg;
while (GetMessage(&msg, nullptr, 0, 0)) {
if (msg.message == WM_PAINT) {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(msg.hwnd, &ps);
Graphics graphics(hdc);
Pen pen(Color(255,0,0,255), 2);
Path path;
PointF points[] = { {50,150}, {150,50}, {250,150}, {150,250} };
BYTE types[] = { PathPointTypeStart, PathPointTypeLine, PathPointTypeLine, PathPointTypeLine };
path.AddPath(&Path(points, types, 4), FALSE);
path.CloseFigure();
graphics.DrawPath(&pen, &path);
EndPaint(msg.hwnd, &ps);
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
GdiplusShutdown(gdiplusToken);
return (int)msg.wParam;
}