Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5844229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:15:46+00:00 2026-05-22T12:15:46+00:00

In the following code, how am I supposed to create a colored bar at

  • 0

In the following code, how am I supposed to create a colored bar at the bottom of the console??
The following code makes the bar at the very top but I wan’t to create the bar at the bottom. How am I supposed to do that?

void main(void)
{
    HANDLE hOutput = (HANDLE)GetStdHandle( STD_OUTPUT_HANDLE ); 
     // Set the text output position to (5,10) 
    COORD sPos; 
    sPos.X = 5; 
    sPos.Y = 10; 
    SetConsoleCursorPosition( hOutput, sPos ); 

    // Set the color to bright green 
    SetConsoleTextAttribute( hOutput, 
    FOREGROUND_INTENSITY | FOREGROUND_GREEN ); 

    // Write the text 
    DWORD nWritten; 
    WriteConsole( hOutput, "This is a test", 14, &nWritten, NULL );

    CHAR_INFO buffer[SCREEN_HEIGHT][SCREEN_WIDTH]; 

    COORD dwBufferSize = { SCREEN_WIDTH,SCREEN_HEIGHT }; 
    COORD dwBufferCoord = { 0, 0 }; 
    SMALL_RECT rcRegion = { 0, 0, SCREEN_WIDTH-1, SCREEN_HEIGHT-1 }; 

    WriteConsoleOutput( hOutput, (CHAR_INFO *)buffer, dwBufferSize, 
        dwBufferCoord, &rcRegion ); 
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:15:47+00:00Added an answer on May 22, 2026 at 12:15 pm

    Use GetConsoleScreenBufferInfo to obtain a CONSOLE_SCREEN_BUFFER_INFO structure.

    CONSOLE_SCREEN_BUFFER_INFO bufferInfo;
    GetConsoleScreenBufferInfo(hOutput, &bufferInfo);
    

    You can use srWindow which will give you the coordinates of the corners of the display-window.

    Use this to position the bar at the bottom:

    // bufferInfo is a structure CONSOLE_SCREEN_BUFFER_INFO.
    SMALL_RECT rcRegion = 
    { 
        bufferInfo.srWindow.Left, 
        bufferInfo.srWindow.Top, 
        SCREEN_WIDTH-1, 
        SCREEN_HEIGHT-1 
    }; 
    

    I am unsure if sr.Window.Left is ever anything but zero, but lets play safe.

    Update 1: I used Bottom in rcRegion, it should be Top. I misunderstood the original code.


    Now your code has some problems. First, you are using uninitialized memory and write it to the buffer. It will most typically result in hilarious effects.

    Second you need to understand that when you write a big region like that straight into the buffer you’ll overwrite anything you had there previously. This includes the text you write at the start.

    If you want to preserve it you will first need to read from the buffer, alter it and write back.

    Anyhow, how to fix the CHAR_BUFFER problem:

    CHAR_INFO buffer[SCREEN_HEIGHT][SCREEN_WIDTH]; 
    memset(&buffer, 0, sizeof(buffer));
    

    Zero it. This ensures that every character in the buffer will render a black void where it is written.

    Then we need to print out our bar. I use the character for lower case O here.

    for (int i = 0; i < SCREEN_WIDTH; i++)
    {
        buffer[SCREEN_HEIGHT - 1][i].Char.AsciiChar = 'o';
        buffer[SCREEN_HEIGHT - 1][i].Attributes = FOREGROUND_BLUE;
    }
    

    This should be pretty straightforward. You write a o to the last row in the buffer. We also tell it to make it blue. You can use “wide characters” (unicode) instead if you like, UnicodeChar = L'å'.

    This will render a result like:

    Console output on Win7 x86-64

    You can see some of the remaining problems here. Our buffer does not overwrite all of the screen area, leaving some pieces intact (you can see the result from cl.exe there in the margins.)

    Why this is should be pretty obvious: SCREEN_* does not correspond to the actual width and height of the window.

    Also my prompt ends up in the middle of the block, but that is mainly because our program does not clean up after exit. It is not visible until termination.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I expected the following code to print 8, 111 and 999. I supposed that
I've got the following code, which supposed to create a new item. Proxy type
The following LINQ to Entities query (using EF 4.1 Code-First), is supposed to create
I have the following code, which is supposed to create a form on the
Suppose I have the following: using(var ctx = DataContextFactory.Create(0)) { ... Some code ...
I am creating a SMS app the following code is supposed to: check if
Given the following code (it's supposed to write helloworld in a helloworld file, and
The following code supposed to read a file containing a set of molecular structures,
I have a factory that is supposed to create objects that inherit from class
I've translated the following C++ code to C#, but I can't determine where and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.