I am currently in the process of developing my own Win32 console application, trying to incorporate all of the C++ theory we have learnt in the first year of uni, for revision purposes.
In order to do this, I obviously have to clear the screen of the console, for example, when I would like to display the menu, I need to get rid of the text from my word count feature.
I have tried the system("cls") from this Microsoft Help page & have also tried the Clrscr(); function, similar to the one in the Borland compiler, yet they both end up giving me a green screen on the console, instead of black (the only things that aren't green are the text from my displayMenu & displayHeaderFooter, functions & the background of that text.
Here is part of the code in my whole application which I think you will need to help:
CODE
//---PART OF THE CODE IN THE MAIN FUNCTION (int main)---\\
//DISPLAYING THE MENU AFTER AGE APPROVAL
keyPressed = getKeyPress();
if (keyPressed == 'M')
{
system("cls");
displayHeaderFooter(currentMonth, currentYear);
displayMenu(keyPressed, currentMonth, currentYear);
}
//---THE TWO FUNCTIONS I THINK YOU NEED TO HELP ME---\\
void displayHeaderFooter( int& currentMonth, int& currentYear)
{ //to paint the universal header and footer of the program on the screen
int currentDate;
int currentHour, currentMinute, currentSecond;
//FOOTER: COPYRIGHT MESSAGE:
Gotoxy(0, 23);
SelectTextColour( clDarkCyan);
cout << "--------------------------------------------------------------------------------"<< endl;
Gotoxy(0, 24);
SelectTextColour( clDarkGrey);
cout << "Developed by Calum Richardson © 2008"<< endl;
//HEADER: WELCOME MESSAGE TO THE USER:
Gotoxy(0, 0);
SelectTextColour( clGrey);
SelectBackColour( clDarkCyan);
cout << " " << "WELCOME" << " " << endl;
Gotoxy(22, 0);
SelectTextColour( clDarkCyan);
SelectBackColour( clBlack);
cout << "________________________________________________"<< endl;
//HEADER: RETRIEVING THE CURRENT DATE AND TIME:
time_t result;
result = time(NULL); //retrieving current date and time in long seconds
struct tm* tp = localtime(&result); //converting current (local)time into a struct for time attributes
currentDate = tp->tm_mday;
currentMonth = tp->tm_mon + 1; //month since January; May would be 4, add 1
currentYear = tp->tm_year + 1900; //year since 1900; 2008 would be 108
currentHour = tp->tm_hour;
currentMinute = tp->tm_min;
currentSecond = tp->tm_sec;
//DISPLAYING THE CURRENT DATE AND TIME:
Gotoxy(57, 0);
SelectBackColour( clDarkCyan);
SelectTextColour( clGrey);
cout << " " << currentDate << "/" << currentMonth << "/" << currentYear << " ";
Gotoxy(68, 0);
cout << "- ";
Gotoxy(71, 0);
cout << currentHour << ":" << currentMinute << ":" << currentSecond << " ";
//DISPLAYING END OF HEADER:
Gotoxy(0, 3);
SelectBackColour( clBlack);
SelectTextColour( clDarkGrey);
cout << "--------------------------------------------------------------------------------"<< endl;
} //end of the 'displayHeaderFooter' function
void displayMenu(int& keyPressed, int& currentMonth, int& currentYear)
{ //to the menu in the console
int getKeyPress();
void wordCounter(int& keyPressed, int& currentMonth, int& currentYear);
void endProgram();
Gotoxy(6, 6);
SelectTextColour( clGrey);
SelectBackColour( clBlack);
cout << "Please press the letter corresponding the option you wish to choose:";
Gotoxy(28, 9);
SelectTextColour( clDarkCyan);
cout << "Word count - (W)";
Gotoxy(28, 10);
cout << "Number count - (N)";
Gotoxy(28, 11);
cout << "Mouse & Cheese game - (G)";
Gotoxy(28, 12);
SelectTextColour( clGreen);
cout << "HELP - (H)";
Gotoxy(28, 13);
SelectTextColour( clYellow);
cout << "ABOUT - (A)";
Gotoxy(28, 14);
SelectTextColour( clRed);
cout << "EXIT - (E)";
keyPressed = getKeyPress();
if (keyPressed == 'W')
{
wordCounter(keyPressed, currentMonth, currentYear);
}
keyPressed = getKeyPress();
if (keyPressed == 'E')
{
endProgram();
}
} //end of the 'displayMenu' function
Any help really would be much appreciated. I'd just like the screen to be cleared to a black colour before I paint the Header, Footer & Menu onto the screen, instead of being cleared green.
Thank you in advance.
Calum.
----------------
Now playing on iTunes:
All-4-One - I Swearvia
FoxyTunes