代码之家  ›  专栏  ›  技术社区  ›  Nathan W

在第三方应用程序中将窗口创建为子窗口

  •  2
  • Nathan W  · 技术社区  · 16 年前

    alt text http://img693.imageshack.us/img693/8871/examplec.jpg

    我想创建我的窗体,使它成为MDIClient句柄005E0ED6的一部分。就像01D7157D窗口一样。

    这可能吗?如果是这样的话,可以用C#完成吗?

    3 回复  |  直到 16 年前
        1
  •  2
  •   Community Mohan Dere    9 年前

    SetParent ? 请参阅下面的StackOverflow问题,看看是否有帮助。 Embedding HWND into external process using SetParent

        2
  •  1
  •   Nathan W    16 年前

    此代码似乎有效:

        [DllImport("user32.dll")]
        private static extern
            IntPtr GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId);
    
        [DllImport("user32.dll")]
        private static extern
            IntPtr AttachThreadInput(IntPtr idAttach, IntPtr idAttachTo, int fAttach);
    
            WinAPI.SetParent(this.Handle, otherappshandle);
    
            IntPtr otherprocessID = GetWindowThreadProcessId(otherappshandle, new IntPtr(0));
            IntPtr threadID = new IntPtr(AppDomain.GetCurrentThreadId());
    
            AttachThreadInput(threadID , otherprocessID , 1);
    
        3
  •  0
  •   kyoryu    16 年前

    祝你好运。我走了这条路,发现有足够的小恼人的陷阱,我最终放弃了它。

    零件

    特别是在WinForms中,我强烈建议您只在主进程中运行UI(如果可以的话),如果您想在另一个进程中隔离您的处理,请改为这样做。