我怎样才能得到事件相关联,当外部进程的主窗口显示一个?
我开始使用的过程
pi = new ProcessStartInfo();
[...]
Process.Start(pi)
比我想出现主窗口的时刻,调整和使用移动它:
[System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
我解决了它是这样的:
async void RepositionWindow(Process process)
{
while ((int)process.MainWindowHandle == 0)
{
await Task.Delay(100);
}
IntPtr hWnd = process.MainWindowHandle;
while (!IsWindowVisible(hWnd))
{
await Task.Delay(100);
}
MoveWindow(hWnd, 0, 0, 500, 800, true);
}
[System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
[System.Runtime.InteropServices.DllImport("user32.dll")]
[return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)]
static extern bool IsWindowVisible(IntPtr hWnd);
可能不是最好的解决办法,但一个良好的起点