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

发布于 2024-11-30 20:02:51 字数 181 浏览 1 评论 0原文

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

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

想法?建议?

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 ultimately hoping for is an IsMDI(IntPtr ptr) kind of call...

Thoughts? Suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

み青杉依旧 2024-12-07 20:02:51

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

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);
笑咖 2024-12-07 20:02:51

如果控件位于您自己的 .NET 应用程序中,则 表单类具有用于MDI窗口的属性:

Form.IsMdiChild

Form.IsMdiContainer

Form.MdiParent

Form.MdiChildren

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文