Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 了解外部流程何时启动';橱窗展示_C#_.net_Process_Window - Fatal编程技术网

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);
也许不是最好的解决方案,但这是一个很好的起点