Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to set entire console window background color with given RGB(SetConsoleScreenBufferInfoEx)?

how to set entire console window background color with given RGB(SetConsoleScreenBufferInfoEx)?

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Falconapollo
    wrote on last edited by
    #1

    I'm struggling at how to customize the console window background color. I have found that SetConsoleScreenBufferInfoEx may help me, but I don't know how to do it. I want to customize the background color like the properties window do. Anybody can help me?enter image description here And now what I have is customize the foreground color with RGB, here is my code:

    HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFOEX csbiInfo;
    csbiInfo.cbSize = sizeof(csbiInfo);
    GetConsoleScreenBufferInfoEx(hStdout, &csbiInfo);
    csbiInfo.ColorTable[6] = RGB(200, 255, 0);
    SetConsoleScreenBufferInfoEx(hStdout, &csbiInfo);
    SetConsoleTextAttribute(hStdout, 6);

    The more I do, the more I can do!

    L 1 Reply Last reply
    0
    • F Falconapollo

      I'm struggling at how to customize the console window background color. I have found that SetConsoleScreenBufferInfoEx may help me, but I don't know how to do it. I want to customize the background color like the properties window do. Anybody can help me?enter image description here And now what I have is customize the foreground color with RGB, here is my code:

      HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
      CONSOLE_SCREEN_BUFFER_INFOEX csbiInfo;
      csbiInfo.cbSize = sizeof(csbiInfo);
      GetConsoleScreenBufferInfoEx(hStdout, &csbiInfo);
      csbiInfo.ColorTable[6] = RGB(200, 255, 0);
      SetConsoleScreenBufferInfoEx(hStdout, &csbiInfo);
      SetConsoleTextAttribute(hStdout, 6);

      The more I do, the more I can do!

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      After a bit of experimentation I found that setting the background colour and then sending a clear screen (cls command) will set the entire background to the selected colour. The only bit I cannot find, is how to send a clear screen command from code. In the old ANSI.SYS days it was done by <ESC>[2J, but that does not seem to work in command.com windows. However by adding a system("cls") call I can get the entire screen to the new colour. The following code sets the background to white.

      SetConsoleTextAttribute(hStdout, BACKGROUND_BLUE | BACKGROUND_RED | BACKGROUND_GREEN);
      system("cls");

      Use the best guess

      F 1 Reply Last reply
      0
      • L Lost User

        After a bit of experimentation I found that setting the background colour and then sending a clear screen (cls command) will set the entire background to the selected colour. The only bit I cannot find, is how to send a clear screen command from code. In the old ANSI.SYS days it was done by <ESC>[2J, but that does not seem to work in command.com windows. However by adding a system("cls") call I can get the entire screen to the new colour. The following code sets the background to white.

        SetConsoleTextAttribute(hStdout, BACKGROUND_BLUE | BACKGROUND_RED | BACKGROUND_GREEN);
        system("cls");

        Use the best guess

        F Offline
        F Offline
        Falconapollo
        wrote on last edited by
        #3

        How to customize the color with RGB ? This is the real question.

        L 1 Reply Last reply
        0
        • F Falconapollo

          How to customize the color with RGB ? This is the real question.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          I don't think you can; the function accepts any combination of the single values [ RED | GREEN | BLUE ] which allows up to 8 colours (16 if you add the highlight flag). If you want full colour control then you should be looking to use a proper Windows application which lets you use the complete range of RGB values.

          Use the best guess

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups