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
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