How to get the HWND of the next window that will be active when you minimize the foreground window?

Viewed 98

Scenario: there's windows X in the foreground, when you minimize it, it will bring windows Y to the front or the desktop.

What WINAPI i could use to get the HWND of Y, before minimizing X?

I tried this:

HWND hWndnext = GetWindow(hWnd, GW_HWNDNEXT);

but it didn't return the HWND i was looking for.

I'm trying to set my window transparent upon trying to minimize, but not letting it be minimized, and after it gets transparent, activate/focus whatever would be the next window case it really was minimized, and upon clicking on it again restore the transparency to default.

My second attempt was:

case WM_SYSCOMMAND:
{
    if (wParam == SC_MINIMIZE) {

        DefWindowProc(hWnd, msg, wParam, lParam);

        BYTE alpha = GetWindowAlpha(hWnd) ? 0 : 255;

        // Update the window transparency.
        DWORD exstyle = GetWindowLongW(hWnd, GWL_EXSTYLE);
        SetWindowLongW(hWnd, GWL_EXSTYLE, exstyle | WS_EX_LAYERED);
        SetLayeredWindowAttributes(hWnd, 0, alpha, LWA_ALPHA);

        // Attempt to restore the window without activating it.
        ShowWindow(hWnd, SW_SHOWNOACTIVATE);
        return 0;

    }
    break;
}

But it still ain't focusing the next window into the taskbar.

1 Answers

The EnumWindows() API allows to get the list of windows by Z-order.

Related