/// <summary> /// 将外进程嵌入到当前程序 /// </summary> /// <param name="process"></param> private bool EmbeddedProcess(Process process) { //---是否嵌入成功标志,用作返回值 bool isEmbedSuccess = false; //---外进程句柄 IntPtr processHwnd = process.MainWindowHandle; //---容器句柄 IntPtr panelHwnd = this.Handle; if (processHwnd != (IntPtr)0 && panelHwnd != (IntPtr)0) { //---把本窗口句柄与目标窗口句柄关联起来 int setTime = 0; while (!isEmbedSuccess && setTime < 10) { isEmbedSuccess = (CWin32API.SetParent(processHwnd, panelHwnd) != 0); CGenFuncDelay.GenFuncDelayms(150); //Thread.Sleep(100); setTime++; } //---设置初始尺寸和位置 CWin32API.MoveWindow(this.defaulProcess.MainWindowHandle, 0, 0, this.Width, this.Height, true); // Remove border and whatnot //---移除边框和右上角的最大,最小和关闭功能 CWin32API.SetWindowLong(new HandleRef(this, this.defaulProcess.MainWindowHandle), CWin32API.GWL_STYLE, CWin32API.WS_VISIBLE); } if (isEmbedSuccess) { this.defaultEmbededWindowHandle = this.defaulProcess.MainWindowHandle; } return(isEmbedSuccess); }
/// <summary> /// /// </summary> /// <param name="e"></param> protected override void OnResize(EventArgs e) { if (defaulProcess != null) { CWin32API.MoveWindow(this.defaulProcess.MainWindowHandle, 0, 0, this.Width, this.Height, true); } base.OnResize(e); }