Reputation: 121
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.
Upvotes: 4
Views: 10892
Reputation: 642
This worked for me.
#include <windows.h>
void maximizeWindow(){
HWND hwnd = GetConsoleWindow();
ShowWindow(hwnd, SW_SHOWMAXIMIZED);
}
Upvotes: 2
Reputation: 1934
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.
Upvotes: 7
Reputation: 152
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);
Upvotes: 2
Reputation: 2026
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++.
Upvotes: 2