Take the 2-minute tour ×

How would you unhook an application from your form once it's now using it as the parent?

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

to unhook i tried SetParent(setter, setter); with no luck.

share|improve this question
I'm not familiar with that, but i'd try to set the old parent (whatever that was), by storing it before setting the new one. –  Grumbler85 Mar 4 '13 at 5:54
Umm sorry I cant understand unhook an application from your form - what does this mean? Like when you drag a Chrome tab into its own App? Please elaborate :) –  Jeremy Thompson Mar 4 '13 at 5:55
you gotta know. –  ploxtic Mar 4 '13 at 5:56
msdn docs on SetParent say that setting parent to NULL hooks it to desktop. Don't have any experience with that, though –  default locale Mar 4 '13 at 5:56
exception, intptr to null not possible, no result from (IntPtr)null –  ploxtic Mar 4 '13 at 5:59

1 Answer 1

SetParent returns the previous parent window handle. To "unhook" the window you should be able to call SetParent with the handle you originally got back.

share|improve this answer
nope. unless you have to move the window via your program also, this does not work.. stuck inside the form/panel –  ploxtic Mar 5 '13 at 2:33
If the previous owner was the desktop I'm not sure there would be any obvious visual effect from restoring the parent unless you move one of the participating windows, or something. –  500 - Internal Server Error Mar 5 '13 at 4:58
Chrome, Notepad: both don't bounce back outside of the form/panel with IntPtr.Zero or -1, null, or its own handle. Did it work for you? Or which handle are you considering "originally got back." –  ploxtic Mar 5 '13 at 5:36

Your Answer


