I'm trying to embed a external application in a form of winform with c#.It worked well with "nodepad.exe" but my target application using following code.
Process.Start(@"C:\Program Files\SIMPACK-9.8\run\bin\win64\simpack-viewer.exe");
int timeToWait = 5000;
while(AppHandle == IntPtr.Zero && timeToWait > 0)
{
Thread.Sleep(100);
timeToWait -= 100;
foreach (Process pList in Process.GetProcesses())
{
if (pList.MainWindowTitle.Contains(@"SIMPACK Viewer"))
{
AppProc = pList;
AppHandle = pList.MainWindowHandle;
break;
}
}
}
if (AppHandle != IntPtr.Zero)
{
//AppProc.WaitForInputIdle();
//AppHandle = foreignApp.MainWindowHandle;
SetParent(AppHandle, this.Handle);
SetWindowLong(AppHandle, GWL_STYLE, WS_VISIBLE + WS_MAXIMIZE);
MoveWindow(AppHandle, 0, 0, this.Width, this.Height, true);
}
My problem is the menu items can't respond to my click but "nodepad" works. Possibly it's because my target application launches through command shell. And I can't apply WaitForInputIdle() function with my target application but notepad can(nodepad need to apply this function actually).
Is anyone can help me, thanks!