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

  • console programs do not support graphics beyond very travel things. You need to write a win32 program to do more complex things.
  • Would trivial things be good for someone like me. :P
  • No, not really, as you have already found out.
  • I hate to ask a dumb question. When or what was it that I have done that has been trivial? Post #1 of this thread, or just about everything I know how to do.
  • I didn't mean to imply the things you have done are travel but what can be done with console programs.
  • Not related to lines or anything, but I came across some information from a random Joe. Claiming C++11 users should use nullptr instead of NULL for srand. Is it true what effect would it have?
  • you might want to read this discussion
Sign In or Register to comment.