Open Andrek25 opened 4 years ago
The documentation in the library here is poor. The behavior you're seeing is expected.
#foregroundize
calls SetForegroundWindow
which, according to that MSDN doc, has the following limitations:
The system restricts which processes can set the foreground window. A process can set the foreground window only if one of the following conditions is true:
- The process is the foreground process.
- The process was started by the foreground process.
- The process received the last input event.
- There is no foreground process.
- The process is being debugged.
- The foreground process is not a Modern Application or the Start Screen.
- The foreground is not locked (see LockSetForegroundWindow).
- The foreground lock time-out has expired (see SPI_GETFOREGROUNDLOCKTIMEOUT in SystemParametersInfo).
- No menus are active.
In this case, clicking on another window prevents the cmd window from being able to successfully call SetForegroundWindow
.
There is no foreground process.
Is there a way to set foreground to null or something? i tried:
Win32::Window::SetForegroundWindow.call(nil)
Win32::Window::SetForegroundWindow.call(0)
Win32::Window::SetForegroundWindow.call(-1)
But none of those worked.
So if my process is not the foreground process i will not be able to show my window again?
When I try to show the window while the CMD window where the program is running is inactive, it does not show the window, it seems that the CMD must be active for it to work.
Example: