text color

This is a discussion on text color within the C++ Programming forums, part of the General Programming Boards category; in a consoel app (dos) i know you can change the color by using something like font[1] and 1 stands ...

  1. #1
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608

    text color

    in a consoel app (dos) i know you can change the color by using something like font[1] and 1 stands for red or something wut do i use for changing text color
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  2. #2
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    does no one know!?!??!?!?!!?!
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    145
    I always use <conio.h> and their textcolor, although it may not work for you...
    Code:
    textcolor(RED);
    textbackground(BLACK);
    clrscr();
    You have to do a clrscr(); afterwards to have the changes take effect. That means that only 1 color on the screen at a time, there is a way to do it with more than 1 color, I am sure if you keep posting someone will give you the code.
    Anyhow, look through conio.h for all of the colors that you can use, and I think you must always type them in capitals.
    RED, BLUE, GREEN, YELLOW, LIGHTCYAN, stuff like that, check out conio.h

    Hope that helps. And if I am way off topic (as usual), just ignore me (as usual )
    "Um...well..."
    -Kyoto Oshiro

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    317
    Code:
    the colors can be mixed 
    
    FOREGROUND_BLUE Text color contains blue. 
    FOREGROUND_GREEN Text color contains green. 
    FOREGROUND_RED Text color contains red. 
    FOREGROUND_INTENSITY Text color is intensified. 
    BACKGROUND_BLUE Background color contains blue. 
    BACKGROUND_GREEN Background color contains green. 
    BACKGROUND_RED Background color contains red. 
    BACKGROUND_INTENSITY Background color is intensified. 
    
    
    #include <windows.h>
    #include <stdio.h>
    
    int main( void )
    {
    
        HANDLE hStdout;
    
        hStdout = GetStdHandle(STD_OUTPUT_HANDLE); 
        SetConsoleTextAttribute(hStdout, FOREGROUND_RED);
        
        printf("WWWWOOOOO MY TEXT IS RED WWOOOOO!!");
    
        return 0;
    }
    --------------------------------------------------------------------------------
    This has been asked a couple of times, I recommend checking the search feature located above on the right.

  5. #5
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Traveller's example works for all C/C++ compilers, Kyoto's example works for Dev-C++ (and maybe gcc compilers to)

  6. #6
    Registered User raimo's Avatar
    Join Date
    Jun 2002
    Posts
    107
    Originally posted by Kyoto Oshiro
    You have to do a clrscr(); afterwards to have the changes take effect. That means that only 1 color on the screen at a time, there is a way to do it with more than 1 color, I am sure if you keep posting someone will give you the code.
    Actually the standard output methods don't work right with textcolor()/textbackground(). That's why there was cprintf() or similar in conio.h, if I remember correct(I don't have conio.h in my current compiler). With cprintf() you need the Windows's CR\LF for newline.

    Originally posted by Quantrizi
    Traveller's example works for all C/C++ compilers, Kyoto's example works for Dev-C++ (and maybe gcc compilers to)
    Works only if it supports WinAPI. DJGPP's gcc supports that but gnu gcc doesn't.
    Last edited by raimo; 07-13-2002 at 11:57 AM.

  7. #7
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Well, I am pretty sure only gcc compilers (like MingW, Cygin (or something like that)) have conio.h because msvc++ doesn't.
    [edit]If you use textcolor() and/or textbackground(), you have to include conio.o[/edit]

  8. #8
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    i use dev c++ 4. but it doesnt have the header file conio.o can someone uplaod it to a post so i can download it?
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  9. #9
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    conio.o is something u have to link to. conio.h is the header file. conio.o is in the lib folder

  10. #10
    Registered User
    Join Date
    Feb 2002
    Posts
    145
    raimo, actually you can do cout<< and it display text color...
    Code:
    #include <iostream.h>
    #include <conio.h>
    
    int main()
    {
    textcolor(LIGHTBLUE);
    textbackground(BLACK);
    clrscr();
    cout<< "This will be Light Blue on a Black background.\n";
    return(0);
    }
    That always gets the job done. You can't use standard cout<< and such for the way Traveller showed.
    "Um...well..."
    -Kyoto Oshiro

  11. #11
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    duh! i wasnt born yesterday. i did it right its jsut i dont have that lib file for some reason caus ei tried to compile it and it said it didnt have the file
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  12. #12
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    oh its conio.h on earlier posts u said it was conio.o
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  13. #13
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    sorry about that....

  14. #14
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    i compiled it, btu isntea dof lookign at a dos mode window (im in a console app)

    a windows window popped up saying

    on the window bar it said compiler lnker out and input
    C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3b2b):comput~1. cpp: undefined reference to `textbackground'
    C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3b33):comput~1. cpp: undefined reference to `clrscr'
    C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3b3d):comput~1. cpp: undefined reference to `textcolor'
    C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3b4a):comput~1. cpp: undefined reference to `textbackground'
    C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3b52):comput~1. cpp: undefined reference to `clrscr'
    C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3b81):comput~1. cpp: undefined reference to `textcolor'
    C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3b8e):comput~1. cpp: undefined reference to `textbackground'
    C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3b96):comput~1. cpp: undefined reference to `clrscr'
    C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3bc5):comput~1. cpp: undefined reference to `textcolor'
    C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3bd2):comput~1. cpp: undefined reference to `textbackground'
    C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3bda):comput~1. cpp: undefined reference to `clrscr'
    C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3c09):comput~1. cpp: undefined reference to `textcolor'
    C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3c16):comput~1. cpp: undefined reference to `textbackground'
    C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3c1e):comput~1. cpp: undefined reference to `clrscr'
    C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3c4d):comput~1. cpp: undefined reference to `textcolor'
    C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3c5a):comput~1. cpp: undefined reference to `textbackground'
    C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3c62):comput~1. cpp: undefined reference to `clrscr'
    what does this mean
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  15. #15
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Ok, I ain't accusing u of being a n00b, but this is a step-by-step process:

    1. Include conio.h
    2. Right click on the project name
    3. Go to project options
    4. Go to "Further object files or linker options"
    5. Type this in: C:\Dev-C++\Lib\conio.o
    6. Click ok

    C:\Dev-C++\ may not the directory, but you know what to do if it ain't

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GUI Text Color Problem
    By justlivelife15 in forum Windows Programming
    Replies: 3
    Last Post: 06-25-2007, 05:47 AM
  2. Change text color in C
    By IndioDoido in forum C Programming
    Replies: 9
    Last Post: 04-15-2007, 05:54 AM
  3. Critique my lighting model.
    By psychopath in forum Game Programming
    Replies: 4
    Last Post: 08-12-2006, 06:23 PM
  4. Color text from windows.h?
    By Saintdog in forum C++ Programming
    Replies: 10
    Last Post: 12-03-2004, 08:20 AM
  5. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 09:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21