Console GDI

Please support our C++ advertiser: Download Intel® Parallel Studio Eval
Reply

Join Date: Dec 2008
Posts: 6
Reputation: chrischavez is an unknown quantity at this point 
Solved Threads: 0
chrischavez chrischavez is offline Offline
Newbie Poster

Console GDI

 
0
  #1
Feb 4th, 2009
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
  1. #define _WIN32_WINNT 0x0500
  2. #include <iostream>
  3. #include <windows.h>
  4. #include "Pen.h"
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. Draw draw(0); ///Sets if the drawing is only in the cmd console or in the entire screen
  11. draw.SetPen(255,100,0,10); ///sets pen color and size SetPen(RED,GREEN,BLUE,PEN SIZE);
  12. while(true) // loop
  13. {
  14. draw.Pen(); /// draws pen
  15. Sleep(10);
  16. }//end
  17. return 0;
  18. }

Pen.h
  1. #ifndef PEN_H_INCLUDED
  2. #define PEN_H_INCLUDED
  3.  
  4. #include <iostream>
  5. #include <windows.h>
  6.  
  7. using namespace std;
  8.  
  9. class Draw{
  10. private:
  11. POINT p;
  12. HWND console;
  13. HDC hdc;
  14. int R;
  15. int G;
  16. int B;
  17. int Size;
  18. public:
  19. Draw(int i)
  20. {
  21. /// SetUP
  22. R=255;
  23. G=0;
  24. B=0;
  25. Size=10;
  26. if(i == 1){/// to draw in cmd window
  27. console = GetConsoleWindow();
  28. hdc = GetDC(console);
  29. SelectObject(hdc, CreatePen(0, Size, RGB(R,G,B)));
  30. GetCursorPos(&p);
  31. ScreenToClient(console, &p);
  32. MoveToEx(hdc, p.x, p.y, NULL);
  33. }else if(i==0){ /// draw on entire screen
  34. console = GetConsoleWindow();
  35. console = NULL;
  36. hdc = GetDC(0);
  37. SelectObject(hdc, CreatePen(0, Size, RGB(R,G,B)));
  38. GetCursorPos(&p);
  39. ScreenToClient(NULL, &p);
  40. MoveToEx(hdc, p.x, p.y, 0);
  41. }
  42. ///End
  43. }
  44. //Functions
  45.  
  46. void Pen();
  47. void Pen(int x, int y);
  48. void SetPen(int r, int g, int b, int s);
  49. // END
  50.  
  51. };
  52. ///Set pen color, Set Pen Size
  53. void Draw::SetPen(int r, int g, int b, int s){
  54. R=r;
  55. G=g;
  56. B=b;
  57. Size=s;
  58. SelectObject(hdc, CreatePen(0, Size, RGB(R,G,B)));
  59. }
  60.  
  61. /// Draws Pen using mousepos
  62. void Draw::Pen()
  63. {
  64. GetCursorPos(&p);
  65. ScreenToClient(console, &p);
  66. LineTo(hdc, p.x, p.y);
  67. }
  68.  
  69. ///using an x and y value input
  70. void Draw::Pen(int x, int y){
  71. GetCursorPos(&p);
  72. ScreenToClient(console, &p);
  73. LineTo(hdc, x, y);
  74. }
  75.  
  76.  
  77. #endif // PEN_H_INCLUDED
Last edited by chrischavez; Feb 4th, 2009 at 12:45 am.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 132
Reputation: marco93 is infamous around these parts marco93 is infamous around these parts marco93 is infamous around these parts 
Solved Threads: 13
marco93 marco93 is offline Offline
Junior Poster

Re: Console GDI

 
0
  #2
Feb 4th, 2009
This has no sense.
Drawing must be done in WM_PAINT
Console are not for drawing
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 3,158
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 324
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is online now Online
Cenosillicaphobiac

Re: Console GDI

 
0
  #3
Feb 4th, 2009
Originally Posted by marco93 View Post
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
Last edited by niek_e; Feb 4th, 2009 at 11:14 am.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 671
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: Console GDI

 
0
  #4
Feb 4th, 2009
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
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 6
Reputation: chrischavez is an unknown quantity at this point 
Solved Threads: 0
chrischavez chrischavez is offline Offline
Newbie Poster

Re: Console GDI

 
0
  #5
Feb 4th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 671
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: Console GDI

 
0
  #6
Feb 5th, 2009
Store what has been drawn by the user somehow, then redraw it
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 6
Reputation: chrischavez is an unknown quantity at this point 
Solved Threads: 0
chrischavez chrischavez is offline Offline
Newbie Poster

Re: Console GDI

 
0
  #7
Feb 5th, 2009
thanks but sorry to bother you how do i store what has been painted
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 671
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: Console GDI

 
0
  #8
Feb 6th, 2009
Store the points at which you have something drawn on the screen in an array/vector or what ever you feel is best.
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum


Views: 763 | Replies: 7
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC