C# 了解外部流程何时启动';橱窗展示
如何获取与显示外部进程主窗口相关的事件 我使用C# 了解外部流程何时启动';橱窗展示,c#,.net,process,window,C#,.net,Process,Window,如何获取与显示外部进程主窗口相关的事件 我使用 pi = new ProcessStartInfo(); [...] Process.Start(pi) 然后,我希望获得主窗口出现的时刻,并使用以下命令调整其大小和移动: [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)] internal static extern bool MoveWindow(IntPtr hWnd,
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);
也许不是最好的解决方案,但这是一个很好的起点