Print a color console screen

Sep 10, 2013 at 5:12am
I've created a calendar program that displays a full year calendar on screen, and I would like to be able to send the screen output to the printer, if I press , let's say, the "P" key. The calender is in color, along with graphic borders, etc. I'm using MS Visual C++ 2012 Express, and it's a console program. I don't feel comfortable trying to learn to program in windows mode. Is it possible to do it? If so, how? Everything I've researched, seems to require opening a file, then printing it, but I just want the screen that's shown, to be printed. Thanks for any help or suggestions.
Sep 10, 2013 at 7:33am
It will need winapi

Aceix
Sep 11, 2013 at 1:56am
@Aceix

I guess that means it can't be done in console mode, right? Or, can winapi be used in the console? I use a clearscreen function that, i believe, is winapi based, and I think that I may use others. Not sure, though. If the 'sending screen to the printer' idea is not feasible, then I'll drop the idea.
Sep 11, 2013 at 1:59am
closed account (Dy7SLyTq)
you can use pdcurses or winapi, which is not just gui. it is both console and gui. and this is just nitpicky but clearscreen is not winapi "based", rather a feature of the api. idk how to do the printer thing in windows(winapi might have something) unless you use sfml or something
Sep 11, 2013 at 3:00am
@DTSCode

I've had no luck on getting pdcurses installed. Or even smfl, for that matter. I try following directions, but I get errors, etc., so I quit trying. ( After 6 or 7 attempts ). Thanks for answering though. I'll just drop the notion of printing. I'll stick to a saving screen capture with the "ZoomIt" program, then printing the resulting picture.
Last edited on Sep 11, 2013 at 4:03am
Sep 11, 2013 at 6:57am
There is an article for using the console with colour in winAPI. Have a look at the page http://www.cplusplus.com/articles/Eyhv0pDG/.
Sep 11, 2013 at 11:43am
It won't matter what you do with the console. Windows printers don't work that way.

(Well, your printer might be able to receive a text stream with special color and other markup codes... but you have to know your printer pretty well to do that.)

To do stuff on the printer, render your text to a properly-initialized printer device context and then draw to the GDC.

Google "msdn printer device contexts" for the overview.

You'll need to use the following API functions:

  GetPrinter() - get a handle to the default printer
  CreateDC() - open a GDC for that printer
  StartDoc() - start a new job
  StartPage() - start a new page
  SetMapMode() - (do some reading about the kinds of things you can adjust)
  CreateFont() - create a font to use
  SelectObject() - select the font and pen to use
  TextOut() - write text with the font
  EndPage() - signal end of page
  EndDoc() - signal end of job
  DeleteDC() - done with printer DC (force print)

You change colors by selecting a pen to use.
1
2
SelectObject( hdc, GetStockObject( DC_PEN ) );  // Select a pen into the DC
SetDCPenColor( RGB( 255, 0, 0 ) );  // Set the pen's color to RED 

I know it looks like a lot, but it isn't really, especially considering that you are drawing a picture and sending it to the printer.

Hope this helps.
Sep 12, 2013 at 4:51am
@NTS

Thanks for the site, but , I already use color in my programs.

@Duoas

Thank you also, for your info. Most of that is over my head. I use, and program in, console mode. At this time, I don't understand the windows aspect of programming.

I have the calendar already showing on screen, so I'm not going to render it into anything else, but I do see that, at this time, that programming is beyond my capabilities.

Thanks to all that helped. I'll set this as solved, since I will not be pursuing it.
Sep 12, 2013 at 11:31am
What?

How did you learn to speak English?
To drive a car?
To do math?

Practice, practice, practice.

If you want to program, you can program. Anyone can program.*

The trick is to understand that there is never a point when you know it all. You will always be learning something. And every time you see something new, it will seem over your head. That's why the internet is littered with tutorials and examples, to help us get past the "holy crap I don't understand all this stuff" stage and into a more productive state.

If you want to program, and enjoy doing it, then keep doing it.

Of course, you must do what you want.

Good luck!


* Well, some people can't... but I doubt you are one of them, since you've already created a working program.
Topic archived. No new replies allowed.