Call an .exe application in a C # Panel

0

To open an application I know that it uses the following code

System.Diagnostics.Process.Start("calc");

Now I need to know how to open the application in Panel in my Form , so that it can not be dragged out of Panel or my application.

    
asked by anonymous 01.05.2018 / 03:14

1 answer

0

Natively is not possible, but you can call internal methods of user32.dll to make this possible. Call the SetPointerParent method with the target executable and the control that will be displayed.

using System.Runtime.InteropServices;

[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hwc, IntPtr hwp);

protected internal IntPtr SetPointerParent(string exename, Control parent)
{
    Process p = Process.Start(exename);
    System.Threading.Thread.Sleep(500);
    p.WaitForInputIdle();

    IntPtr hw = p.MainWindowHandle;
    IntPtr hc = parent.Handle;
    SetParent(hw, hc);
    return hw;
}
    
01.05.2018 / 04:01