我可以将窗口位置设置为最顶层,也可以使用 SetWindowPos
将其设置为非最顶层.但我不知道如何检查窗口是否在最上面。有没有什么方法可以用 pinvoke 检查窗口是否在最上面?
最佳答案
您可以使用 GetWindowLong()
检查 Extended Window Styles 的函数.
未经测试,但我相信它应该有效:
[DllImport("user32.dll", SetLastError=true)]
static extern int GetWindowLong(IntPtr hWnd, int nIndex);
const int GWL_EXSTYLE = -20;
const int WS_EX_TOPMOST = 0x0008;
public static bool IsWindowTopMost(IntPtr hWnd)
{
int exStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
return (exStyle & WS_EX_TOPMOST) == WS_EX_TOPMOST;
}
关于c# - 确定窗口是否在最顶层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36952600/