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

Thread: Multiple colors in one screen cmd

  1. #1
    Join Date
    Aug 2011
    Posts
    80

    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
    Posts
    598

    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.

  3. #3
    Join Date
    Aug 2011
    Posts
    80

    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
    Location
    Sweden
    Posts
    3,632

    Re: Multiple colors in one screen cmd

    I have never used it but this might an easier way than writing your own libs http://pdcurses.sourceforge.net/

    Edit: or this one maybe http://gnuwin32.sourceforge.net/packages/ncurses.htm (see also http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/)
    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
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    http://www.microsoft.com/visualstudio/eng/downloads

  5. #5
    Join Date
    Aug 2011
    Posts
    80

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center