Unable to change text color

Hi, I have a class called WinConsole which contains several methods including a SetColor and a CreateConsole function. I've noticed that when I call SetColor after CreateConsole and more precisely after the following lines:

1
2
3
4
5
if(!SetConsoleScreenBufferSize(m_outConsole, { static_cast<short>(m_screenWidth), static_cast<short>(m_screenHeight) }))
{
   std::cout << GetStringError(GetLastError());
   return false;
}


that are within the CreateConsole function, the color doesn't change at all but if I place the call to SetColor before those lines it changes.
The things I've tried so far are debugging, see if the function fails and read briefly through the MSDN documentation to find something.
The code used for SetColor is this:

1
2
3
4
5
6
7
8
9
10
11
void SetColor(int arg_color)
{
    WORD lColor;
    CONSOLE_SCREEN_BUFFER_INFO csbi;

    if(GetConsoleScreenBufferInfo(m_outConsole, &csbi))
    {
        lColor = (csbi.wAttributes & 0xF0) + (arg_color & 0x0F);
        SetConsoleTextAttribute(m_outConsole, lColor);
    }
}


So I would be really happy if someone could give me some answers or advices on how to solve it and if it could be useful: I use MinGW 8.1.0 and CodeBlocks as an IDE. Thank You.
Last edited on
I may have stumbled on a fix. I had a similar problem. I couldn't change the font color anywhere in a document. I highlighted a word I wanted to change, then when the minitoolbar appeared, I clicked the arrow/triangle next to the font color icon, and selected a color from the the palette of standard colors on the expanded menu. Voila! The color changed and after that I could change anything in the document using the usual methods - clicking on the font color change icon.
http://www.traininginchennai.co.in/aws-training-in-chennai/
Topic archived. No new replies allowed.