0

我想知道 WPF 窗口/控件是否对用户可见(如果它被其他窗口隐藏),我发现了这个函数 GetUpdateRect() 但它只适用于 Windows 窗体。

有什么方法可以在 WPF 控件/Windows 中使用函数 GetUpdateRect() 吗?我尝试了一切,我发现的只是:

[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
internal struct RECT
{
    public int Left;
    public int Top;
    public int Right;
    public int Bottom;
    public int Width { get { return this.Right - this.Left; } }
    public int Height { get { return this.Bottom - this.Top; } }
}

[System.Runtime.InteropServices.DllImport("user32.dll")]
internal static extern bool GetUpdateRect(IntPtr hWnd, ref RECT rect, bool bErase);

public static bool IsControlVisibleToUser(System.Windows.Forms.Control control)
{
    control.Invalidate();
    Rectangle bounds = control.Bounds;
    RECT rect = new RECT { Left = bounds.Left, Right = bounds.Right, Top = bounds.Top, Bottom = bounds.Bottom };
    return GetUpdateRect(control.Handle, ref rect, false);
}
4

0 回答 0