2

我想有一些 user32.dll 调用可以用来验证窗口是否是 MDI 窗口,例如使用 DefMDIChildProc 并查看它是否失败,但我想知道这是否有任何限制,或者是否有更好的方法来做到这一点? 检查父母是否足够?

为简单起见,我最终希望的是一种 IsMDI(IntPtr ptr) 类型的调用......

想法?建议?

4

2 回答 2

4

我已经想通了(在 pinvoke.net 的帮助下)-您可以根据扩展的 Windows 样式找到:

        public static bool IsMDI(IntPtr hwnd)
        {
            WINDOWINFO info = new WINDOWINFO();
            info.cbSize = (uint)Marshal.SizeOf(info);
            GetWindowInfo(hwnd, ref info);
            //0x00000040L is the style for WS_EX_MDICHILD
            return (info.dwExStyle & 0x00000040L)==1;
        }

        [StructLayout(LayoutKind.Sequential)]
        private struct WINDOWINFO
        {
            public uint cbSize;
            public RECT rcWindow;
            public RECT rcClient;
            public uint dwStyle;
            public uint dwExStyle;
            public uint dwWindowStatus;
            public uint cxWindowBorders;
            public uint cyWindowBorders;
            public ushort atomWindowType;
            public ushort wCreatorVersion;

            public WINDOWINFO(Boolean? filler)
                : this()   // Allows automatic initialization of "cbSize" with "new WINDOWINFO(null/true/false)".
            {
                cbSize = (UInt32)(Marshal.SizeOf(typeof(WINDOWINFO)));
            }

        }

        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("user32.dll", SetLastError = true)]
        private static extern bool GetWindowInfo(IntPtr hwnd, ref WINDOWINFO pwi);
于 2011-08-19T15:30:17.063 回答
2

如果控件在您自己的 .NET 应用程序中,则Form 类具有使用 MDI 窗口的属性:

Form.IsMdiChild

Form.IsMdiContainer

Form.MdiParent

Form.MdiChildren

于 2011-08-19T15:13:42.847 回答