Winforms 将Windows窗体设置为win32窗口的弹出子窗口

Winforms 将Windows窗体设置为win32窗口的弹出子窗口,winforms,winapi,Winforms,Winapi,Windows屏幕保护程序API为我提供了/c:xxxx的命令行参数,其中xxxx是该窗口的句柄,该窗口应该是我为配置屏幕保护程序而创建的任何子窗口的父窗口 目前我有以下助手: [DllImport("user32.dll")] static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent); const int GWL_STYLE = -16; [Flags] public

Windows屏幕保护程序API为我提供了
/c:xxxx
的命令行参数,其中
xxxx
是该窗口的句柄,该窗口应该是我为配置屏幕保护程序而创建的任何子窗口的父窗口

目前我有以下助手:

    [DllImport("user32.dll")]
    static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

    const int GWL_STYLE = -16;

    [Flags]
    public enum WindowStyle : ulong
    {
        WS_OVERLAPPED = 0x00000000,
        WS_POPUP = 0x80000000,
        WS_CHILD = 0x40000000,
        WS_MINIMIZE = 0x20000000,
        WS_VISIBLE = 0x10000000,
        WS_DISABLED = 0x08000000,
        WS_CLIPSIBLINGS = 0x04000000,
        WS_CLIPCHILDREN = 0x02000000,
        WS_MAXIMIZE = 0x01000000,
        WS_CAPTION = 0x00C00000, // WS_BORDER | WS_DLGFRAME
        WS_BORDER = 0x00800000,
        WS_DLGFRAME = 0x00400000,
        WS_VSCROLL = 0x00200000,
        WS_HSCROLL = 0x00100000,
        WS_SYSMENU = 0x00080000,
        WS_THICKFRAME = 0x00040000,
        WS_GROUP = 0x00020000,
        WS_TABSTOP = 0x00010000,
        WS_MINIMIZEBOX = 0x00020000,
        WS_MAXIMIZEBOX = 0x00010000,
        WS_TILED = WS_OVERLAPPED,
        WS_ICONIC = WS_MINIMIZE,
        WS_SIZEBOX = WS_THICKFRAME
    };

    [DllImport("user32.dll")]
    static extern UIntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, UIntPtr dwNewLong);

    [DllImport("user32.dll", SetLastError = true)]
    static extern UIntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex);

    [DllImport("user32.dll")]
    static extern bool GetClientRect(IntPtr hWnd, out Rectangle lpRect);

    public static void SetParent(Control child, IntPtr parent)
    {
        SetParent(child.Handle, parent);
    }

    public static void AddStyle(Control child, WindowStyle addstyle)
    {
        UIntPtr style = GetWindowLongPtr(child.Handle, GWL_STYLE);
        style = new UIntPtr(style.ToUInt64() | (UInt64)addstyle);
        SetWindowLongPtr(child.Handle, GWL_STYLE, style);
    }

    public static Rectangle GetClientRect(IntPtr window)
    {
        Rectangle rect;
        GetClientRect(window, out rect);
        return rect;
    }

然后在Windows窗体对话框中:

    public ConfigForm(IntPtr parentHWnd)
    {
        InitializeComponent();

        User32.SetParent(this, parentHWnd);
        User32.AddStyle(this, User32.WindowStyle.WS_POPUP);
    }
弹出标志似乎被忽略,因为Windows窗体是作为子窗体(而不是弹出窗口)绘制的,在父窗体的边界内剪切,并且存在各种各样的绘图问题。检查后,我添加
WS_POPUP
之前表单的窗口样式为
0x06CF0000


如何使Windows窗体对话框成为一个实际的弹出窗口?也就是说,与提供的父句柄是模态的,但不剪切到父窗口的边界?

SetParent()
使其成为子窗口。子窗口不能是弹出窗口。
WS_子项
WS_弹出式
样式是互斥的,就像在MSDN上一样。那么如何将对话框与父项关联?