Exemple #1
0
        internal bool MessageBoxWithFocusRestore(string message, MessageBoxButton buttons, MessageBoxImage image)
        {
            bool   result = false;
            IntPtr focus  = UnsafeNativeMethods.GetFocus();

            try
            {
                result = (MessageBox.Show(message, this.DialogCaption, buttons, image, MessageBoxResult.OK, MessageBoxOptions.None) == MessageBoxResult.Yes);
            }
            finally
            {
                UnsafeNativeMethods.SetFocus(new HandleRef(this, focus));
            }
            return(result);
        }
Exemple #2
0
        /// <summary>
        /// 获取一个值,该值指示控件或它的一个子控件当前是否有输入焦点。
        /// </summary>
        /// <param name="hWnd">控件句柄。</param>
        /// <returns>如果控件或它的一个子控件当前已经有输入焦点,则为 true;否则为 false。</returns>
        public static bool GetContainsFocus(IntPtr hWnd)
        {
            if (!GetIsHandleCreated(hWnd))
            {
                return(false);
            }

            IntPtr focus = UnsafeNativeMethods.GetFocus();

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

            return((focus == hWnd) || UnsafeNativeMethods.IsChild(hWnd, focus));
        }
Exemple #3
0
 /// <summary>
 /// 获取一个值,该值指示控件是否有输入焦点。
 /// </summary>
 /// <param name="hWnd">控件句柄。</param>
 /// <returns>如果控件有焦点,则为 true;否则为 false。</returns>
 public static bool GetFocused(IntPtr hWnd)
 {
     return(GetIsHandleCreated(hWnd) && (UnsafeNativeMethods.GetFocus() == hWnd));
 }