nico marty
nico marty

Reputation: 11

ShowWindow restores the window only if is the last minimized

I'm trying to make a program in C++ that shows a minimized calculator.

It works if I minimize it, but if I minimize the Calculator and then another program like firefox, the program doesn't show the calculator anymore.

int main()
{
    hwnd = FindWindow(NULL,TEXT("Calculator"));
    ShowWindow(hwnd, SW_SHOW);
    return 0;
}

Upvotes: 1

Views: 899

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 595392

If the calculator is minimized (see IsIconic()), then you should be using SW_RESTORE instead of SW_SHOW, per the ShowWindow() documentation:

SW_RESTORE
9

Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window.

SW_SHOW
5

Activates the window and displays it in its current size and position.

Try this:

int main()
{
    HWND hwnd = FindWindow(NULL, TEXT("Calculator"));
    if (hwnd)
    {
        if (IsIconic(hwnd))
            ShowWindow(hwnd, SW_RESTORE);
        else
            ShowWindow(hwnd, SW_SHOW);
    }
    return 0;
}

Upvotes: 3

Related Questions