开发者

How Can I Check if a Window is an MDI Window?

I imagine there's some user32.dll call that I can use to verify if a window is an MDI window, like using DefMDIChildProc and seeing if it fails, but I wonder if there's any limitations to this, or if there's a better way to do this? Is checking for a Parent sufficient?

For simplicity's sake, what I'm ulti开发者_运维知识库mately hoping for is an IsMDI(IntPtr ptr) kind of call...

Thoughts? Suggestions?


I've figured it out (with the help of pinvoke.net) - you can find out based on the Extended Windows Styles:

        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);


If the controls are in your own .NET application, the Form class has properties for working with MDI windows:

Form.IsMdiChild

Form.IsMdiContainer

Form.MdiParent

Form.MdiChildren

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜