NoCode
NoCode

Reputation: 471

Attach window to external process

I'm writing an application in C# which needs to attach one of its own windows to a window owned by another process. I tried using the SetParent function from the windows api, but it doesn't seem to work. Is there any way to do this?

    [DllImport("user32.dll", SetLastError = true)]
    private static extern int SetParent(int hWndChild, int hWndNewParent);

    private void AttachWindow(int newParent) {
    SetParent(this.Handle, newParent);
     }

Upvotes: 1

Views: 1959

Answers (1)

ken2k
ken2k

Reputation: 48985

Firstly, your P/Invoke declaration is wrong. Handles are represented by IntPtr, not Int32:

[DllImport("user32.dll", SetLastError = true)]
private static extern int SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

Now maybe you should avoid "attaching" a window to another process. See this SO thread.

Upvotes: 2

Related Questions