0

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.

rickhik
  • 1
  • 2
  • Why don't you just make a c++ ActiveX control that uses OpenGL that you can then embed into your c# app window? ActiveX/COM is faster than creating a named pipe or network-layer TCP socket. –  Jul 16 '16 at 15:37
  • Micky D, you mean something like this: http://stackoverflow.com/questions/5747723/opengl-view-on-c-sharp-form or http://www.codeproject.com/Articles/127141/Unmanaged-C-OpenGL-Drawing-and-C-WinForms-WPF-inte ? Just to point me in the right direction. – rickhik Jul 16 '16 at 17:19

0 Answers0