C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28629
Number of posts: 94611

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Blink and color text using textcolor () Posted by Ashu2912 on 1 Nov 2010 at 10:19 PM
While executing the below code, I expected to get the PLAYER MENU string in red and blinking mode. However, I do not get so. Please help me as I need to get this code ready ASAP.

Note : Have tried textattr () function as well. I'm using Turbo C++ Version 3.0.

PS : Sorry for posting such a long code for such a minor error. Thank you for your time and energy.


See this code:

void menu ()
{
int x1, y1, x2, y2, x3, y3;
char choice;
textcolor (YELLOW);
textbackground (0);
do
{
clrscr ();
disptime ();
cout << "\t ";
x1 = wherex ();
y1 = wherey ();
for (int i = 1; i <= 55; i ++)
cout << "_";
x2 = wherex () - 1;
y2 = wherey ();
gotoxy (x1, y1 + 1);
cout << "|";
gotoxy (x2, y2 + 1);
cout << "|";
gotoxy (x1, y1 + 2);
cout << "|";
gotoxy (x2, y2 + 2);
cout << "|";
gotoxy (x1, y1 + 3);
cout << "|";
textcolor (RED + BLINK);
cout << "\t\t PLAYER MENU";
textcolor (YELLOW);
gotoxy (x2, y2 + 3);
cout << "|";
gotoxy (x1, y1 + 4);
cout << "|";
gotoxy (x2, y2 + 4);
cout << "|";
gotoxy (x1, y1 + 5);
cout << "|";
cout << "\t\t (1) Enter new player";
gotoxy (x2, y2 + 5);
cout << "|";
gotoxy (x1, y1 + 6);
cout << "|";
cout << "\t (2) Update player details";
gotoxy (x2, y2 + 6);
cout << "|";
gotoxy (x1, y1 + 7);
cout << "|";
cout << "\t\t (3) Modify player details";
gotoxy (x2, y2 + 7);
cout << "|";
gotoxy (x1, y1 + 8);
cout << "|";
cout << "\t (4) Search player";
gotoxy (x2, y2 + 8);
cout << "|";
gotoxy (x1, y1 + 9);
cout << "|";
cout << "\t (5) Delete player";
gotoxy (x2, y2 + 9);
cout << "|";
gotoxy (x1, y1 + 10);
cout << "|";
cout << "\t (6) Hourly Lucky Draw";
gotoxy (x2, y2 + 10);
cout << "|";
gotoxy (x1, y1 + 11);
cout << "|";
cout << "\t (7) Silver Club Championship";
gotoxy (x2, y2 + 11);
cout << "|";
gotoxy (x1, y1 + 12);
cout << "|";
cout << "\t (8) Instruction manual";
gotoxy (x2, y2 + 12);
cout << "|";
gotoxy (x1, y1 + 13);
cout << "|";
cout << "\t (9) System Settings";
gotoxy (x2, y2 + 13);
cout << "|";
gotoxy (x1, y1 + 14);
cout << "|";
cout << "\t (0) Exit";
gotoxy (x2, y2 + 14);
cout << "|";
gotoxy (x1, y1 + 15);
cout << "|";
gotoxy (x2, y2 + 15);
cout << "|";
gotoxy (x1, y1 + 16);
cout << "|";
cout << "\t\t Enter your choice here :- ";
x3 = wherex ();
y3 = wherey ();
gotoxy (x2, y2 + 16);
cout << "|";
gotoxy (x1, y1 + 17);
cout << "|";
gotoxy (x2, y2 + 17);
cout << "|";
gotoxy (x1, y1 + 18);
cout << "|";
gotoxy (x2, y2 + 18);
cout << "|";
gotoxy (x1, y1 + 19);
cout << "|";
gotoxy (x2, y2 + 19);
cout << "|";
gotoxy (x1, y1 + 20);
cout << "|";
gotoxy (x2, y2 + 20);
cout << "|";
gotoxy(x1, y1 + 20);
for (i = 1; i <= 55; i ++)
cout << "-";
gotoxy (x3, y3);
choice = getche ();
switch (choice)
{
case '1' : newplayer ();
break;
case '2' : update ();
break;
case '3' : break;
case '4' : break;
case '5' : break;
case '6' : break;
case '7' : break;
case '8' : break;
case '9' : break;
case '0' : break;
default : gotoxy (x1 + 1, y1 + 18);
cout << "\t\t Invalid choice. Try again!!!";
getch ();
}
} while (choice != '0');
}

Report
Re: Blink and color text using textcolor () Posted by pseudocoder on 2 Nov 2010 at 6:38 AM
try using cprintf instead of cout... cprintf("|");

if the program is run in an emulated window (2k, xp, vista, etc), then you may get goofy output as these functions were designed for the text mode screen.
Report
Re: Blink and color text using textcolor () Posted by Ashu2912 on 2 Nov 2010 at 7:12 AM
I tried it mate. Some weird characters are coming in the line of 'PLAYER MENU'. Thanks for you time.
Report
Re: Blink and color text using textcolor () Posted by pseudocoder on 2 Nov 2010 at 4:34 PM
the weird char is probably the tabs in the strings.

If you need or want to draw a border around your menu, check your docs for charset codes. I can't recall all of them now, but there are some for making two or three different box styles... it may depend on your keyboard layout though.

If you don't have the docs, just use a loop to cycle through them

unsigned i;

for(i=128; i < 256; i++) {   
   printf("0x%2X %c\n", i, i);   
}


Something like that.
Report
Re: Blink and color text using textcolor () Posted by Ashu2912 on 2 Nov 2010 at 11:55 PM
What are tabs in the strings?
Report
Re: Blink and color text using textcolor () Posted by pseudocoder on 8 Nov 2010 at 1:48 PM
I'm thinking the odd character is the \t you've got in the strings; it's probably printing the character mapped to 0x09.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.