我可以使用SetWindowPos
函数将窗口置于最顶层或取消其置于最顶层。但是,我无法找到检查窗口是否置于最顶层的方法。是否有通过来检查窗口是否置于最顶层的方法?
GetWindowLong()
函数来检查扩展窗口样式。以下为可能可行的代码示例:[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;
}
根据您使用的UI技术,您可以选择以下两种:
Form.TopMost
}}Window.TopMost
}}您可以使用这些属性来检查某个窗口是否置顶,并且您还可以使用这些属性将窗口设置为置顶。我更喜欢这些方法而不是任何win32方法。
GetWindowLong()
声明。好吧,我不确定该使用哪个了。 - Visual Vincent