Multiple colors in one screen cmd
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 5 of 5

Thread: Multiple colors in one screen cmd

  1. #1
    Join Date
    Aug 2011

    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.

  2. #2
    Join Date
    Apr 2009

    Re: Multiple colors in one screen cmd

    The command line window stores characters and their colors in a big array.
    See 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.

  3. #3
    Join Date
    Aug 2011

    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

  4. #4
    Join Date
    Oct 2006

    Re: Multiple colors in one screen cmd

    I have never used it but this might an easier way than writing your own libs

    Edit: or this one maybe (see also
    Last edited by S_M_A; September 12th, 2011 at 01:18 PM.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    and before posting

    Refresh your memory on formatting tags here

    Get your free MS compiler here

  5. #5
    Join Date
    Aug 2011

    Re: Multiple colors in one screen cmd

    Ok i found the following solution:

    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;
    			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.ignore(numeric_limits<streamsize>::max(), '\n');
    						cout << " Invalid input, try again.";
    						cout << "\n Your choice(0..9): ";
    							case 1:
    							case 2:
    							case 3:
    							case 0:

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a survey!

HTML5 Development Center