1

我正在用 C# 编写一个应用程序,它需要将自己的一个窗口附加到另一个进程拥有的窗口。我尝试使用 Windows api 中的 SetParent 函数,但它似乎不起作用。有没有办法做到这一点?

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

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

1 回答 1

2

首先,您的 P/Invoke 声明是错误的。句柄由 表示IntPtr,而不是Int32

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

现在也许您应该避免将窗口“附加”到另一个进程。请参阅此 SO 线程

于 2012-02-05T13:05:35.067 回答