Before calling GetConsoleScreenBufferInfoEx
, you have to first set cbSize of CONSOLE_SCREEN_BUFFER_INFOEX
.
The simplest way is something like that:
//Example of changing palette
int main()
{
HANDLE outH = GetStdHandle(STD_OUTPUT_HANDLE); //It doesn't make sense to everytime call GetStdHandle
CONSOLE_SCREEN_BUFFER_INFOEX oldOne, newBuff;
oldOne.cbSize = sizeof(CONSOLE_SCREEN_BUFFER_INFOEX);
GetConsoleScreenBufferInfoEx(outH, &oldOne);
oldOne.srWindow.Bottom++; //After getting current buffer window usually makes smaller
newBuff = oldOne; //Copy your current to new
/* Edit your new buffer */
//Set your dreamed buffer
SetConsoleScreenBufferInfoEx(outH, &newBuff);
/* Do something */
//restore to defaults
SetConsoleScreenBufferInfoEx(outH, &oldOne);
return 0;
}
As you can see, all that I changed is oldOne.cbSize = sizeof(CONSOLE_SCREEN_BUFFER_INFOEX)
. It's important because in another way GetConsoleScreenBufferInfoEx
will failure. For more information go there. Pay attention that after changing your console palette, you will never restore it, so better add some lines to your code to save your previous one.