[ad_1]
I’m trying to set the size of the Windows terminal based on characters per row and the number of columns, not pixels. I’m a bit lost, but I figured out a few things so far.
To get the current number of dimensions of the console window in the units I want, I can do:
const auto hout = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(hout, &csbi);
// Bind x and y
const auto& [wx, wy] = csbi.dwMaximumWindowSize;
std::cout << " { " << wx << ", " << wy << " } " << std::endl;
Which, for me, outputs { 120, 56 }
. This means 120 chars/row and 56 visible rows.
My problem seems is that, to change this, I seem to have to convert these units to pixels and completely redraw the window. I know how to do this as well, assuming I knew the size I wanted for the window in terms of pixels:
HWND console = GetConsoleWindow();
RECT console_rect;
GetWindowRect(console, &console_rect);
MoveWindow(console, console_rect.left, console_rect.top, /* nWidth */, /* nHeight */, TRUE);
So, I need 1 of 2 solutions.
- Is there a way to skip the conversion and change the size of the window in terms of chars/row and number of visible rows? If not,
- How do I accurately convert from my preferred format to pixels? I’m assuming I have to take font sizes into account, which I’m also not completely sure how to do.
Thanks in advance for anyone who’s willing to help! I’m using C++20 and the Windows API.
[ad_2]