How to make a C++ program run maximized automatically?

Dishon picture Dishon · Aug 21, 2012 · Viewed 7.9k times · Source

I need to know whether there is a code for a C++ program to automatically maximize the program window since I always have to maximize the window when I run the program. I'm using Windows 7.

I am very much new to C++.

Can someone help me? Thanks.

Answer

Tejendra picture Tejendra · Aug 21, 2012

Try this It will Work

#include "stdafx.h"
#include "conio.h"
#include "Windows.h"
#include "tchar.h"

int _tmain(int argc, _TCHAR* argv[])
{
 //Write Your Code HERE//
  HWND hWnd;
  SetConsoleTitle(_T("test"));
  hWnd = FindWindow(NULL, _T("test"));
  HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
  COORD NewSBSize = GetLargestConsoleWindowSize(hOut);
  SMALL_RECT DisplayArea = {0, 0, 0, 0};

  SetConsoleScreenBufferSize(hOut, NewSBSize);

  DisplayArea.Right = NewSBSize.X - 1;
  DisplayArea.Bottom = NewSBSize.Y - 1;

  SetConsoleWindowInfo(hOut, TRUE, &DisplayArea);

  ShowWindow(hWnd, SW_MAXIMIZE);
 _getch();
  return 0;
}

It Will show your Output in Maximized Window.