Gregory Van Vooren
Gregory Van Vooren

Reputation: 21

Programmatically hide an application on windows

Is there a way to programmatically hide an application on windows? I want to achieve the same thing as the windows+D shortcut, but for a single application. I want to do this from within that application (application consists of several windows, one of those can't be moved, resized, closed or minimized by the user). Application is written in c++ and uses Qt for the UI.

Upvotes: 1

Views: 2071

Answers (2)

Raindrop7
Raindrop7

Reputation: 3911

to do so it's so easy:

1- retrieve the handle to that window:

HWND hChild = GetDlgItem(hWnd, ID_MYCHILD);

2- send to it SW_SHOW either using ShowWindow or via SendMessage:

ShowWindow(hChild, SW_HIDE); // hide
ShowWindow(hChild, SW_SHOW); // show

SendMessage(hChild, SW_HIDE, 0, 0); // hide
SendMessage(hChild, SW_SHOW, 0, 0); // show
  • if the window doesn't belong to your application then:

1 - retrieve the main window with:

HWND hWnd = GetForegroundWindow(void);

2- use the above to hide/show it

Upvotes: 2

noelicus
noelicus

Reputation: 15055

ShowWindow(HwndWindow, SW_MINIMIZE);

Here's the MSDN ShowWindow documentation.

In addition you may find EnumChildWindows useful for finding all these windows if their handles aren't readily available to you.

Upvotes: 1

Related Questions