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


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

  • 相关阅读:
    php练习题之裁判打分
    OPENSUSE:安装方式
    openSUSE:下载帮助
    安装mysql时出现HTTP 500 内部服务…
    关于wamp启动是80端口被占用的问题…
    推荐15款好用的JS开发工具
    u盘美化
    wordpress怎么修改地址栏小图标
    显示桌面图标不见了
    站长必备的131个高权重外链库(转…
  • 原文地址:https://www.cnblogs.com/skyay/p/4216201.html
Copyright © 2020-2023  润新知