• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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
{
}
}
}


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
c#计算2个字符串的相似度发布时间:2022-07-13
下一篇:
养成良好的代码风格---c#变量命名规则发布时间:2022-07-13
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap