Trouble with Lines

I found this simple enough code on the internet that gives you a parallel line, and I though wow that is pretty cool. From there I created a class for the function, and put some of its declarative things in private. It worked just fine. Then I created another function with the angle of the line changed. I found that in doing this you cannot for some strange reason have the declarative things privatized. I would like to know why? I was able to fix it by simply putting them back into each function, but it seems like a total waste of space doing this.

The main thing I cannot do is get the horizontal and vertical lines to move any further then where they are. You would think that it would be as easy as punching in some different numbers but it is not.
#include <iostream>
#include <Windows.h>
using std::cin;

class Lines
{
	/*
	Unable to privatize the following because if I do only one line appears.


	// Get window handle to console, and device context
	HWND a = GetConsoleWindow();
	HDC b = GetDC(a);

	// Here's a 5 pixels wide Green line [from initial 0,0] to 300,300
	HPEN c = CreatePen(PS_SOLID, 5, RGB(0, 255, 0));
	*/ 
public:
	Lines()
	{
		SetConsoleTitle (TEXT ("Graphics"));
	}

	void Parallel_Line()
	{
		// Get window handle to console, and device context 
		HWND a = GetConsoleWindow();
		HDC b = GetDC(a);

		// Here's a 5 pixels wide Green line [from initial 0,0] to 300,300
		HPEN c = CreatePen(PS_SOLID, 5, RGB(0, 255, 0));
		SelectObject(b, c);
		LineTo(b, 300, 300);

		ReleaseDC(a, b);
	}

	void Vertical_Line()
	{
		// Get window handle to console, and device context 
		HWND a = GetConsoleWindow();
		HDC b = GetDC(a);

		// Here's a 5 pixels wide Green line [from initial 0,0] to 300,300
		HPEN c = CreatePen(PS_SOLID, 5, RGB(0, 255, 0));

		SelectObject(b, c);
		LineTo(b, 100, 1800);

		ReleaseDC(a, b);
	}

	void Horizontal_Line()
	{
		// Get window handle to console, and device context 
		HWND a = GetConsoleWindow();
		HDC b = GetDC(a);

		// Here's a 5 pixels wide Green line [from initial 0,0] to 300,300
		HPEN c = CreatePen(PS_SOLID, 5, RGB(0, 255, 0));

		SelectObject(b, c);
		LineTo(b, 1800, 100);

		ReleaseDC(a, b);
	}
};

int main()
{
	Lines use;

	use.Parallel_Line();
	use.Vertical_Line();
	use.Horizontal_Line();
	cin.get();
}// main.cpp 

Comments

Sign In or Register to comment.