예제 #1
0
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
            case NativeMethods.WM_REFLECT + NativeMethods.WM_HSCROLL:
            case NativeMethods.WM_REFLECT + NativeMethods.WM_VSCROLL:
                WmReflectScroll(ref m);
                break;

            case NativeMethods.WM_ERASEBKGND:
                break;

            case NativeMethods.WM_SIZE:
                //VS7#13707 : FredB, 4/26/1999 - Fixes the scrollbar focus rect
                if (UnsafeNativeMethods.GetFocus() == this.Handle)
                {
                    DefWndProc(ref m);
                    SendMessage(NativeMethods.WM_KILLFOCUS, 0, 0);
                    SendMessage(NativeMethods.WM_SETFOCUS, 0, 0);
                }
                break;

            default:
                base.WndProc(ref m);
                break;
            }
        }
예제 #2
0
        /// <include file='doc\FileDialog.uex' path='docs/doc[@for="FileDialog.MessageBoxWithFocusRestore"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Prompts the user with a <see cref='System.Windows.Forms.MessageBox'/>
        ///       with the given parameters. It also ensures that
        ///       the focus is set back on the window that had
        ///       the focus to begin with (before we displayed
        ///       the MessageBox).
        ///    </para>
        /// </devdoc>
        internal bool MessageBoxWithFocusRestore(string message, string caption,
                                                 MessageBoxButtons buttons, MessageBoxIcon icon)
        {
            bool   ret;
            IntPtr focusHandle = UnsafeNativeMethods.GetFocus();

            try {
                ret = MessageBox.Show(message, caption,
                                      buttons, icon) == DialogResult.Yes;
            }
            finally {
                UnsafeNativeMethods.SetFocus(new HandleRef(null, focusHandle));
            }
            return(ret);
        }
예제 #3
0
            // Enables/disables all top-level Controls on this thread
            internal void Enable(bool state)
            {
                if (!_onlyWinForms && !state)
                {
                    _activeHwnd = UnsafeNativeMethods.GetActiveWindow();
                    Control activatingControl = ThreadContext.FromCurrent().ActivatingControl;
                    if (activatingControl != null)
                    {
                        _focusedHwnd = activatingControl.Handle;
                    }
                    else
                    {
                        _focusedHwnd = UnsafeNativeMethods.GetFocus();
                    }
                }

                for (int i = 0; i < _windowCount; i++)
                {
                    IntPtr hWnd = _windows[i];
                    Debug.WriteLineIf(CompModSwitches.MSOComponentManager.TraceInfo, "ComponentManager : Changing enabled on window: " + hWnd.ToString() + " : " + state.ToString());
                    if (UnsafeNativeMethods.IsWindow(new HandleRef(null, hWnd)))
                    {
                        SafeNativeMethods.EnableWindow(new HandleRef(null, hWnd), state);
                    }
                }

                // OpenFileDialog is not returning the focus the way other dialogs do.
                // Important that we re-activate the old window when we are closing
                // our modal dialog.
                //
                // edit mode forever with Excel application
                // But, DON'T change other people's state when we're simply
                // responding to external MSOCM events about modality.  When we are,
                // we are created with a TRUE for onlyWinForms.
                if (!_onlyWinForms && state)
                {
                    if (_activeHwnd != IntPtr.Zero && UnsafeNativeMethods.IsWindow(new HandleRef(null, _activeHwnd)))
                    {
                        UnsafeNativeMethods.SetActiveWindow(new HandleRef(null, _activeHwnd));
                    }

                    if (_focusedHwnd != IntPtr.Zero && UnsafeNativeMethods.IsWindow(new HandleRef(null, _focusedHwnd)))
                    {
                        UnsafeNativeMethods.SetFocus(new HandleRef(null, _focusedHwnd));
                    }
                }
            }
예제 #4
0
        internal static DebugFocus()
        {
            IntPtr focusHwnd = UnsafeNativeMethods.GetFocus();

            if (focusHwnd != lastFocusHwnd)
            {
                lastFocusHwnd = focusHwnd;
                if (focusHwnd != IntPtr.Zero)
                {
                    Debug.WriteLine("FOCUS watch: new focus: " + focusHwnd.ToString() + GetControlInformation(focusHwnd));
                }
                else
                {
                    Debug.WriteLine("FOCUS watch: no one has focus");
                }
            }
            return(false);
        }
        /// <devdoc>
        ///     Assigns focus to the activeControl. If there is no activeControl then
        ///     focus is given to the form.
        ///     package scope for Form
        /// </devdoc>
        internal void FocusActiveControlInternal()
        {
#if DEBUG
            // Things really get ugly if you try to pop up an assert dialog here
            if (activeControl != null && !this.Contains(activeControl))
            {
                Debug.WriteLine("ActiveControl is not a child of this ContainerControl");
            }
#endif

            if (activeControl != null && activeControl.Visible)
            {
                // Avoid focus loops, especially with ComboBoxes, on Win98/ME.
                //
                IntPtr focusHandle = UnsafeNativeMethods.GetFocus();
                if (focusHandle == IntPtr.Zero || Control.FromChildHandleInternal(focusHandle) != activeControl)
                {
                    UnsafeNativeMethods.SetFocus(new HandleRef(activeControl, activeControl.Handle));
                }
            }
            else
            {
                // Determine and focus closest visible parent
                ContainerControl cc = this;
                while (cc != null && !cc.Visible)
                {
                    Control parent = cc.ParentInternal;
                    if (parent != null)
                    {
                        cc = parent.GetContainerControlInternal() as ContainerControl;
                    }
                    else
                    {
                        break;
                    }
                }
                if (cc != null && cc.Visible)
                {
                    UnsafeNativeMethods.SetFocus(new HandleRef(cc, cc.Handle));
                }
            }
        }
예제 #6
0
        private bool FocusInside()
        {
            if (!IsHandleCreated)
            {
                return(false);
            }

            IntPtr hwndFocus = UnsafeNativeMethods.GetFocus();

            if (hwndFocus == IntPtr.Zero)
            {
                return(false);
            }

            IntPtr hwnd = Handle;

            if (hwnd == hwndFocus || SafeNativeMethods.IsChild(new HandleRef(this, hwnd), new HandleRef(null, hwndFocus)))
            {
                return(true);
            }

            return(false);
        }