CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Guest

    How to change the text color for a console app?

    I'm writing a console program and would like to display some of the characters (text) in yellow when in the DOS Prompt Box,
    how do I code it ?

    Thanks and regards.


  2. #2
    Join Date
    Oct 1999
    Posts
    9

    Re: How to change the text color for a console app?

    Hi,

    Use the API function SetConsoleTextAttribute.

    First, you need a handle to the screen buffer, if you are using standard I/O you can get this with a call to GetStdHandle:


    // Begin snippet
    HANDLE hScreen;

    hScreen = GetStdHandle (STD_OUTPUT_HANDLE);

    // Set the console text to green on a blue background
    SetConsoleTextAttribute (hScreen, FOREGROUND_GREEN | BACKGROUND_BLUE);
    // End Snippet




    The second paramater to SetConsoleTextAttribute specifies the colours and can be a combination of the following values:

    FOREGROUND_RED, FOREGROUND_GREEN, FOREGROUND_BLUE, FOREGROUND_INTENSITY, BACKGROUND_RED, BACKGROUND_GREEN, BACKGROUND_BLUE, and BACKGROUND_INTENSITY.

    Hope this helps.
    Darren.


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured