line connecting two points in VC++

Anybody knows how to display two points connected via a line in MS Visual C++?
Yeah I made one here ( http://www.cplusplus.com/forum/general/8709/ ) - read both posts
Last edited on
there is a function to draw a line between two points.
see this code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
case WM_PAINT:
	BeginPaint(hwnd,&ps);
	
	//change color of lines
	hPen = CreatePen(PS_SOLID,1,RGB(r++ % 255,g++ % 255,b++ % 255));
	SelectObject(ps.hdc ,hPen);
		
	j=0;
	k=0;
	//make seven parallel squares
	while(k<7)
	{
		MoveToEx(ps.hdc ,cxCenter[0]+j,cyCenter[0]+j,NULL);
		LineTo(ps.hdc ,cxCenter[1]+j,cyCenter[1]+j);
		
		MoveToEx(ps.hdc ,cxCenter[1]+j,cyCenter[1]+j,NULL);
		LineTo(ps.hdc ,cxCenter[2]+j,cyCenter[2]+j);
		
		MoveToEx(ps.hdc ,cxCenter[2]+j,cyCenter[2]+j,NULL);
		LineTo(ps.hdc ,cxCenter[3]+j,cyCenter[3]+j);

		MoveToEx(ps.hdc ,cxCenter[3]+j,cyCenter[3]+j,NULL);
		LineTo(ps.hdc ,cxCenter[0]+j,cyCenter[0]+j);
		
		j += 3;
		k++;
	}		
	//for (k=0;k<500;k++)
	//	SetPixel(ps.hdc ,pd.Point[k].x ,pd.Point [k].y ,pd.Color[k]);

		
	DeleteObject(hPen);
	return 0;


this is a part of code i wrote some time back.
you need to take the device context first using beginpaint of getdc()
then create a pen using createpen(), this will be the color of your line.
now move to starting position by using moveto() or movetoex() and
then draw the line to the ending point using lineto() function.
in the end delete the pen using deleteobject.
simple!! i hope this is what you want.
ignore the rest of the details, just see the basic thing.

1
2
3
4
5
6
7
8
9
10
11
PAINTSTRUCT		ps;
HPEN			hPen;

BeginPaint(hwnd,&ps);//get dc

hPen = CreatePen(PS_SOLID,1,RGB(r++ % 255,g++ % 255,b++ % 255));
SelectObject(ps.hdc ,hPen);//create the pen and select it in dc

MoveToEx(ps.hdc ,cxCenter[0]+j,cyCenter[0]+j,NULL);//move to starting point
LineTo(ps.hdc ,cxCenter[1]+j,cyCenter[1]+j);//create the line to ending point
DeleteObject(hPen);//delete the pen. 

Topic archived. No new replies allowed.