Ejemplo n.º 1
0
        protected override void ProcessRecord()
        {
            if (hWnd == IntPtr.Zero)
            {
                hWnd = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
            }


            if (x != int.MinValue || y != int.MinValue || width != int.MinValue || Height != int.MinValue)
            {
                Rectangle pos = GetWindowRectangle(hWnd);
                SetPosition(hWnd, x != int.MinValue ? x : pos.X, y != int.MinValue ? y : pos.Y, width != int.MinValue ? width : pos.Width, height != int.MinValue ? height : pos.Height);
            }

            if (state != -1)
            {
                switch (state)
                {
                case (int)WindowState.Maximized:
                    USER32.PostMessage(hWnd, USER32.WM.SysCommand, USER32.SC.Maximize, IntPtr.Zero);
                    break;

                case (int)WindowState.Minimized:
                    USER32.PostMessage(hWnd, USER32.WM.SysCommand, USER32.SC.Minimize, IntPtr.Zero);
                    break;

                case (int)WindowState.Normal:
                    USER32.PostMessage(hWnd, USER32.WM.SysCommand, USER32.SC.Restore, IntPtr.Zero);
                    break;
                }
            }

            if (flash != -1)
            {
                USER32.FLASHWINFO fInfo = new USER32.FLASHWINFO();
                switch (flash)
                {
                case (int)WindowFlash.Stop:
                    fInfo.cbSize    = Convert.ToUInt32(Marshal.SizeOf(fInfo));
                    fInfo.hwnd      = hWnd;
                    fInfo.dwFlags   = USER32.FLASHW_STOP;
                    fInfo.uCount    = UInt32.MaxValue;
                    fInfo.dwTimeout = 0;
                    USER32.FlashWindowEx(ref fInfo);
                    break;

                case (int)WindowFlash.Infinite:
                    fInfo.cbSize    = Convert.ToUInt32(Marshal.SizeOf(fInfo));
                    fInfo.hwnd      = hWnd;
                    fInfo.dwFlags   = USER32.FLASHW_ALL;
                    fInfo.uCount    = UInt32.MaxValue;
                    fInfo.dwTimeout = 0;
                    USER32.FlashWindowEx(ref fInfo);
                    break;

                case (int)WindowFlash.Quick:
                    fInfo.cbSize    = Convert.ToUInt32(Marshal.SizeOf(fInfo));
                    fInfo.hwnd      = hWnd;
                    fInfo.dwFlags   = USER32.FLASHW_ALL;
                    fInfo.uCount    = 5;
                    fInfo.dwTimeout = 0;
                    USER32.FlashWindowEx(ref fInfo);
                    break;

                case (int)WindowFlash.Long:
                    fInfo.cbSize    = Convert.ToUInt32(Marshal.SizeOf(fInfo));
                    fInfo.hwnd      = hWnd;
                    fInfo.dwFlags   = USER32.FLASHW_ALL;
                    fInfo.uCount    = 15;
                    fInfo.dwTimeout = 0;
                    USER32.FlashWindowEx(ref fInfo);
                    break;
                }
            }
        }