Rainlendar's ability to place windows "on desktop" allows them to behave as bottomMost windows. This is not a built-in feature of WPF, but it can be achieved using Win32 API calls, which require P/Invoke from C#.
Rainlendar's Options:
Rainlendar offers two options for window placement:
Achieving On Desktop Placement:
To place a WPF window "on desktop," you can use the SetParent API:
[DllImport("user32.dll")] public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
Setting hWndNewParent to IntPtr.Zero removes the parent and makes the window a desktop child.
Achieving On Bottom Placement:
To keep a window "on bottom," you need to intercept the WM_WINDOWPOSCHANGING message:
protected override void WndProc(ref Message m) { if (m.Msg == (int) WM.WINDOWPOSCHANGING) { var pos = (WINDOWPOS) Marshal.PtrToStructure(m.LParam, typeof(WINDOWPOS)); // Check if the window is being promoted to the top if ((pos.flags & SWP_NOMOVE) == 0 && (pos.flags & SWP_NOSIZE) == 0) { pos.hwndInsertAfter = HWND_BOTTOM; pos.flags |= SWP_NOACTIVATE; Marshal.StructureToPtr(pos, m.LParam, true); } } base.WndProc(ref m); }
By setting hwndInsertAfter to HWND_BOTTOM and adding the SWP_NOACTIVATE flag, the window will always remain at the bottom and will not activate when clicked.
The above is the detailed content of How Can I Achieve 'On Desktop' and 'On Bottom' Window Placement in WPF?. For more information, please follow other related articles on the PHP Chinese website!