【发布时间】:2015-06-14 20:28:47
【问题描述】:
我有一个录音程序,它一直保持TopMost,除非我打开Modern app (Windows 8) 或Start Screen。
可以使桌面应用程序保持在现代应用程序之上,例如Magnifying Glass 工具:
现在,问题是在 WPF 窗口中使用 TopMost 选项和/或 API 调用不适用于现代应用程序。
我正在尝试什么:
static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
static readonly IntPtr HWND_TOP = new IntPtr(0);
static readonly IntPtr HWND_BOTTOM = new IntPtr(1);
const UInt32 SWP_NOSIZE = 0x0001;
const UInt32 SWP_NOMOVE = 0x0002;
const UInt32 TOPMOST_FLAGS = SWP_NOMOVE | SWP_NOSIZE;
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
//OnLoaded event handler:
var source = PresentationSource.FromVisual(this) as HwndSource;
SetWindowPos(source.Handle, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS);
【问题讨论】:
-
这是不可能的。就像您不能在全屏 DirectX 游戏上显示窗口一样。也许在 Windows 10 中,还没玩过。
-
但是示例图像发生了什么? Win32 应用程序运行在一切之上。