c# - 确定窗口是否在最顶层

标签 c# pinvoke

我可以将窗口位置设置为最顶层,也可以使用 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/

相关文章:

c# - 如何使用 Html Agility Pack 进行 HTML 验证

c# - 哪个更快?++、+= 或 x + 1?

c# - 在 C# 中设置风扇速度

c# - PInvoke 和 double*

c# - 检测是否从 P/Invoke 调用

javascript - 如何从 javascript 调用 user32.dll 方法

c# - 有没有比 DataTable.Load(DataReader) 更快/更智能的方法来填充数据表? C#

c# - 如何使用 GE Winforms API 更改 KMLTreeView 中地标条目的图标

c# - 列出 1...n 之间的 k 个整数的所有可能组合(n 选择 k)

c# - 如何使用 .NET P/调用 CryptUIWizExport 函数