アプリケーションがパネルに表示されるように、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);
}
}