在C#中将外部应用程序嵌入winform时出现的一些问题

时间:2016-01-11 12:14:12

标签: c# winforms external-application

我正在尝试使用c#以winform的形式嵌入外部应用程序。它与“nodepad.exe”配合使用,但我的目标应用程序使用以下代码。

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

        }

我的问题是菜单项无法响应我的点击,但“nodepad”有效。可能是因为我的目标应用程序通过命令shell启动。 我不能将WaitForInputIdle()函数应用于我的目标应用程序,但记事本可以(nodepad实际上需要应用此函数)。

有人可以帮助我,谢谢!

0 个答案:

没有答案