threaz
threaz

Reputation: 403

win32 drawing function plot with brush

I'm supposed to write an application using win32 API which draws a function f(x)= x^2 plot. To accomplish this I'm asked to use HBRUSH structure, but there seems to be no appropriate procedure in win32 API. There are tons of them mostly used to draw complete shapes.

Is there one I can use to draw my plot point by point?

Upvotes: 0

Views: 373

Answers (1)

Brush is intended to draw surfaces, rect areas, filling, etc; you really need pens

Try this:

HDC hdc = /* init this */;
HPEN pen = CreatePen(PS_SOLID, 0, RGB(0, 0, 0));
HGDIOBJ old_pen = SelectObject(hdc, pen);

// move to first poing in plot
MoveToEx(hdc, startingpoint_x, statingpoint_y, NULL);

// executes for each point in plot
LineTo(hdc, pointx, pointy);

// clean up
SelectObject(hdc, old_pen);
DeleteObject(pen);

Upvotes: 1

Related Questions