3

我正在尝试使用GetTitleBarInfo函数来确定给定窗口是否有关闭按钮,如this SO answer中所建议的那样。但是当我调用该函数时,它的返回值rgstate[5]- 应该指示关闭按钮状态 - 始终为 0,我不明白为什么。有人知道我在这里做错了什么吗?或者,如果有人可以建议另一种方法来获取此信息,那也会有所帮助。谢谢!

[DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
internal static extern IntPtr GetForegroundWindow();

[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool GetTitleBarInfo(IntPtr hwnd, ref TITLEBARINFO pti);

[StructLayout(LayoutKind.Sequential)]
internal struct TITLEBARINFO
{
    public int cbSize;
    public RECT rcTitleBar;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
    public int[] rgstate;
}

IntPtr handle = GetForegroundWindow();
TITLEBARINFO titleBarInfo = new TITLEBARINFO();
titleBarInfo.cbSize = Marshal.SizeOf(titleBarInfo);

if (!GetTitleBarInfo(handle, ref titleBarInfo))
    throw new Win32Exception(Marshal.GetLastWin32Error());

// titleBarInfo.rgstate[5] is always 0 here. Why?

编辑:为了清楚起见,根据 MSDN,返回值应该是此处列出的一个或多个值的组合。

4

0 回答 0