I am trying to detach another program's child window using SetParent(hWnd, IntPtr.Zero)
. After setting parent as null I remove WS_CHILD
style. It is OK until I want to change its size, it seems it is acting like a child window still. Only can take up its old container (parent window's client area). Is there a way to change this behaviour in the Windows API?
Here is the code
using System.Runtime.InteropServices;
class Program
{
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr hWndChildAfter, string className, string windowTitle);
static void Main(string[] args)
{
IntPtr hWnd = FindWindow("DigiAppWndClass", null);
if (hWnd != IntPtr.Zero)
{
hWnd = FindWindowEx(hWnd, IntPtr.Zero, null, "Edit: test");
if (hWnd != IntPtr.Zero)
{
SetParent(hWnd, IntPtr.Zero);
}
}
}
}
Any help would be great, thanks.