Is there any simple function to draw a line from point a to point b?
Printable View
Is there any simple function to draw a line from point a to point b?
Code:MoveToEx(hDC, x1,y1,NULL);
LineTo(hDC,x2,y2);
If you're using Windows, there's the GDI function Line(). I forget the specifics of the parameters though.
I don't think there is a Line() function although there is LineTo, Polyline, PolylineTo
You could create your own Line() function with MoveToEx, and LineTo.
Code:void Line(HDC hDC, int x1, int y1, int x2, int y2)
{
MoveToEx(hDC,x1,y1,NULL);
LineTo(hDC,x2,y2);
}
There isn't?... Umm... oh.... umm... well okay then :rolleyes:... I could have sworn there was. Never mind.
Ok, thanks. Does this draw the line on the screen, or in the window? I was trying to create a class with some shapes (rectangle, point, segment, etc) and I didn't see any line being drawn.
It draws the line on a specified device context, (check out msdn in GDI programming)
If you want to draw to the window, you pass a device context handle you retrieve with GetDC(hwnd) where hwnd is the window handle
If you want to draw directly on the screen you pass the handle of GetDC(0)
If you want to draw lines with doublebuffering you create a memory dc with CreateCompatibleDC and pass that, then update the window with bitblt as needed.