How to embed third party exe file in windows application?

emded third party exeThis example dock third party exe in your windows application form panel and match its size, it can be any .exe file , autocad exe , notepad. Minimize or hide third party exe until load in this way way user might not notice the difference 'startInfo.WindowStyle = ProcessWindowStyle.Minimized'

Download

Example Source Snippets - Embed_DockExeFile.zip

Download

Example Source Snippets - Embed_DockExeFile.zip

Dock Exe file


using System;
using System.Collections.Generic;vvv
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace DockExeFile
{
    public partial class Form1 : Form
    {
        [DllImport("user32.dll")]
        public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

        [DllImport("user32.dll", SetLastError = true)]
        public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);

        private Process dockProcess;
        private IntPtr hWndOriginalParent;
        private IntPtr hWndDocked;
        private IntPtr hWndParent;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            dockInPanel();
        }
        private void dockInPanel()
        {
            if (hWndDocked != IntPtr.Zero) 
                return;
            hWndParent = IntPtr.Zero;

            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
            startInfo.UseShellExecute = true;
            startInfo.FileName = "NOTEPAD";
            startInfo.Arguments = @"D:\dock.txt";

            startInfo.WindowStyle = ProcessWindowStyle.Minimized;
            dockProcess = new Process();
            dockProcess = System.Diagnostics.Process.Start(startInfo);

            while (hWndDocked == IntPtr.Zero)
            {
                dockProcess.WaitForInputIdle(1000); //wait 

                dockProcess.Refresh();//update process info

                if (dockProcess.HasExited)
                {
                    return; //abort if the process finished before we got a handle.
                }
                hWndDocked = dockProcess.MainWindowHandle;  //cache the window handle
                hWndOriginalParent = SetParent(hWndDocked, panel1.Handle);
             
                panel1.SizeChanged += new EventHandler(panel1_Resize);
              
                panel1_Resize(new Object(), new EventArgs());
            }
        }

        private void panel1_Resize(object sender, EventArgs e)
        {
            //Change the docked windows size to match its parent's size. 
            MoveWindow(hWndDocked, 0, 0, panel1.Width, panel1.Height, true);            
        }
    }
}
       

smartsnipps.ecomparefiles.com © 2019, All Rights Reserved | Disclaimer: smartsnipps.eCompareFiles.com is free to use any code snippets without guarantee