在窗体中嵌入 应用程序
//在窗体中嵌入应用程序
//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); }