| | |
Console GDI
![]() |
•
•
Join Date: Dec 2008
Posts: 6
Reputation:
Solved Threads: 0
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 c++ Syntax (Toggle Plain Text)
#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 c++ Syntax (Toggle Plain Text)
#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
Last edited by chrischavez; Feb 4th, 2009 at 12:45 am.
•
•
•
•
This has no sense.
Drawing must be done in WM_PAINT
Console are not for drawing

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
Last edited by niek_e; Feb 4th, 2009 at 11:14 am.
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.
@marco
Thats like saying you should do all DirectX Drawing inside WM_PAINT
@marco
Thats like saying you should do all DirectX Drawing inside WM_PAINT
Knowledge is power -- But experience is everything
![]() |
Similar Threads
- VX2? Nail.exe? Aurora popups? H E L P ! (Viruses, Spyware and other Nasties)
- CoolWWW/ (Viruses, Spyware and other Nasties)
- Could some1 have a look please (Viruses, Spyware and other Nasties)
- Graphics In Pixel: Part II B (C)
- HilackThis Log (Viruses, Spyware and other Nasties)
- dxsetu.exe error (Viruses, Spyware and other Nasties)
- I have annoying 'Search Results for Poker Online' popups. Pls Help! (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: Running C++ program in the background
- Next Thread: Heap corruption probelm when i try to return std::string from function in dll
Views: 763 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api array arrays assignment binary borland c++ c/c++ calculator char class classes code compile compiler console constructor conversion convert count data delete desktop dll encryption error file forms fstream function functions game givemetehcodez graph homework http iamthwee ifstream input int java lazy lib link linker list loop looping loops map math matrix memory newbie news number objects output pointer pointers problem program programming project python qt random read recursion recursive reference return search sort sorting spoonfeeding string strings struct student studio system template templates text tree url variable vc++ vector video visual visualstudio win32 window windows winsock wordfrequency wxwidgets






