i Wrote some basic code on something i saw here i while ago and was wondering what people could do with it. it uses a console and you can draw on the console or the entire desktop. i was hopping there was thing people could do to add or improve my code. if you get linker errors you have to add the libgdi32.a library Main.cpp

#define _WIN32_WINNT 0x0500
#include <iostream>
#include <windows.h>
#include "Pen.h"

using namespace std;

int main()
	Draw draw(0); ///Sets if the drawing is only in the cmd console or in the entire screen
	draw.SetPen(255,100,0,10); ///sets pen color and size SetPen(RED,GREEN,BLUE,PEN SIZE);
	while(true) // loop
		draw.Pen(); /// draws pen
	return 0;



#include <iostream>
#include <windows.h>

using namespace std;

class Draw{
	HWND console;
	HDC hdc;
	int R;
	int G;
	int B;
	int Size;
	Draw(int i)
		/// SetUP
		if(i == 1){/// to draw in cmd window
		console = GetConsoleWindow();
		hdc = GetDC(console);
		SelectObject(hdc, CreatePen(0, Size, RGB(R,G,B)));
		ScreenToClient(console, &p);
		MoveToEx(hdc, p.x, p.y, NULL);
		}else if(i==0){ /// draw on entire screen
		console = GetConsoleWindow();
		console = NULL;
		hdc = GetDC(0);
		SelectObject(hdc, CreatePen(0, Size, RGB(R,G,B)));
		ScreenToClient(NULL, &p);
		MoveToEx(hdc, p.x, p.y, 0);

	void Pen();
	void Pen(int x, int y);
	void SetPen(int r, int g, int b, int s);
	// END

///Set pen color, Set Pen Size
void Draw::SetPen(int r, int g, int b, int s){
	SelectObject(hdc, CreatePen(0, Size, RGB(R,G,B)));

/// Draws Pen using mousepos
void Draw::Pen()
	ScreenToClient(console, &p);
	LineTo(hdc, p.x, p.y);

///using an x and y value input
void Draw::Pen(int x, int y){
	ScreenToClient(console, &p);
	LineTo(hdc, x, y);

#endif // PEN_H_INCLUDED

This has no sense.
Drawing must be done in WM_PAINT
Console are not for drawing

Why not? If it's possible? Try thinking outside the box :)

To be honest, I can't think of any uses right now, but if were to make a console-based hangman game or something in that order, this might come in useful

Well if one was to hide the console window and paint on the main window / active window you could use it in conjunction with something like presentations as a pointing aidor something like that.

Thats like saying you should do all DirectX Drawing inside WM_PAINT :)

Well my use for this was for presentations. so i can draw on the screen. only problem is that if it draws over anything that changes or moves the line is deleted on that area

Store the points at which you have something drawn on the screen in an array/vector or what ever you feel is best.

This article has been dead for over six months. Start a new discussion instead.