I am using C++ in Visual Studio 2017, and I am making a text based game in the console window.
When I run my program, and it opens the console window, I want it to automatically go into full screen mode.
Here is my current attempt, where it resizes the console window, but it doesn't move to fill the screen and goes off of the edge
#include <Windows.h>
int main()
{
HWND window = GetDesktopWindow();
HWND console = GetConsoleWindow();
RECT r;
if (GetWindowRect(window, &r))
{
int width = r.right - r.left;
int height = r.bottom - r.top;
MoveWindow(console, 0, 0, width, height, TRUE);
}
}
When I run it, the console window opens to a random spot on the screen as normal, but then it grows to the size of the full screen, but the top left corner doesn't move.
When I run the program:
Edit: I do not need to use any of this info again, it’s a very basic game that I am just making for fun, and I thought it would look nicer if it was in full screen. I don’t know what half of this code means, all I want is a full screen console window
Is this what you are looking for?
#include <Windows.h>
int main()
{
HWND console = GetConsoleWindow();
RECT r;
if (GetWindowRect(GetDesktopWindow(), &r))
{
SendMessage(console, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
}
}
Or even:
#include <Windows.h>
int main()
{
SendMessage(GetConsoleWindow(), WM_SYSCOMMAND, SC_MAXIMIZE, 0);
}
But I'm sure you want the various Handles, etc for future use.