-
September 12th, 2011, 05:48 AM
#1
Multiple colors in one screen cmd
Hi all,
i've found several things to change the font color in the system output.
You can also use (windows only) system("color xy");
or define it in main with: SetConsoleTextAttribute(hConsole, 7);
Only the thing is, these lines affect everything. I realy like to know how i can set 2 characters in red and 2 in bue or something
Or maybe you can tell: system("color xy") where to stop using the colors and define new characters.
-
September 12th, 2011, 08:05 AM
#2
Re: Multiple colors in one screen cmd
The command line window stores characters and their colors in a big array.
See http://www.arl.wustl.edu/~lockwood/c...23/CH23-1.html or search google with "color b800 video dos".
So, usually, you change the color of something by changing a few bytes in memory. The example is given in assembly, but it is the same thing for C, or maybe you can include some lines of assembly code into your C source file.
-
September 12th, 2011, 10:33 AM
#3
Re: Multiple colors in one screen cmd
Thanks for the reply, i think i have to make some time free for this, still a newbie
-
September 12th, 2011, 01:16 PM
#4
Re: Multiple colors in one screen cmd
Last edited by S_M_A; September 12th, 2011 at 01:18 PM.
-
September 12th, 2011, 04:51 PM
#5
Re: Multiple colors in one screen cmd
Ok i found the following solution:
Code:
void menu4()
{
HANDLE hStdout;
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
int col1 = 6; // Define colors.
int col2 = 7; // " "
int col3 = 3; // " "
int loop=1;
int men4;
while(loop==1){
system("CLS");
SetConsoleTextAttribute(hStdout, col1); // Set text color
cout << "\n ::Networking Tools::\n"; SetConsoleTextAttribute(hStdout, col2); // Change color back to original.
cout << "\n 1) Ping (Checks with icmp packet requests to see if a host is \"online\"."
<< "\n 2) Traceroute (Good way to follow your network packets)."
<< "\n 3) DNS Lookup (Gather DNS information)."; SetConsoleTextAttribute(hStdout, col3); cout
<< "\n\n 0) Return to main menu." << endl << endl; SetConsoleTextAttribute(hStdout, col2); cout
<< " Your choice (0..9): ";
while(!(cin >> men4)){
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << " Invalid input, try again.";
cout << "\n Your choice(0..9): ";
}
switch(men4){
case 1:
ping();
break;
case 2:
traceroute();
break;
case 3:
dnslookup();
break;
case 0:
return;
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|