1

I am trying to add a camera gui which is a .exe file in a panel in my windows application. the following shows what the gui looks like. its a Caltex Scientific application

enter image description here

this is my code:

[DllImport("user32.dll", SetLastError = true)]
        private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);


        private void setCamera()
        {
            //string camProgram = "C:\\Windows\\notepad.exe";
            //string progName = "notepad";
            string progName = "Capture2.1";
            string camProgram = "C:\\Program Files\\Capture2.0\\Capture2.1.exe";
            ProcessStartInfo psi = new ProcessStartInfo(camProgram);
            psi.WindowStyle = ProcessWindowStyle.Minimized;
            Process p = Process.Start(psi);
            Thread.Sleep(5000);

            foreach (Process p1 in Process.GetProcesses())
            {
                // Console.WriteLine(p1.MainWindowHandle);

                if (p1.ProcessName == progName)
                {
                    p1.StartInfo.CreateNoWindow = true;    // new
                    p1.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
                    p1.Refresh();
                    SetParent(p1.MainWindowHandle, this.camPanel.Handle);
                    MoveWindow(p1.MainWindowHandle, 0, 0, camPanel.Width / 2, camPanel.Height, true);
                    break;
                }
            }
            //SetParent(p.MainWindowHandle, camPanel.Handle);
            //CenterToScreen();
            //psi.WindowStyle = ProcessWindowStyle.Normal;

        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            setCamera();
        }

However, I am unable to add the application into the panel in my form. I tried to launch a notepad.exe, the notpad successfully appears in my panel. the windowhandle of the Capture2.1.exe is a non zero value.

please advise

sticky bit
  • 36,626
  • 12
  • 31
  • 42
Adhil
  • 1,678
  • 3
  • 20
  • 31
  • 1
    This usage of SetParent() is appcompat for Win3 programs, harking back from the days that the notions of a process and memory isolation did not yet exists. The custom frame of this app is a dead-giveaway that this app is not anything like a Win3 app. Talk to the owner, they surely can provide you with an api. – Hans Passant Nov 15 '19 at 13:47
  • Like what @HansPassant said. Does the Capture2.1.exe load any DLL when it's executed? You can [Process Explorer v16.30](https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer) will show you information about which handles and DLLs processes have opened or loaded. – Black Frog Nov 15 '19 at 16:11
  • @Black Frog The .exe comes with a lot of dlls, however, the capture tools comes with some features i need like area focus, thats why i want to add the gui in the window, any suggestions – Adhil Nov 16 '19 at 05:24
  • So what do i do with the handles and dlls opened? – Adhil Nov 16 '19 at 05:28
  • You have to look at each DLL and check out what API they expose. Take a look at the following answer on SO to provide a little guidance https://stackoverflow.com/a/42074044/256728 – Black Frog Nov 16 '19 at 14:38

0 Answers0