确定窗口是否有关闭按钮(或者,为什么GetTitleBarInfo不起作用?)

时间:2012-06-26 19:14:20

标签: c# winapi pinvoke

我正在尝试根据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,返回值应该是the values listed here中的一个或多个的组合。

0 个答案:

没有答案