C# 将父对象设置为挂钩,如何解除挂钩?

C# 将父对象设置为挂钩,如何解除挂钩?,c#,winforms,winapi,release,C#,Winforms,Winapi,Release,当应用程序现在用作父应用程序时,您将如何从窗体中取消挂钩 [DllImport("user32.dll")] public static extern int SetParent(IntPtr hWndChild, IntPtr hWndNewParent); [DllImport("coredll.dll", SetLastError = true)] private static extern int GetWindowLong(IntPtr hWnd, int nIndex); [Dl

当应用程序现在用作父应用程序时,您将如何从窗体中取消挂钩

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

[DllImport("coredll.dll", SetLastError = true)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);

[DllImport("coredll.dll", SetLastError = true)]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

SetParent(setter, this.panel1.Handle);

要解开挂钩,我尝试了SetParent(setter,setter);运气不佳。

SetParent返回上一个父窗口句柄。要“取消挂钩”窗口,您应该能够使用最初返回的句柄调用SetParent。

我知道这已经晚了,但我能够通过0从父窗口取消挂钩:

SetParent(process.MainWindowHandle, IntPtr.Zero);

这会将桌面窗口设置为新的父窗口。

我不熟悉这一点,但我会尝试在设置新的父窗口之前存储旧的父窗口(无论是什么)。嗯,很抱歉,我无法理解
将应用程序从您的表单中解钩
-这是什么意思?比如当你把Chrome标签拖到自己的应用中?请详细说明:)假设将parent设置为NULL会将其挂接到桌面。没有这方面的经验,thoughexception,intptr到null不可能,没有来自(intptr)的结果null@ploxtic尝试使用
IntPtr.Zero
而不是.Net
null
.nope。除非您也必须通过程序移动窗口,否则此操作不起作用。。卡在窗体/面板内如果以前的所有者是桌面,我不确定还原父级是否会有任何明显的视觉效果,除非您移动其中一个参与的窗口或其他什么。Chrome、记事本:两者都不会使用IntPtr.Zero或-1、null或其自己的句柄从窗体/面板外反弹回来。对你有用吗?或者你考虑的是哪一个手柄“最初回来了”