GetActiveWindow() private method

private GetActiveWindow ( ) : IntPtr
return System.IntPtr
        /// <summary>
        /// Start tracking the provided popup.
        /// </summary>
        /// <param name="popup">Popup instance to track.</param>
        public void StartTracking(VisualPopup popup)
        {
            Debug.Assert(popup != null);
            Debug.Assert(!popup.IsDisposed);
            Debug.Assert(popup.IsHandleCreated);
            Debug.Assert(_suspended == 0);

            // The popup control must be valid
            if ((popup != null) && !popup.IsDisposed && popup.IsHandleCreated)
            {
                // Cannot start tracking when a popup menu is alive
                if (_suspended == 0)
                {
                    // If we already have a popup...
                    if (_current != null)
                    {
                        // Then stack it
                        _stack.Push(_current);
                    }
                    else
                    {
                        // Cache the currently active window
                        _activeWindow = PI.GetActiveWindow();

                        // For the first popup, we hook into message processing
                        FilterMessages(true);
                    }

                    // Store reference
                    _current = popup;
                }
            }
        }
Beispiel #2
0
        private static string InternalShow(IWin32Window owner, string title, string message, string prompt = "", string okText = "O&k", string cancelText = "&Cancel", bool passwordEnabled = false, FormStartPosition startPosition = FormStartPosition.WindowsDefaultLocation)
        {
            IWin32Window showOwner = owner ?? FromHandle(PI.GetActiveWindow());

            using (KryptonInputBox kib = new KryptonInputBox(title, message, prompt, okText, cancelText, passwordEnabled, startPosition))
            {
                kib.StartPosition = showOwner == null ? startPosition : startPosition;

                return(kib.ShowDialog(showOwner) == DialogResult.OK ? kib.GetUserResponse() : string.Empty);
            }
        }
        private static string InternalShow(IWin32Window owner,
                                           string prompt,
                                           string caption,
                                           string defaultResponse)
        {
            // If do not have an owner passed in then get the active window and use that instead
            IWin32Window showOwner = owner ?? FromHandle(PI.GetActiveWindow());

            // Show input box window as a modal dialog and then dispose of it afterwards
            using (KryptonInputBox ib = new KryptonInputBox(prompt, caption, defaultResponse))
            {
                ib.StartPosition = showOwner == null ? FormStartPosition.CenterScreen : FormStartPosition.CenterParent;

                return(ib.ShowDialog(showOwner) == DialogResult.OK ? ib.InputResponse : string.Empty);
            }
        }
        public bool PreFilterMessage(ref Message m)
        {
            // If we have suspended operation....
            if (_suspended > 0)
            {
                // Intercept the non-client mouse move to prevent the custom
                // chrome of the form from providing hot tracking feedback
                if (m.Msg == PI.WM_NCMOUSEMOVE)
                {
                    return(true);
                }

                // A mouse move can occur because a context menu is showing with a popup also
                // already showing. We suppress the mouse move to prevent tracking of the popup
                if (m.Msg == PI.WM_MOUSEMOVE)
                {
                    return(ProcessMouseMoveWithCMS(ref m));
                }

                return(false);
            }

            if (_current != null)
            {
                // If the popup has been become disposed
                if (_current.IsDisposed)
                {
                    EndCurrentTracking();
                    return(false);
                }
                else
                {
                    // Get the active window
                    IntPtr activeWindow = PI.GetActiveWindow();

                    // Is there a change in active window?
                    if (activeWindow != _activeWindow)
                    {
                        // If the current window has become active, ask popup if that is allowed
                        if ((activeWindow == _current.Handle) && _current.AllowBecomeActiveWhenCurrent)
                        {
                            _activeWindow = _current.Handle;
                        }
                        else
                        {
                            bool focus = _current.ContainsFocus;

                            if (!focus)
                            {
                                VisualPopup[] popups = _stack.ToArray();

                                // For from last to first for any popup that has the focus
                                for (int i = popups.Length - 1; i >= 0; i--)
                                {
                                    if (!popups[i].IsDisposed)
                                    {
                                        if (popups[i].ContainsFocus)
                                        {
                                            focus = true;
                                            break;
                                        }
                                    }
                                }
                            }

                            // If the change in active window (focus) is not to the current
                            // or a stacked popup then we need to pull down the entire stack
                            // as focus has been shifted away from the use of any popup.
                            if (!focus)
                            {
                                EndAllTracking();
                                return(false);
                            }
                        }
                    }
                }

                // We only intercept and handle keyboard and mouse messages
                if (!IsKeyOrMouseMessage(ref m))
                {
                    return(false);
                }

                switch (m.Msg)
                {
                case PI.WM_KEYDOWN:
                case PI.WM_SYSKEYDOWN:
                    // If the popup is telling us to redirect keyboard to itself
                    if (!_current.KeyboardInert)
                    {
                        // If the focus is not inside the actual current tracking popup
                        // then we need to manually translate the message to ensure that
                        // KeyPress events occur for the current popup.
                        if (!_current.ContainsFocus)
                        {
                            PI.MSG msg = new PI.MSG
                            {
                                hwnd    = m.HWnd,
                                message = m.Msg,
                                lParam  = m.LParam,
                                wParam  = m.WParam
                            };
                            PI.TranslateMessage(ref msg);
                        }
                        return(ProcessKeyboard(ref m));
                    }
                    break;

                case PI.WM_CHAR:
                case PI.WM_KEYUP:
                case PI.WM_DEADCHAR:
                case PI.WM_SYSCHAR:
                case PI.WM_SYSKEYUP:
                case PI.WM_SYSDEADCHAR:
                    // If the popup is telling us to redirect keyboard to itself
                    if (!_current.KeyboardInert)
                    {
                        return(ProcessKeyboard(ref m));
                    }

                    break;

                case PI.WM_MOUSEMOVE:
                case PI.WM_NCMOUSEMOVE:
                    return(ProcessMouseMove(ref m));

                case PI.WM_LBUTTONDOWN:
                case PI.WM_RBUTTONDOWN:
                case PI.WM_MBUTTONDOWN:
                    return(ProcessClientMouseDown(ref m));

                case PI.WM_NCLBUTTONDOWN:
                case PI.WM_NCRBUTTONDOWN:
                case PI.WM_NCMBUTTONDOWN:
                    return(ProcessNonClientMouseDown(ref m));
                }
            }

            return(false);
        }
Beispiel #5
0
 public DialogResult ShowDialog()
 {
     return(ShowDialog(Control.FromHandle(PI.GetActiveWindow())));
 }