Currently I have build a application in C++ that renders OpenGL objects. This all works fine but I want to create a control interface (C#) to control what to draw (use of pipe or socket).
In my C# application I have a Panel tool named "canvas". In the canvas I want to open the C++ application (the C++ app is just a window without borders). Basically I want to show the C++ context in my C# app. I tried to use the following code (open the app and show it inside the "canvas"), but it always opens the exe outside the canvas (panel). For the example I use notepad.exe instead of the real app. I use Visual Studio 2015.
I borrowed the code from another Stackoverflow topic.
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = file;
info.Arguments = "";
info.UseShellExecute = true;
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Normal;
info.RedirectStandardInput = false;
info.RedirectStandardOutput = false;
info.RedirectStandardError = false;
Process p = Process.Start(info);
p.WaitForInputIdle();
Thread.Sleep(3000);
Process[] p1;
if(p.MainWindowHandle == null)
{
List<String> arrString = new List<String>();
foreach (Process proc in Process.GetProcesses())
{
arrString.Add(Convert.ToString(proc.ProcessName));
}
p1 = Process.GetProcessesByName(file);
Thread.Sleep(5000);
SetParent(p1[0].MainWindowHandle, this.canvas.Handle);
}
else
{
SetParent(p.MainWindowHandle, this.canvas.Handle);
}
Probably there is a better way to achieve what I want but thats not at my knowledge at this moment.