我有一个生成全屏窗口的小型 .NET 程序。我想将此窗口保留在最后面的窗口(即其他窗口应在其顶部打开,并且单击时不应出现在最前面)。在 Windows Presentation Foundation 下有什么实用的方法可以做到这一点吗?
问问题
1427 次
1 回答
2
据我所知,您必须 P/Invoke 才能正确执行此操作。调用SetWindowPos
函数,指定窗口句柄和HWND_BOTTOM
标志。
这会将您的窗口移动到 Z 顺序的底部,并防止它遮挡其他窗口。
示例代码:
Private Const SWP_NOSIZE As Integer = &H1
Private Const SWP_NOMOVE As Integer = &H2
Private Const SWP_NOACTIVATE As Integer = &H10
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Private Shared Function SetWindowPos(hWnd As IntPtr, hWndInsertAfter As IntPtr,
X As Integer, Y As Integer,
cx As Integer, cy As Integer,
uFlags As Integer) As Boolean
End Function
Public Sub SetAsBottomMost(ByVal wnd As Window)
' Get the handle to the specified window
Dim hWnd As IntPtr = New WindowInteropHelper(wnd).Handle
' Set the window position to HWND_BOTTOM
SetWindowPos(hWnd, New IntPtr(1), 0, 0, 0, 0,
SWP_NOSIZE Or SWP_NOMOVE Or SWP_NOACTIVATE)
End Sub
于 2011-02-19T07:22:01.287 回答