【问题标题】:Attach window to external process将窗口附加到外部进程
【发布时间】:2012-02-05 12:49:15
【问题描述】:

我正在用 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);
     }

【问题讨论】:

    标签: c# windows winapi user32


    【解决方案1】:

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

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

    现在也许您应该避免将窗口“附加”到另一个进程。见this SO thread

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多