I need to launch some Windows apps to run inside a form. I'm developing a Windows desktop app on C# using VS-15 IDE.
This topic has been tackled in SO many years ago. This is the best answer I found:
How can I run another application within a panel of my C# program?
However all examples deal with launching Notepad, which works ok. I indeed can launch and run notepad inside a target panel in a target form, and works perfectly.
But I don't need to launch Notepad, I need to launch other installed apps, and have found the frustrating reality that's impossible to launch the desired app inside the target panel/form. It just opens outside the form.
Even found a post in which a OP needs to launch IE, but the same result, IE starts outside the form.
Reading and reading related topics, I've found that it could be a probability of being solved using something called EnumWindows. I'm really new to C#, I usually deal with Python. I'm not even native to windows, had to install it in a VM.
I'm using Visual Studio 2015. The expected output is a desktop app to Windows 7 and 8 machines, 64 bits.
The code:
using System;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
namespace < >
{
public partial class Form1:
{
private void btn_qui_Click(object sender, EventArgs e)
{
var postventa = new appUser("POSTVENTA", "",3);
try
{
frm_3.Show();
Process p = Process.Start("C://QuiterWeb/QuiterWeb.exe");
p.WaitForInputIdle();
SetParent(p.MainWindowHandle, frm_3.panel_3.Handle);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
When running the code, the .exe opens outside the form. But if instead I make it open notepad.exe, it opens inside the specific panel and form. Which indicates that the destination is well mapped to the method.
What is wrong here? How to make the .exe run inside the panel and form?