简体   繁体   English

确定窗口是否在最顶层

[英]Determine if a window is topmost or not

I am able to set a windows position as topmost and also setting it no topmost with SetWindowPos . 我可以将Windows位置设置为最高,也可以使用SetWindowPos将其设置为最高。 But i can't figure out how to check if a window is topmost or not. 但我不知道如何检查窗口是否最顶层。 Is there any Method to check if a window is topmost or not with pinvoke? 是否有任何方法可以通过pinvoke检查窗口是否位于最顶层?

You can use the GetWindowLong() function to check the Extended Window Styles . 您可以使用GetWindowLong()函数来检查扩展窗口样式

Untested, but I believe it should work: 未经测试,但我认为它应该可以工作:

[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;
}

Depending on the UI technology you*re using, you can choose of the following two: 根据您正在使用的UI技术,您可以选择以下两种:

You can you those properties to check if a certain window is topmost and you can also use these to set a window topmost. 您可以使用这些属性来检查某个窗口是否位于最顶部,也可以使用这些属性将窗口设置为最顶部。 I'd prefer these in favor of any win32 methods. 我希望这些方法支持任何win32方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM