Process MainWindowHandle return 0 after used SetParent

205 views Asked by At
    [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

0

There are 0 answers