Search code examples
c#docksetparent

How to undock Game Window for SetParent


Hello everyone.

    [DllImport("user32.dll")]
    public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
    
    public void DockAllNote(System.Windows.Forms.Panel panel)
    {
        Process[] MultiClients = Process.GetProcessesByName("notepad");
        foreach (Process Client in MultiClients)
        {
            hWndOriginalParent = Client.MainWindowHandle;
            SetParent(Client.MainWindowHandle, panel.Handle);
            panel.Refresh();
        }
    }`enter code here`

worked above code. i want to undock notepad windows.

    public void UndockNoteAll(System.Windows.Forms.Panel panel)
    {
        Process[] MultiClients = Process.GetProcessesByName("notepad");
        foreach (Process Client in MultiClients)
        {
            SetParent(Client.MainWindowHandle, IntPtr.Zero);
            panel.Refresh();
        }
    }

I tried this undock code but Undock did not work. Notepad remained on the panel. How to undock window? tried undock a year ago using IntPtr.Zero. I don't remember what the code is.

Sorry for Bad English Thanks


Solution

  • Solved.

    IntPtr DockedHandle = IntPtr.Zero;
    IntPtr OrjinalHandle = IntPtr.Zero;
    //Dock
    OrjinalHandle = process.MainWindowHandle
    DockedHandle = SetParent(process.MainWindowHandle, panel.Handle);
    //Undock
    SetParent(OrjinalHandle, DockedHandle);