Nohsib
Nohsib

Reputation: 3722

How to trigger maximize/minimize in windows programming

For windows programming in C++, how to make active window to either maximize or minimize?

For mouse down events we use something like mi.dwFlags = MOUSEEVENTF_LEFTDOWN and send it to the system using SendInput() function. I assume these are defined in windows.h.

How to achieve the maximize or minimize on these lines?

Upvotes: 2

Views: 4608

Answers (2)

Trubiso
Trubiso

Reputation: 21

You can get the foreground window with this code:

#include <windows.h>
HWND foregroundWindow = GetForegroundWindow();

and then minimize the foreground window using foregroundWindow as handle

ShowWindow(foregroundWindow, SW_MINIMIZE);

or maximize it

ShowWindow(foregroundWindow, SW_MAXIMIZE);

But I don't know how to know other windows' handle, you can google it or ask here in StackOverflow how to get windows by its process name or by PID.

Upvotes: 0

Michael
Michael

Reputation: 55435

Use the ShowWindow function, with either SW_MAXIMIZE or SW_MINIMIZE.

Upvotes: 3

Related Questions