Drawing in a Win32 console in C ++?

What is the best way to draw things in a console window on a Win 32 platform using C ++?

I know that you can draw simple art using symbols, but is there a way to make something more complex, like circles or even bitmap images?

+6
c ++ api winapi console
source share
6 answers

No, you cannot just do this because the Win32 console does not support these methods. However, you can use GDI to draw in the console window.

This is a great example of drawing a bitmap on the 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 is not really a console draw. This is a kind of drawing "on top" of the console, but it still does a good job of this.

+10
source share
#include <windows.h> #include <iostream.h> int main() { // Get window handle to console, and device context HWND console_handle = GetConsoleWindow(); HDC device_context = GetDC(console_handle); //Here a 5 pixels wide RED line [from initial 0,0] to 300,300 HPEN pen =CreatePen(PS_SOLID,5,RGB(255,0,0)); SelectObject(device_context,pen); LineTo(device_context,300, 300); ReleaseDC(console_handle, device_context); cin.ignore(); return 0; } 
+12
source share

It is possible, although completely undocumented, to create a console screen buffer that uses HBITMAP , which is shared between the console window process and the calling process. This is the approach that NTVDM takes to display graphics as soon as the DOS application switches to graphics mode.

Take a look.

+3
source share

Perhaps you are talking about DOS programs using VGA mode . A quick google search reveals a C-tutorial .

+2
source share

As Nick Brooks noted, you can use GDI calls in console applications, but graphics cannot be displayed in the same window as text I / O consoles. This can make a difference, as you can draw text elements in GDI.

A simplified interface for GDI calls in console applications is provided by WinBGIm . This is a clone of the Borland DOS BGI API, but with extensions for handling resizable windows, mouse input, and 24-bit color models. Since it is available as source code, it also serves as a good demonstration of using GDI in this way.

You can also have both a console and a GDI window, or you can disable the console window by indicating that the application is a graphical interface (the -mwindows linker option in the GNU toolchain) - note that specifying a GUI application really only suppresses the console, this is only GUI application if it has a message loop. Having a console is suitable for debugging, since stdout and stderr are displayed by default.

+2
source share

Not without usng ASCII art. Back in DOS, it was β€œpretty” easy to do by redesigning bitmaps for characters. This is only possible in windows, creating your own font, but im really not sure what is possible

0
source share

All Articles