Click here to Skip to main content
15,881,600 members
Articles / Programming Languages / C++
Article

Basic Graphics For Your Console Applications

Rate me:
Please Sign up or sign in to vote.
4.80/5 (36 votes)
12 Apr 2007CPOL3 min read 100K   5.1K   71   9
An article and Demo Project for basic graphics in console applications.

Image 1

Introduction

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

Background

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.

setCursor(CursorMode);

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.

C++
cursorInfo.bVisible  = FALSE;

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

C++
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.

C++
gf.setColor(FOREGROUND_GREEN  || FOREGROUND_INTENSITY);

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.

License

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


Written By
Web Developer
Turkey Turkey
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 3 Pin
Genius1523-Apr-14 1:42
Genius1523-Apr-14 1:42 
GeneralWarnings Pin
CodeSonx16-Jan-09 7:03
CodeSonx16-Jan-09 7:03 
Generalwrong palce Pin
Filipe Marques15-Dec-08 8:35
Filipe Marques15-Dec-08 8:35 
GeneralSetConsoleTitle(_title) Pin
manhatman17-Apr-07 9:33
manhatman17-Apr-07 9:33 
QuestionSource lost? Pin
qiuqianren2-Feb-07 21:29
qiuqianren2-Feb-07 21:29 
AnswerRe: Source lost? Pin
Firat Karakusoglu3-Feb-07 1:29
Firat Karakusoglu3-Feb-07 1:29 
AnswerRe: Source lost? Pin
PJ Arends3-Feb-07 14:12
professionalPJ Arends3-Feb-07 14:12 
GeneralRe: Source lost? Pin
MrGoodly3-Feb-07 14:59
MrGoodly3-Feb-07 14:59 
Exactly!!!!!

How can you give this idiot a 5, if he cant even get the source code up!!!!

GeneralRe: Source lost? Pin
cristitomi8-Mar-07 3:12
cristitomi8-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.