本文介绍了知道什么时候一个外部进程“窗口显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能得到事件相当外部程序的主窗口显示的?

我用启动过程

  PI =新的ProcessStartInfo();
[...]
的Process.Start(PI)的
 

比我想获得主窗口出现的那一刻,并调整其大小,并使用移动:

  [System.Runtime.InteropServices.DllImport(user32.dll中,SetLastError =真)
        内部静态外部布尔的MoveWindow(IntPtr的的HWND,INT X,诠释Y,INT nWidth,nHeight参数INT,BOOL bRepaint);
 

解决方案

我解决了它是这样的:

 异步无效RepositionWindow(工艺过程)
        {
            而((INT)process.MainWindowHandle == 0)
            {
                等待Task.Delay(100);
            }
            的IntPtr的HWND = process.MainWindowHandle;
            而(!IsWindowVisible(HWND))
            {
                等待Task.Delay(100);
            }
            的MoveWindow(HWND,0,0,500,800,真);
        }

        [System.Runtime.InteropServices.DllImport(user32.dll中,SetLastError =真)
        内部静态外部布尔的MoveWindow(IntPtr的的HWND,INT X,诠释Y,INT nWidth,nHeight参数INT,BOOL bRepaint);

        [System.Runtime.InteropServices.DllImport(user32.dll中)
        [返回:System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)
        静态外部布尔IsWindowVisible(IntPtr的的HWND);
 

可能不是最好的解决办法,但一个很好的起点

How can I get an event relative to when the main window of an external process is showed?

I start the process using

pi = new ProcessStartInfo();
[...]
Process.Start(pi)

Than I want to get the moment the main window appears and resize and move it using:

[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);
解决方案

I solved it like this:

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);

Probably not the best solution, but a good starting point

这篇关于知道什么时候一个外部进程“窗口显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 15:54
查看更多