How to restore a window without focus using WPF (or interop)

I need to restore ("un-minim") the WPF window that was already created, but the window that is currently on top (not necessarily WPF) cannot lose focus or activation . I tried using all the WIN32 features that I can find, but to no avail. In fact, disappointed in this, you really appreciate any pointers and tips.

Obviously, just changing to WindowState.Normal in WPF doesn't shorten it, as it makes the window get focus and activation as-well. I also tried all sorts of combinations with installing Hidden and IsEnabled during recovery.

I tried WIN32 SetWindowPos with HWND_TOP, HWND_TOPMOST, etc., but this function is not designed to restore windows and will only change the position of already "displayed" windows.

Tried WIN32 ShowWindow and SetWindowPlacement , but no luck. I tried a desperate attempt to add HwndHook to try to listen to WM_SETFOCUS and restore focus to the original window, but I only get zero for the last focused window handle.

Edit - a solution with a window extension after a prompt from Joel Lucsy:

 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); } } 
+7
source share
1 answer

A ShowWindow call that passes the SW_SHOWNOACTIVATE flag.

+6
source

All Articles