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
Sleep(10);
}//end
return 0;
}
Pen.h
#ifndef PEN_H_INCLUDED
#define PEN_H_INCLUDED
#include <iostream>
#include <windows.h>
using namespace std;
class Draw{
private:
POINT p;
HWND console;
HDC hdc;
int R;
int G;
int B;
int Size;
public:
Draw(int i)
{
/// SetUP
R=255;
G=0;
B=0;
Size=10;
if(i == 1){/// to draw in cmd window
console = GetConsoleWindow();
hdc = GetDC(console);
SelectObject(hdc, CreatePen(0, Size, RGB(R,G,B)));
GetCursorPos(&p);
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)));
GetCursorPos(&p);
ScreenToClient(NULL, &p);
MoveToEx(hdc, p.x, p.y, 0);
}
///End
}
//Functions
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){
R=r;
G=g;
B=b;
Size=s;
SelectObject(hdc, CreatePen(0, Size, RGB(R,G,B)));
}
/// Draws Pen using mousepos
void Draw::Pen()
{
GetCursorPos(&p);
ScreenToClient(console, &p);
LineTo(hdc, p.x, p.y);
}
///using an x and y value input
void Draw::Pen(int x, int y){
GetCursorPos(&p);
ScreenToClient(console, &p);
LineTo(hdc, x, y);
}
#endif // PEN_H_INCLUDED