从桌面恢复父级 window

Restoring parent from the desktop window

我导入了:

public static extern IntPtr SetParent(
        IntPtr hWndChild,      // handle to window
        IntPtr hWndNewParent   // new parent window
    );

来自 user32.dll 我的 windows 表单应用程序并在后台线程中连续设置 SetParent(hwndf,hwndParent);(如果变量为真)。

在哪里

IntPtr hwndf = Control.Handle;
IntPtr hwndParent = FindWindow("ProgMan", null);

我的问题 如何将父句柄重置为默认 windows 表单句柄,也就是如何不在桌面顶部显示 window window 了吗? 并且正在关注,这是执行此操作的有效方法吗(重复?)。

没关系。我可以使用

SetParent(hwndf, new IntPtr(0));

当我想 "reset" 表单 window 父级时。唯一的问题是 window 被最小化了,所以我的解决方案是 运行 ShowWindow(hwndf, SW_RESTORE); 在从 user32.dll!

导入这些方法之后
    [DllImport("user32.dll")]
    public static extern IntPtr ShowWindow(
        IntPtr hWnd,      // handle to window
        uint nCmdShow
    );
    private const uint SW_RESTORE = 0x09;