'how to make console automatically zoom to full screen when running (In C++)

I want to make a game by coding on Visual Studio. When I run code, the console will appear but it's small. And I need to press maximize to make it full screen.

After I google about window.h, I use this code:

void ConsoleSize(SHORT width, SHORT height)
{
    HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);

    SMALL_RECT WindowSize;
    WindowSize.Top = 0;
    WindowSize.Left = 0;
    WindowSize.Right = width;
    WindowSize.Bottom = height;

    SetConsoleWindowInfo(hStdout, 1, &WindowSize);
}

But it only makes the console bigger, not automatically full screen. So please help me. Thanks. I'm not good at English so my question will have some grammatical errors. Sometimes it doesn't do what I want but I sincerely thank you all.



Solution 1:[1]

I have written two functions, maxsc() and fullsc() are two different full screen, you could use these two functions separately to see if it can meet your needs.

#include<iostream>
#include<Windows.h>
using namespace std;
void maxsc()
{
    HWND Hwnd = GetForegroundWindow();
    ShowWindow(Hwnd, SW_MAXIMIZE);
}
void fullsc()
{
    HWND Hwnd = GetForegroundWindow();
    int x = GetSystemMetrics(SM_CXSCREEN);
    int y = GetSystemMetrics(SM_CYSCREEN);
    LONG winstyle = GetWindowLong(Hwnd, GWL_STYLE);
    SetWindowLong(Hwnd, GWL_STYLE, (winstyle | WS_POPUP | WS_MAXIMIZE) & ~WS_CAPTION & ~WS_THICKFRAME & ~WS_BORDER);
    SetWindowPos(Hwnd,HWND_TOP,0,0,x,y,0);

}
int main()
{
    //maxsc();
    fullsc();
    return 0;
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1