Click here to Skip to main content
13,448,134 members (55,213 online)
Click here to Skip to main content
Add your own
alternative version


70 bookmarked
Posted 2 Feb 2007

Basic Graphics For Your Console Applications

, 12 Apr 2007
Rate this:
Please Sign up or sign in to vote.
An article and Demo Project for basic graphics in console applications.


By using the f_graph.h header file you can create new visual affects for your console window.


Generally, students studying at some colleges work with console applications and learn the basics of programming by developing these kind of programs. I have written this header file for whom, who need some basic graphic functions such as, clrscr() especially for DevC++ users or additional functions like box() which creates a box on the console window.

Using the code

Now let's look at the member functions in f_graph.h header file and explain how to use them.


CursorMode's type is enumeration and its members are CURSOR_OFF, CURSOR_ON and CURSOR_BIG. While CursorMode is CURSOR_OFF, no cursor shown on the screen. Because as we see below, its visibility is set false in the function.

cursorInfo.bVisible  = FALSE;

While mode is CURSOR_ON, we see the default cursor on the screen. 10% height and visibility on.

cursorInfo.dwSize  = 10; 
cursorInfo.bVisible  = TRUE;

Respectively, getDimensionX() gets the current length of x dimension, and getDimensionY() gets y's. The whereX() function returns the cursor position on x axis, and whereY() returns y's. goBeginPixels(), sets our cursor to the position (1,1). And goRight(), goLeft(), goUp(), goDown() functions sets our cursor to the given positions.

clrscr() clears the console window. Especially sets the colors with default ones (white text on black background).

gotoxy(int,int), as we know, sets our cursor to the given position.

setTitle(const char*), is used to change console window's title.

wait(int), in fact this function is using default Sleep() function, but I think, wait is much suitable to be meaningful.

setColor(WORD), as we see, we can change the colors of our window screen, and also WORD can be, FOREGROUND_BLUE, FOREGROUND_GREEN, FOREGROUND_RED, FOREGROUND_INTENSITY, BACKGROUND_BLUE, BACKGROUND_GREEN, BACKGROUND_RED or BACKGROUND_INTENSITY. For example, we can make shining green color by writing the code below.


Next, as I said at the beginning, there are some additional functions, such as box or some other functions that uses all eboves and works as a member for our template shape (makeSkeleton(WORD)) such as headerLine(char *). Ok,it is time to explain them.

First, box(int,int,int,int), as I mentioned before, this function makes a box with the given directions.

Then, clearArea(int,int,int,int), clears the area within those directions. In fact, it fills with space character in those area.

showTextInBox(char *,bool,bool ,int ,int ,int ,int ), with this function, you can write a text within a box that you determine the size. If size of that box comes enough for text, all shown in the box, but, if not, for the remain part, there will be created a new box with the same size with a stream that you control. Also you can specify, if the text will be a new beginning or not.

The functions below were written for our template shape.

makeSkeleton(const WORD), makes our template shape with the given color.

showLeftSide(char *,bool), this function shows the text given, in the box (small one) that positioned on the left side. Also you can specify, if the text will be a new beginning or not.

showRightSide(char *,bool,bool), this function shows the text given, in the box (big one) that positioned on the right side. And you can specify, if the text will be a new beginning or not. Moreover, you can control the page stream.

headerLine(char *), shows the text given in the box on the top. Also, the text is positioned to the center automatically.

footerLine(char *), shows the text given in the box on the bottom. You can use this for taking information from the user.

rightBottomText(char *,const WORD), with this function, you can write some text to outside of the boxes for alerting people. Also, this function positions the text to the right side.

blink(char *,const WORD), this function makes blinked texts by using given text.

warning(char *), makes given text blinked red at the bottom of the outside.

message(char *), makes given text blinked blue at the bottom of the outside.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Firat Karakusoglu
Web Developer
Turkey Turkey
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralMy vote of 3 Pin
Genius1523-Apr-14 1:42
memberGenius1523-Apr-14 1:42 
GeneralWarnings Pin
CodeSonx16-Jan-09 7:03
memberCodeSonx16-Jan-09 7:03 
Generalwrong palce Pin
Member 458341415-Dec-08 8:35
memberMember 458341415-Dec-08 8:35 
GeneralSetConsoleTitle(_title) Pin
manhatman17-Apr-07 9:33
membermanhatman17-Apr-07 9:33 
QuestionSource lost? Pin
qiuqianren2-Feb-07 21:29
memberqiuqianren2-Feb-07 21:29 
AnswerRe: Source lost? Pin
Firat KARAKUSOGLU3-Feb-07 1:29
memberFirat KARAKUSOGLU3-Feb-07 1:29 
AnswerRe: Source lost? Pin
PJ Arends3-Feb-07 14:12
memberPJ Arends3-Feb-07 14:12 
GeneralRe: Source lost? Pin
MrGoodly3-Feb-07 14:59
memberMrGoodly3-Feb-07 14:59 
GeneralRe: Source lost? Pin
cristitomi8-Mar-07 3:12
membercristitomi8-Mar-07 3:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02-2016 | 2.8.180318.3 | Last Updated 12 Apr 2007
Article Copyright 2007 by Firat Karakusoglu
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid