0

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.

GSerg
  • 76,472
  • 17
  • 159
  • 346
EmrecanK.
  • 11
  • 1
  • 1
    Did you also [set `WS_POPUP`](https://stackoverflow.com/a/21636744/11683)? Are you sure your target window is [prepared](https://devblogs.microsoft.com/oldnewthing/20130412-00/?p=4683) for this kind of experience? – GSerg Jan 08 '22 at 21:20
  • 1# No I didn't add WS_POPUP. 2# The application didn't designed to support it. So, no. The thing I want to learn is, unlocking resizing restrictions. – EmrecanK. Jan 09 '22 at 00:32
  • 1
    Resizing restrictions are implemented by the window's window procedure (e.g. by handling the [`WM_GETMINMAXINFO`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-getminmaxinfo) message). You cannot *"unlock"* that behavior, unless you are prepared to replace the target window's window procedure. – IInspectable Jan 09 '22 at 10:45
  • Perhaps WinUI3 which can [Show multiple views for an app](https://learn.microsoft.com/en-us/windows/apps/design/layout/show-multiple-views) can work for you. – YangXiaoPo-MSFT Jan 10 '22 at 10:01

0 Answers0