Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to restore a window without giving it focus using WPF (or interop)
    primarykey
    data
    text
    <p>I need to <strong>restore</strong> ("un-minimize") a WPF window that has already been created but the window that's currently on top (not necessarily WPF) <strong>can't lose focus or activation</strong>. I have tried using all WIN32 functions I can find, to no avail. Getting really frustrated by now, would really appreciate any pointers and tips.</p> <p>Obviously just changing to <code>WindowState.Normal</code> in WPF doesn't cut it as this makes the window receive focus and activation as-well. I have also tried all sorts of combinations with setting <code>Hidden</code> and <code>IsEnabled</code> while restoring.</p> <p>I have tried WIN32 <code>SetWindowPos</code> with HWND_TOP, HWND_TOPMOST etc. but this function is not intended to restore windows and will only change position of already "displayed" windows.</p> <p>Tried WIN32 <code>ShowWindow</code> and <code>SetWindowPlacement</code> but no luck there either. Tried a desperate attempt at adding a HwndHook to try and listen for <code>WM_SETFOCUS</code> and restoring focus to the original window but i only get zero for the last focused window handle..</p> <p><strong>Edit - Solution with window extension after tip from Joel Lucsy:</strong></p> <pre><code>public static class RestoreWindowNoActivateExtension { [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] static extern bool ShowWindow(IntPtr hWnd, UInt32 nCmdShow); private const int SW_SHOWNOACTIVATE = 4; public static void RestoreNoActivate(this Window win) { WindowInteropHelper winHelper = new WindowInteropHelper(win); ShowWindow(winHelper.Handle, SW_SHOWNOACTIVATE); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload