在窗体中嵌入 应用程序
//在窗体中嵌入应用程序
//show
Process process = null; IntPtr appWin; private string exeName = ""; [DllImport("user32.dll", SetLastError = true)] private static extern long SetParent(IntPtr hWndChild, IntPtr hWndNewParent); [DllImport("user32.dll", SetLastError = true)] private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);
private void button1_Click(object sender, EventArgs e) { this.exeName = IniHelper.IniData.VideoUrl.pathvalue; try { // Start the process process = System.Diagnostics.Process.Start(this.exeName); // Wait for process to be created and enter idle condition process.WaitForInputIdle(); // Get the main handle appWin = process.MainWindowHandle; } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error"); } // Put it into this form SetParent(appWin, this.Handle); // Remove border and whatnot // SetWindowLong(appWin, GWL_STYLE, WS_VISIBLE); // Move the window to overlay it on this window MoveWindow(appWin, 0, 0, this.Width, this.Height, true); } private void Form2_FormClosed(object sender, FormClosedEventArgs e) { try { process.Kill(); } catch { } } private void Form2_Resize(object sender, EventArgs e) { if (this.appWin != IntPtr.Zero) { MoveWindow(appWin, 0, 0, this.Width, this.Height, true); } //base.OnResize(e); }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步