views:

446

answers:

5

What is the best way to draw things in the Console Window on the Win 32 platform using C++?

I know that you can draw simple art using symbols but is there a way of doing something more complex like circles or even bitmaps?

A: 

Not without usng ASCII art. Back in the days of DOS it was "fairly" easy to do by redesigning the character bitmaps. It might only be possible in windows by creating your own font, but im really not sure thats possible

Goz
then how did they make those old DOS games in console?
Thats not the "console". There is a switch from text mode to graphics mode ...
Goz
The console back then was not the same console as it is now.
anon
DOS games did not use the Win32 Console, they wrote graphics directly to video memory.
Kevin Panko
PS: REad up about Mode 13h ... you'll probably find most info on that :)
Goz
you're stuck with GDI buddy :)
Nick Brooks
+5  A: 

No you can't just do that because Win32 console doesn't support those methods. You can however use GDI to draw on the console window.

This is a great example of drawing a bitmap on a console by creating a child window on it: http://www.daniweb.com/code/snippet216431.html

And this tells you how to draw lines and circles:
http://www.daniweb.com/code/snippet216430.html

This isn't really drawing in the console though. This is sort of drawing "over" the console but it still does the trick pretty well.

Nick Brooks
+1  A: 

Perhaps you are talking about DOS programs, using VGA mode. A quick google search shows up a C tutorial.

drspod
is that possible with VC++ ? i don't want to be getting used to a new IDE.
+1  A: 

As Nick Brooks has pointed out, you can use GDI calls in console apps, but the graphics cannot appear in the same window as the text console I/O. This may not matter since you can draw text elements in GDI.

A simplified interface to GDI calls in console apps is provided by WinBGIm. It is a clone of Borland's DOS BGI API, but with extensions to handle resizable windows, mouse input, and 24bit colour models. Since it is available as source code, it also serves a good demonstration of using GDI in this way.

It is possible to either have both a console and the GDI window, or you can suppress the console window by specifying that the application is a GUI app (the -mwindows linker option in GNU toolchain) - not that specifying a GUI app really only supresses the console, it is only really a GUI app if it has a message loop. Having the console is good for debugging, since it is where stdout and stderr are output to by default.

Clifford
A: 

It is possible, albeit totally undocumented, to create a console screen buffer that uses an HBITMAP that is shared between the console window process and the calling process. This is the approach that NTVDM takes to display graphics once a DOS application switches to graphics mode.

Koro