如何显示与外部流程主窗口何时显示相关的事件?
我使用
开始这个过程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);
答案 0 :(得分:1)
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);
可能不是最好的解决方案,但却是一个很好的起点