Aspect and format of the console
I would like to change the aspect and the format fo the shell used to launch the following code:
Code:
#include <windows.h>
#include <stdio.h>
int main()
{
HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO InfCon;
GetConsoleScreenBufferInfo(hCon, &InfCon);
if (!GetConsoleScreenBufferInfo(hCon, &InfCon))
{
printf("GetConsoleScreenBufferInfo failed %d\n", GetLastError());
return 1;
}
printf("x: %d, y: %d\n", InfCon.dwSize.X, InfCon.dwSize.Y);
InfCon.dwSize.X = 50;
InfCon.dwSize.Y = 50;
if (!SetConsoleScreenBufferSize(hCon, InfCon.dwSize))
{
printf("SetConsoleScreenBufferSize %d\n", GetLastError());
return 1;
}
return 0;
}
but the console don't change and also get an error:
Code:
C:\Users\Quasar999\Documents\Source\WIN32\Win32_0016\ConsoleApplication1\x64\Release>ConsoleApplication1
x: 120, y: 9001
SetConsoleScreenBufferSize 87
C:\Users\Quasar999\Documents\Source\WIN32\Win32_0016\ConsoleApplication1\x64\Release>
Re: Aspect and format of the console
Quote:
Originally Posted by
Quasar999
I would like to change the aspect and the format fo the shell used to launch the following code:
Code:
#include <windows.h>
#include <stdio.h>
int main()
{
HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO InfCon;
GetConsoleScreenBufferInfo(hCon, &InfCon);
if (!GetConsoleScreenBufferInfo(hCon, &InfCon))
{
printf("GetConsoleScreenBufferInfo failed %d\n", GetLastError());
return 1;
}
printf("x: %d, y: %d\n", InfCon.dwSize.X, InfCon.dwSize.Y);
InfCon.dwSize.X = 50;
InfCon.dwSize.Y = 50;
if (!SetConsoleScreenBufferSize(hCon, InfCon.dwSize))
{
printf("SetConsoleScreenBufferSize %d\n", GetLastError());
return 1;
}
return 0;
}
but the console don't change and also get an error:
Code:
C:\Users\Quasar999\Documents\Source\WIN32\Win32_0016\ConsoleApplication1\x64\Release>ConsoleApplication1
x: 120, y: 9001
SetConsoleScreenBufferSize 87
C:\Users\Quasar999\Documents\Source\WIN32\Win32_0016\ConsoleApplication1\x64\Release>
According to the documentation this error means:
Quote:
ERROR_INVALID_PARAMETER
87 (0x57)
The parameter is incorrect.
Did you check whether the HANDLE hCon is correct/valid?
Re: Aspect and format of the console
Quote:
Originally Posted by
VictorN
According to the documentation this error means:
Did you check whether the HANDLE hCon is correct/valid?
Changed the code, but output is the same:
#include <windows.h>
#include <stdio.h>
int main()
{
HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
if (hCon == INVALID_HANDLE_VALUE) {
printf("GetStdHandle Error");
return 1;
}
CONSOLE_SCREEN_BUFFER_INFO InfCon;
GetConsoleScreenBufferInfo(hCon, &InfCon);
if (!GetConsoleScreenBufferInfo(hCon, &InfCon))
{
printf("GetConsoleScreenBufferInfo failed %d\n", GetLastError());
return 1;
}
printf("x: %d, y: %d\n", InfCon.dwSize.X, InfCon.dwSize.Y);
InfCon.dwSize.X = 50;
InfCon.dwSize.Y = 50;
if (!SetConsoleScreenBufferSize(hCon, InfCon.dwSize))
{
printf("SetConsoleScreenBufferSize %d\n", GetLastError());
return 1;
}
return 0;
}
Re: Aspect and format of the console
You can't change the buffer size to be less than the size of the console window. Note that there are two sizes - the size of the buffer and the size of the window. The window is a 'picture' of the buffer where the window 'moves' over the buffer. This is how scrolling is done. The window size can't be larger than the buffer. The buffer can't be smaller than the window.
It looks like you want to change the size of the console window. Consider:
Code:
#include <windows.h>
#include <stdio.h>
int main() {
HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
if (hCon == INVALID_HANDLE_VALUE) {
printf("GetStdHandle Error");
return 1;
}
CONSOLE_SCREEN_BUFFER_INFO InfCon;
if (!GetConsoleScreenBufferInfo(hCon, &InfCon)) {
printf("GetConsoleScreenBufferInfo failed %d\n", GetLastError());
return 1;
}
printf("x: %d, y: %d\n", InfCon.srWindow.Right - InfCon.srWindow.Left + 1, InfCon.srWindow.Bottom - InfCon.srWindow.Top + 1);
InfCon.srWindow.Right = InfCon.srWindow.Left + 50;
InfCon.srWindow.Bottom = InfCon.srWindow.Top + 30;
if (!SetConsoleWindowInfo(hCon, true, &InfCon.srWindow)) {
printf("SetConsoleWindowInfo %d\n", GetLastError());
return 1;
}
}
This changes the window size for me. Note that if error 87 is returned then the window has been given an invalid size.