Thread: different colors

  1. #16
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644

    Re: What about Visual C

    Originally posted by real_cozzy
    // This doesn't compile for me in Visual C.

    #include <stdlib.h>
    #include <stdio.h>
    #include <time.h>
    #include <conio.h>


    int main()
    {
    textcolor(RED);
    cprintf("this is left\n\n");
    textcolor(LIGHTGRAY);
    cprintf("back to same color");
    return 0;
    }
    That's because Visual C doesn't use textcolor. You have to do this:
    Code:
    #include <stdlib.h>
    #include <stdio.h>
    #include <time.h>
    #include <windows.h>
     
    
    int main() 
    { 
    	HANDLE hStdout;
    	hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
    	SetConsoleTextAttribute(hStdout, FOREGROUND_RED);
    	cprintf("this is left\n\n"); 
    	HANDLE hStdout;
    	hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
    	SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY);
    	cprintf("back to same color"); 
    	return 0; 
    }
    You can NOT use conio.h w/ VC++. I've already attempted it numerous times on two different computers.

  2. #17
    Registered User
    Join Date
    Jul 2002
    Posts
    3
    Found a way for making it go the RIGHT way >>

    Code:
    #include <stdio.h>
    #include <conio.h>
    
    main()
    {
    textcolor(RED);
    cprintf("this is left");
    printf("\n\n");
    textcolor(LIGHTGRAY);
    cprintf("back to same color");
    return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why I only get 8 colors out of ncurses?
    By Nazgulled in forum C Programming
    Replies: 3
    Last Post: 05-08-2007, 06:06 PM
  2. Relation between material colors and light colors.
    By indigo0086 in forum Game Programming
    Replies: 3
    Last Post: 04-18-2007, 03:20 PM
  3. colors in forefox and colors in IE
    By MisterSako in forum Tech Board
    Replies: 3
    Last Post: 05-15-2006, 01:59 PM
  4. colors?
    By planet_abhi in forum Game Programming
    Replies: 1
    Last Post: 09-10-2003, 05:37 PM
  5. Text Colors
    By GaPe in forum C Programming
    Replies: 1
    Last Post: 07-11-2002, 06:57 AM