繁体   English   中英

如何检查窗口是否为MDI窗口?

[英]How Can I Check if a Window is an MDI Window?

我想象有一个user32.dll调用可以用来验证窗口是否为MDI窗口,例如使用DefMDIChildProc并查看它是否失败,但是我想知道对此是否有任何限制,或者是否有更好的方法来执行此操作? 检查父母是否足够?

为了简单起见,我最终希望的是一种IsMDI(IntPtr ptr)的呼叫...

思考? 建议?

我已经弄清楚了(在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);

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

Form.IsMdiChild

Form.IsMdiContainer

Form.MdiParent

Form.MdiChildren

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM