0
    [DllImport("user32.dll", SetLastError = true)]
    public static extern IntPtr SetParent(IntPtr MainWindowHandle, IntPtr Panel);
    public static void Dock(IntPtr OrjinalHandle, Panel panel)
    {
        IntPtr DockedHandle = Native.SetParent(OrjinalHandle, panel.Handle);
    }
    private void button1_Click(object sender, EventArgs e)
    {
        IntPtr handle = Process.GetProcessesByName("notepad")[0].MainWindowHandle;
        Dock(handle, panel1);
        IntPtr newhandle = Process.GetProcessesByName("notepad")[0].MainWindowHandle;
        MessageBox.Show("Handle value: " + newhandle.ToString("X"));
    }

show 0 value in messagebox. Worked without SetParent. Why return 0? How to solve this problem? Thanks

ÖMER
  • 15
  • 6
  • 1
    Your SetParent call made the window no longer top-level so it no longer qualifies as a main window. – Raymond Chen Apr 12 '22 at 14:04
  • Well, notepad is running in the background when accidentally close it. does not work the undock function with mainwindowhandle 0. there an undock function way?? – ÖMER Apr 12 '22 at 14:08
  • [Unhook Window into its original state](https://stackoverflow.com/a/65847818/7444103) – Jimi Apr 12 '22 at 14:20
  • What you're trying to do is inherently unsupported. There are various things you can try, but none are guaranteed to work. If you want to show text in an edit box, you can just put an edit box in your app. – Raymond Chen Apr 12 '22 at 15:59

0 Answers0