How to hide the window that is displayed after the owner is minimized?

I know about the contract between Windows Owners and their Owner and that Own windows are hidden when the Owner is hidden. This is actually what I want. The problem is that if you show the Owned window after the Owner window is minimized, the Owned window will not be hidden, but it will display normally on the screen. In this case, the WindowState of the window is minimized at startup, so any displayed window that is displayed is displayed on the screen.

I know that I can call ShowOwnedPopups to make the OS hide all its own windows, but this only seems to work after the Owned window actually shows that you are seeing flickering on the screen. I tried to explicitly hide the window (for example, by removing the WS_VISIBLE bit or trying to change WM_SHOWCOMMAND so that it was hidden), but then the Owned window does not become visible when the owner is restored. This is consistent with the documentation for the ShowOwnedPopups API, in which the only windows that become visible are hidden calls to ShowOwnedPopups.

So, I'm looking for a way for the OS to display the window so that it is not visible to the end user until the owner is restored - or - a way to set a flag in the window so that the OS thinks it is hiding the window using ShowOwnedPopups, and then I will manually hide the window and set this flag.

Please note that the code that displays the Own windows is not associated with the shell, so it’s not easy not to show the owned window until the owner is restored. This is part of a separate custom control, in which case it is a WPF control, so the control can even be used in ElementHost, so I can’t just watch WindowState in its own window. Any Windows API solution is welcome.

+4
source share
1 answer

As a little dirty trick (which I used earlier in one of my projects), I suggest creating a window outside the visible area, minimizing it, and moving my position to the visible area again when it is minimized. Check out the code below.

private void Window_Loaded(object sender, RoutedEventArgs e) { var w = new Window(); // Create window w.Owner = this; // Set this window as owner w.WindowStartupLocation = System.Windows.WindowStartupLocation.Manual; // Set startup location as manual w.Left = -10000; // Set x position to -10000 (or anything which makes it out of bounds) w.Top = -10000; // Set y position to -10000 w.Show(); // Show window (it will not be shown, not even blink) w.WindowState = System.Windows.WindowState.Minimized; // Set window as minimized w.Left = 100; // Set x position to 100 (or whatever you want) w.Top = 100; // Set y position to 100 (or whatever you want) } 
0
source

Source: https://habr.com/ru/post/1397626/


All Articles