Пример #1
0
        public override void ActivateForm(Window form, Window window, IntPtr hwnd)
        {
            var fHandle = (PresentationSource.FromVisual(form) as HwndSource).Handle;
            var wHandle = (PresentationSource.FromVisual(window) as HwndSource).Handle;

            if (window == null || wHandle != fHandle)
            {
                uint fgProcessId;
                uint spProcessId;
                User32.GetWindowThreadProcessId(User32.GetForegroundWindow(), out fgProcessId);
                User32.GetWindowThreadProcessId(fHandle, out spProcessId);

                if (fgProcessId != spProcessId)
                {
                    if (User32.AttachThreadInput(fgProcessId, spProcessId, true))
                    {
                        User32.SetForegroundWindow(fHandle);
                        User32.AttachThreadInput(fgProcessId, spProcessId, false);
                    }
                }
                else
                {
                    User32.SetForegroundWindow(fHandle);
                }

                // stop flashing...happens occassionally when switching quickly when activate manuver is fails
                Shell32.FlashWindow(fHandle, 0);
            }
        }
Пример #2
0
        public override void ActivateForm(Window form, Window window, IntPtr hwnd)
        {
            var fHandle = (PresentationSource.FromVisual(form) as HwndSource).Handle;
            var wHandle = (PresentationSource.FromVisual(window) as HwndSource).Handle;

            if (window == null || wHandle != fHandle)
            {
                // set as active form in task bar
                User32.ShowWindow(fHandle, User32.ShowWindowCommands.Restore);
                User32.SetForegroundWindow(fHandle);

                // stop flashing...happens occassionally when switching quickly when activate manuver is fails
                Shell32.FlashWindow(fHandle, 0);
            }
        }
Пример #3
0
        public override void ActivateForm(Window form, Window window, IntPtr hwnd)
        {
            var fHandle = (PresentationSource.FromVisual(form) as HwndSource).Handle;
            var wHandle = (PresentationSource.FromVisual(window) as HwndSource).Handle;

            if (window == null || wHandle != fHandle)
            {
                form.Topmost = true;
                form.Topmost = false;
                form.Focus();
                form.Show();
                form.Activate();

                // stop flashing...happens occassionally when switching quickly when activate manuver is fails
                Shell32.FlashWindow(fHandle, 0);
            }
        }
Пример #4
0
        public override void ActivateForm(Window form, Window window, IntPtr hwnd)
        {
            var fHandle = (PresentationSource.FromVisual(form) as HwndSource).Handle;
            var wHandle = window == null ? IntPtr.Zero : (PresentationSource.FromVisual(window) as HwndSource).Handle;

            if (window == null || wHandle != fHandle)
            {
                IntPtr Dummy = IntPtr.Zero;

                IntPtr hWnd = fHandle;
                if (User32.IsIconic(hWnd))
                {
                    User32.ShowWindowAsync(hWnd, SW_RESTORE);
                }
                else
                {
                    //User32.ShowWindowAsync(hWnd, SW_SHOW);
                    form.ShowActivated = true;
                    form.Show();
                }
                User32.SetForegroundWindow(hWnd);
                form.Activate();
                form.Topmost = true;
                form.Topmost = false;

                // Code from Karl E. Peterson, www.mvps.org/vb/sample.htm
                // Converted to Delphi by Ray Lischner
                // Published in The Delphi Magazine 55, page 16
                // Converted to C# by Kevin Gale
                IntPtr foregroundWindow = User32.GetForegroundWindow();
                if (foregroundWindow != hWnd)
                {
                    uint foregroundThreadId = User32.GetWindowThreadProcessId(foregroundWindow, Dummy);
                    uint thisThreadId       = User32.GetWindowThreadProcessId(hWnd, Dummy);

                    if (User32.AttachThreadInput(thisThreadId, foregroundThreadId, true))
                    {
                        form.Activate();
                        form.Topmost = true;
                        form.Topmost = false;
                        User32.BringWindowToTop(hWnd);                         // IE 5.5 related hack
                        User32.SetForegroundWindow(hWnd);
                        User32.AttachThreadInput(thisThreadId, foregroundThreadId, false);
                    }
                }

                if (User32.GetForegroundWindow() != hWnd)
                {
                    // Code by Daniel P. Stasinski
                    // Converted to C# by Kevin Gale
                    IntPtr Timeout = IntPtr.Zero;
                    User32.SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, Timeout, 0);
                    User32.SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, Dummy, SPIF_SENDCHANGE);
                    User32.BringWindowToTop(hWnd);                     // IE 5.5 related hack
                    User32.SetForegroundWindow(hWnd);
                    form.Activate();
                    form.Topmost = true;
                    form.Topmost = false;
                    User32.SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, Timeout, SPIF_SENDCHANGE);
                }

                Shell32.FlashWindow(fHandle, 0);
            }
        }