1

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);
     }
Yahia
  • 69,653
  • 9
  • 115
  • 144
NoCode
  • 471
  • 3
  • 9

1 Answers1

2

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.

Community
  • 1
  • 1
ken2k
  • 48,145
  • 10
  • 116
  • 176