I know I have posted this before but this is a small utility to work with to change the colors and change the location of text and what not. Works well with vc++.
Code:
#ifndef _CONSOLE_LIBRARY_INTERFACE
#define _CONSOLE_LIBRARY_INTERFACE
#include <windows.h>
WORD cl_fc_param = 0;
WORD cl_bc_param = 0;
void text_color(bool red, bool green, bool blue, bool bright)
{
#ifdef _INC_IOSTREAM
cout.flush();
#endif
cl_fc_param = 0;
if ( red ) cl_fc_param |= FOREGROUND_RED;
if ( green ) cl_fc_param |= FOREGROUND_GREEN;
if ( blue ) cl_fc_param |= FOREGROUND_BLUE;
if ( bright ) cl_fc_param |= FOREGROUND_INTENSITY;
SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE), cl_fc_param|cl_bc_param );
}
void text_background(bool red, bool green, bool blue, bool bright)
{
#ifdef _INC_IOSTREAM
cout.flush();
#endif
cl_bc_param = 0;
if ( red ) cl_bc_param |= BACKGROUND_RED;
if ( green ) cl_bc_param |= BACKGROUND_GREEN;
if ( blue ) cl_bc_param |= BACKGROUND_BLUE;
if ( bright ) cl_bc_param |= BACKGROUND_INTENSITY;
SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE), cl_fc_param|cl_bc_param );
}
void text_loc(int x, int y)
{
#ifdef _INC_IOSTREAM
cout.flush();
#endif
COORD cursor_coordinates;
cursor_coordinates.X = x;
cursor_coordinates.Y = y;
SetConsoleCursorPosition( GetStdHandle(STD_OUTPUT_HANDLE), cursor_coordinates );
}
void console_title(const char* title)
{
SetConsoleTitle(title);
}
#endif
Anyways, here is a snippet of code that should help you accomplish what you want. What it attempts to do is set up a string that it as long as the buffer screen and print it to the string (there probably is a better way, i never tried system("CLS") with colors active). Then it sets the text location to the center minus an offset for the name length and prints it out.
Code:
void ShowEndScreen(const char * name)
{
const int xmax = 80;
const int ymax = 25;
int buff[xmax*ymax];
memset(buff, 0, xmax*ymax); // string.h
text_color(0, 1, 0, 0); // red green blue bright
text_background(0, 1, 0, 0); // same
text_loc(0, 0);
cout << buff;
text_loc( ymax/2, xmax/2 - strlen(name)/2 ); // I think the row is mentioned first, you might want to flip
text_color(1, 1, 1, 1); // same as above
cout << name;
}