首页 > Windows开发 > 详细

把第三方的exe程序嵌入C#界面上

时间:2015-01-11 12:14:29      阅读:454      评论:0      收藏:0      [点我收藏+]

public partial class eTerm_Form : WinFormsUI.Docking.DockContent
{
public eTerm_Form()
{
InitializeComponent();
}

Process process = null;
IntPtr appWin;

[DllImport("user32.dll", SetLastError = true)]
private static extern long SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
private static extern long SetWindowPos(IntPtr hwnd, long hWndInsertAfter, long x, long y, long cx, long cy, long wFlags);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);

private void eTerm_Form_Resize(object sender, EventArgs e)
{
if (this.appWin != IntPtr.Zero)
MoveWindow(appWin, 0, 0, this.Width, this.Height, true);
}

private void eTerm_Form_Load(object sender, EventArgs e)
{
try
{
process = System.Diagnostics.Process.Start(@”E:MyProjectNewSkyrickieManageSkyrickieManageShenZhen.skyrickie.SkyrickieManagebinDebugSkyrickieManage.exe”);
process.WaitForInputIdle();
appWin = FindWindow(null, “skyrickie个人管理系统登录”);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, “Error”,MessageBoxButtons.OK, MessageBoxIcon.Error);
}

SetParent(appWin, this.Handle);
MoveWindow(appWin, 0, 0, this.Width, this.Height, true);
}

private void eTerm_Form_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
if (!process.HasExited)
process.Kill();
}
catch
{
}
}
}

把第三方的exe程序嵌入C#界面上

原文:http://www.cnblogs.com/skyay/p/4216201.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!