Changing the Console text back to black

This is a discussion on Changing the Console text back to black within the C++ Programming forums, part of the General Programming Boards category; Okay before I begin, I DID use Search and I found nothing. Okay, to buisness. I know how to do ...

  1. #1
    Unregistered
    Guest

    Unhappy Changing the Console text back to black

    Okay before I begin, I DID use Search and I found nothing.

    Okay, to buisness. I know how to do the text color changing stuff. The problem is, I want to change it back to a black background and white text at times. I know about combining colors and all that, but I can't black for the background (I can do white for the text)! Any help would be greatly appreciated. Also, I'm using MVC++ 6 Standard Edition.

    Brendan

  2. #2
    Unregistered
    Guest
    Could someone PLEASE help??? I mean, someone here MUST know how to, you're all much better at this sort of thing than me. Why is it that when people post questions that've been asked a gazillion times you answer those but you don't answer ones that haven't been asked before? I'm not trying to sound rude or anything, but I really need the help, and I haven't been able to get it. Thanks.

  3. #3
    Unregistered
    Guest
    Lol oops now I feel exceptionally stupid. I found out how to by mistake. I accidentally forgot to add background color info. when i wanted to change the color again, and I found out that not adding any code for changing background color puts it back to black. Lol I'm sorry.

    Brendan

  4. #4
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    by the way, how DO you change console colors at all?
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  5. #5
    Unregistered
    Guest
    What compiler do you have? It depends.

    Brendan

  6. #6
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    if you are using a windows compiler you can use SetConsoleAttrib() or something like that, or if you are using a pure dos compiler you can use the conio.h functions to do it (I forget which ones)

  7. #7
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    i found this one in wincon.h:

    Code:
    SetConsoleTextAttribute(
        HANDLE hConsoleOutput,
        WORD wAttributes
        );
    but i cant work out how to use wAttributes. any ideas?
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >but i cant work out how to use wAttributes.
    They are macros like FOREGROUND_RED and FOREGROUND_INTENSITY that can be OR'd together like so:

    SetConsoleTextAttribute ( handle, FOREGROUND_RED | FOREGROUND_INTENSITY );

    This creates bright red text.

    -Prelude
    My best code is written with the delete key.

  9. #9
    Unregistered
    Guest
    >but i cant work out how to use wAttributes.

    There's several, and I'll list them here:
    ------------------------------------------------------------------------------------
    FOREGROUND_RED // a dark red for text
    FOREGROUND_GREEN // a dark green for text
    FOREGROUND_BLUE // a dark blue for text
    FOREGROUND_INTENSITY // brightens text color

    BACKGROUND_RED // dark red for background of text
    BACKGROUND_GREEN // dark green for background of text
    BACKGROUND_BLUE // dark blue for background of text
    BACKGROUND_INTENSITY // background is brightened
    ------------------------------------------------------------------------------------
    You may want to use #define or something and just call, for instance, FOREGROUND_RED something like fRed so it's easier and less typo-prone.

    To use, you would just do the following (in MSVC++):
    ------------------------------------------------------------------------------------
    #include <iostream.h> // cout
    #include <windows.h> // text stuff

    // pretend i already did all the #define thingys listed above
    HANDLE stdHand=GetStdHandle(STD_OUTPUT_HANDLE);

    int main()
    {
    SetConsoleTextAttribute(stdHand, fBlue | bGreen | bIntens);
    cout << "See the blue text on the green background?\n";
    return 0;
    }
    ------------------------------------------------------------------------------------
    You can also combine colors to make a new one; for example, bRed, bGreen, bBlue, and bIntens would make a white background. This is done as follows:
    ------------------------------------------------------------------------------------
    SetConsoleTextAttribute(stdHand,fBlue | fIntens | bRed | bGreen |
    bBlue | bIntens);
    cout << "Now it's light blue text over white. Oooo.\n";
    ------------------------------------------------------------------------------------
    Hope that helps.

    Brendan

    Also, I'm still at a loss with these tag things. [code] That's not working.

  10. #10
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    yeah that works

    wow, red on black, blue on orange, its too much for me

    by the way, to do code, do this:

    [ c o d e ]


    /* code here */


    [ / c o d e ]

    but without all the spaces inbetween
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  11. #11
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    if you can only do red, green and blue, plus bright versions of those, doesn't that mean there are only 12 colors to choose from? that doesn't seem very good.

    (even though its just the console :-)
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  12. #12
    Registered User
    Join Date
    Jul 2002
    Posts
    6
    Ok, lets try that then...

    Code:
    void SetPoint(Point * pt, int x, int y)
    {
            ...
    }
    Hey wow it does work. Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 05-25-2005, 01:50 PM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. Scrolling text in a DOS CONSOLE box
    By Blizzarddog in forum C++ Programming
    Replies: 4
    Last Post: 04-06-2004, 02:27 PM
  4. Back to console apps.
    By elfjuice in forum C++ Programming
    Replies: 9
    Last Post: 01-14-2004, 10:16 PM
  5. structure with 2-dim array
    By sballew in forum C Programming
    Replies: 8
    Last Post: 10-27-2001, 04:30 PM

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