Exemplo n.º 1
0
        /// <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 = (CWinAPIWindows.SetParent(processHwnd, panelHwnd) != 0);
                    CGenFuncDelay.GenFuncDelayms(150);
                    //Thread.Sleep(100);
                    setTime++;
                }
                //---设置初始尺寸和位置
                CWinAPIWindows.MoveWindow(this.defaultProcess.MainWindowHandle, 0, 0, this.Width, this.Height, true);
                // Remove border and whatnot
                //---移除边框和右上角的最大,最小和关闭功能
                CWinAPIWindows.SetWindowLong(new HandleRef(this, this.defaultProcess.MainWindowHandle), CWinAPIWindows.GWL_STYLE, CWinAPIWindows.WS_VISIBLE);
            }

            if (isEmbedSuccess)
            {
                this.defaultEmbededWindowHandle = this.defaultProcess.MainWindowHandle;
            }

            return(isEmbedSuccess);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 大小重置
        /// </summary>
        /// <param name="e"></param>
        protected override void OnResize(EventArgs e)
        {
            if (defaultProcess != null)
            {
                CWinAPIWindows.MoveWindow(this.defaultProcess.MainWindowHandle, 0, 0, this.Width, this.Height, true);
            }

            base.OnResize(e);
        }