Does anyone know how to restore a window (which does not belong to current process) to the state is was in previous to having been minimized?

I've been trying ShowWindow and SetForegroundWindow, but if the window was maximized, it will only restore it to it's RESTORE state (not maximized)

ShowWindowAsync(hWnd, SW_SHOW);
SetForegroundWindow(hWnd);

I have tried every flag for nCmdShow, but none work, and I've tried ShowWindow with them all as well as ShowWindowAsync.

Untested, but this should work provided you're running in the same session as the target process.

if (!IsWindowVisible(hWnd))
{
    ShowWindow(hWnd, SW_MINIMIZE);
    ShowWindow(hWnd, SW_RESTORE);
}

SetForegroundWindow(hWnd);

Thank's for taking the time to reply nullptr.
Unfortunately, this does not activate and show the window if it is minimized.

This appears to work fine.

SetForegroundWindow(hWnd);
if (!IsWindowVisible(hWnd) || IsIconic(hWnd))
{     
    ShowWindow(hWnd, SW_MINIMIZE);
    ShowWindow(hWnd, SW_RESTORE);
}

duplicate - ignore

That assumes, of course, you know the HWND handle of the window to be restored. If you don't already know it then you can find it by calling EnumWindows()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.