Calling an . exe application in a C#Panel

Asked

Viewed 168 times

0

To open an application know you use the following code

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

Now I need to know how to open the application in a Panel in my Form, so that it is not possible to drag it out of the Panel or my application.

1 answer

0

Natively it is not possible, but you can call internal methods from user32.dll to make this possible. Call the method SetPointerParent 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;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.