问题描述
我试图在 C# 程序中触发和应用程序(在本例中为 SAP2000),以便应用程序显示在面板中。我在不同的帖子中搜索过,似乎“SetParent()”策略最适合此目的。然而,也确实有一些用户报告说它有一些问题,并且已经定义了“SetParent()”策略的不同方法。你可以在下面找到我的:
尽管在“proc.WaitForInputIdle(1000)”和“Thread.Sleep(10000)”中定义了很高的“延迟”值,但应用程序 (SAP2000) 并不总是显示在面板中 和 当它按下时,应用程序按钮可以被按下,但它们没有反应(见图)。
我的问题是:“SetParent()”是在 C# 程序面板中运行这种“重”应用程序的合适方法吗?或者对于这种情况是否需要另一种策略?如果是这样,我真的很感激任何处理这个问题的建议。
提前致谢。问候
using System;
using System.Linq;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;
namespace Prueba_OAPI_CSi_SAP
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender,EventArgs e)
{
Process proc = Process.Start("C:\\Program Files\\Computers and Structures\\SAP2000 22\\SAP2000.exe");
if (proc != null)
{
proc.WaitForInputIdle(1000);
while (proc.MainWindowHandle == IntPtr.Zero)
{
Thread.Sleep(10000);
proc.Refresh();
}
OpcionesTeclado.SetParent(proc.MainWindowHandle,panel2.Handle);
OpcionesTeclado.MessageBeep(1);
this.BringToFront();
}
}
public class OpcionesTeclado
{
[DllImport("user32.dll",SetLastError = true)]
public static extern IntPtr SetParent(IntPtr hWndChild,IntPtr hWndNewParent);
[DllImport("user32.dll")]
public static extern bool MessageBeep(int uType);
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)