关于C#:如何检查窗口是否始终位于顶部?

How to check if window is “Always on top”?

在我有用的热键程序中,我有一个全局热键,可通过调用

将当前的前台窗口设置为最高/最高

1
2
SetWindowPos(hwnd, HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
SetWindowPos(hwnd, HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);

目前我必须有两个单独的热键,Win Z将窗口设置为TOPMOST和Win X将窗口设置为NOTOPMOST。

我无法在MSDN中找到一个可以让您检查Windows z顺序的函数。我希望获得诸如GetWindowOrder之类的东西,但没有。我也尝试过检查Windows ex标志,如下所示:

1
dwExStyles & WS_EX_TOPMOST

但是标志似乎从未改变过,它只是告诉窗口在第一次创建时将其设置为最高位置。

是否有检查功能?


我认为您可以这样做:

1
2
3
4
5
6
DWORD dwExStyle = ::GetWindowLong(m_hWnd, GWL_EXSTYLE);

if ((dwExStyle & WS_EX_TOPMOST) != 0)
{
    // do stuff
}

这是MSDN链接-http://msdn.microsoft.com/zh-cn/library/ms633584(VS.85).aspx

这是扩展样式的MSDN链接-http://msdn.microsoft.com/zh-cn/library/ff700543(v=VS.85).aspx-最顶部当前列为" TBD" :)


您正在寻找GetWindow()

Retrieves a handle to a window that
has the specified relationship
(Z-Order or owner) to the specified
window.