Question

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.

Était-ce utile?

La solution

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.

Autres conseils

Try ShowWindow(SW_MAXIMIZED). You would have to run a program you created, FindWindow(your target) and then invoke ShowWindow(SW_MAXIMIZED) on it. Note that this is achievable through AutoHotkey and no C++.

If you wanna maximize your program when it runs you can use this code in your Main Form

    __fastcall TMainForm::TMainForm(TComponent* Owner) : TForm(Owner)
{

           WindowState = wsMaximized;
}

Or if you want to maximize your program during codes e.g. pressing a button then you can use this code if it's in you're Main form:

ShowWindow(this->Handle, SW_SHOWMAXIMIZED);

Or this one if you're in a child one :

ShowWindow(Application->Handle, SW_SHOWMAXIMIZED);

This worked for me.

#include <windows.h>

void maximizeWindow(){
    HWND hwnd = GetConsoleWindow();
    ShowWindow(hwnd, SW_SHOWMAXIMIZED);
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top