Scale console to more than 800x800 visual-c++

Asked

Viewed 147 times

-1

Why can’t I resize the screen with 1400x900 "widthxheight"?
More precisely the width because I saw that the height I can enlarge with more than 800, 900 and with 1000 it already exceeds the windows toolbar.

#include <stdio.h>
#include <windows.h>
#define _WIN32_WINNT 0x0500

void resizeConsole(int, int);

int main()
{
    resizeConsole(1400, 900); //redimensionar a tela
    system("pause");
}
void resizeConsole(int width, int height)
{
    HWND console = GetConsoleWindow();
    RECT r;
    GetWindowRect(console, &r);
    MoveWindow(console, r.left, r.top, width, height, TRUE);
}

I read that, it won’t work because the width of the console is limited by default to 80 characters. And I need to change the screen buffer size in order to resize the screen. But I have no idea how to do this!
Someone understands me?
Resize the width to less than 800 I can, just as in the doubt of this enthusiast...
--> insert link description here <--

1 answer

0

I don’t know what kind of projects will fit this code but you should take a look at the GUI of c++ because it will be easier to work the window

If you want sizes much larger than the terminal allows you to double click on the terminal white bar and it will expand

but if you want to code tlvs the code below solve it or better even work with a GUI

but to do what you need you might want to work with Setconsolewindowinfo and Setconsolescreenbuffersize.

Here’s a little example

#include <windows.h>
#include <iostream>

using namespace std;

int main() {
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
SMALL_RECT sr;
COORD consoleSize;
cout << "Tamanho original\nPressionar enter para continuar..." << endl;
cin.get();

consoleSize.X = 50; consoleSize.Y = 25;

sr.Top=sr.Left=0;
sr.Right=49; sr.Bottom=24;

SetConsoleWindowInfo(console, TRUE, &sr);
SetConsoleScreenBufferSize(console, consoleSize);

cout << "50x25\nPressionar enter para continuar..." << endl;
cin.get();

consoleSize.X = 20; consoleSize.Y = 10;

sr.Right=19; sr.Bottom=9;

SetConsoleWindowInfo(console, TRUE, &sr);
SetConsoleScreenBufferSize(console, consoleSize);

cout << "20x10\nPressionar enter para continuar..." << endl;
cin.get();

consoleSize.X = 80; consoleSize.Y = 25;

sr.Right=79; sr.Bottom=24;

SetConsoleScreenBufferSize(console, consoleSize);
SetConsoleWindowInfo(console, TRUE, &sr);
return 0;
}

Edit:Had a small error in the code but it already works right

  • Very good! But it still does not enlarge beyond the original size, although the double click the console goes to the upper corner straight from the monitor the height can even extend to the limit of the Windows Toolbar but the width still can not exceed the initial size.

  • better even use a Voce GUI with the GUI can expand a lot even and will solve your problem then don’t forget to mark the answer to help others with your problem

Browser other questions tagged

You are not signed in. Login or sign up in order to post.