Пример #1
0
        /// <summary>
        /// Registers the an element within a window, allowing the user to use it to drag the window.
        /// Make sure that this method is called after the window has loaded; placing it in the
        /// window's constructor will not work.
        /// </summary>
        /// <param name="window">The window.</param>
        /// <param name="element">The element.</param>
        public static void Register(Window window, UIElement element)
        {
            var windowHandle = new WindowInteropHelper(window).Handle;

            if (windowHandle.ToInt64() > 0)
            {
                element.MouseMove += delegate(object sender, MouseEventArgs e)
                {
                    if (e.Source == element)
                    {
                        Action moveWindow = () =>
                        {
                            if (e.LeftButton == MouseButtonState.Pressed)
                            {
                                ReleaseCapture();
                                SendMessage(
                                    windowHandle,
                                    WM_NCLBUTTONDOWN,
                                    HT_CAPTION, 0);
                            }
                        };

                        // This may seem a bit odd; I was encountering an odd exception with the
                        // moveWindow code when I did not use the dispatcher and tried to drag off
                        // of a control that was not the window itself.
                        // More details here: http://stackoverflow.com/questions/7442943/dispatcher-throws-invalidoperationexception-on-messagebox-show-in-textchanged-ev#answer-7443519
                        Application.Current.Dispatcher.BeginInvoke(
                            DispatcherPriority.Normal,
                            moveWindow);
                    }
                };
            }
        }
Пример #2
0
        /// <summary>
        /// Gets the window's WS_DISABLED style. See <see cref="SetNativeEnabled(Window, bool)"/>.
        /// </summary>
        /// <returns>true, if the window is enabled; otherwise, false.</returns>
        public static bool IsNativeEnabled(this Window window)
        {
            IntPtr hWnd = new WindowInteropHelper(window).Handle;

            if (hWnd.ToInt64() != 0)
            {
                long style = GetWindowLong(hWnd, GWL_STYLE);
                return((style & WS_DISABLED) == 0);
            }
            return(false);
        }
Пример #3
0
        /// <summary>
        /// Hides the close button in the window title bar.
        /// </summary>
        /// <param name="window">The Window instance.</param>
        public static void HideCloseBox(this Window window)
        {
            IntPtr hwnd = new WindowInteropHelper(window).Handle;

            if (hwnd.ToInt64() == 0)
            {
                window.SourceInitialized += (s, a) => HideCloseBox(window);
            }
            else
            {
                SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);
            }
        }
Пример #4
0
        /// <summary>
        /// Sets the window's WS_DISABLED style without telling the framework about it. The window
        /// can be made disabled for the operating system and will not react to user input but still
        /// appear enabled.
        /// </summary>
        /// <param name="isEnabled">true, to enable the window; false, to disable it.</param>
        /// <returns>true, if the state was applied; otherwise, false.</returns>
        public static bool SetNativeEnabled(this Window window, bool isEnabled)
        {
            IntPtr hWnd = new WindowInteropHelper(window).Handle;

            if (hWnd.ToInt64() != 0)
            {
                long prevStyle = SetWindowLong(
                    hWnd,
                    GWL_STYLE,
                    GetWindowLong(hWnd, GWL_STYLE) & ~WS_DISABLED | (isEnabled ? 0 : WS_DISABLED));
                return(prevStyle != 0);
            }
            return(false);
        }
Пример #5
0
        /// <summary>
        /// Hides the minimize and maximize buttons in the window title bar.
        /// </summary>
        /// <param name="window">The Window instance.</param>
        public static void HideMinimizeAndMaximizeBoxes(this Window window)
        {
            IntPtr hwnd = new WindowInteropHelper(window).Handle;

            if (hwnd.ToInt64() == 0)
            {
                window.SourceInitialized += (s, a) => HideMinimizeAndMaximizeBoxes(window);
            }
            else
            {
                SetWindowLong(hwnd, GWL_STYLE,
                              GetWindowLong(hwnd, GWL_STYLE) & ~(WS_MAXIMIZEBOX | WS_MINIMIZEBOX));
            }
        }
Пример #6
0
        /// <summary>
        /// Stops flashing the window in the task bar.
        /// </summary>
        /// <param name="window">The Window instance.</param>
        /// <returns></returns>
        public static bool StopFlashing(this Window window)
        {
            IntPtr hWnd = new WindowInteropHelper(window).Handle;

            if (hWnd.ToInt64() != 0)
            {
                var fInfo = new FLASHWINFO();
                fInfo.cbSize    = Convert.ToUInt32(Marshal.SizeOf(fInfo));
                fInfo.hwnd      = hWnd;
                fInfo.dwFlags   = FLASHW_STOP;
                fInfo.uCount    = 0;
                fInfo.dwTimeout = 0;
                return(FlashWindowEx(ref fInfo));
            }
            return(false);
        }
Пример #7
0
        /// <summary>
        /// Hides the icon in the window title bar.
        /// </summary>
        /// <param name="window">The Window instance.</param>
        public static void HideIcon(this Window window)
        {
            IntPtr hwnd = new WindowInteropHelper(window).Handle;

            if (hwnd.ToInt64() == 0)
            {
                window.SourceInitialized += (s, a) => HideIcon(window);
            }
            else
            {
                uint exStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
                SetWindowLong(hwnd, GWL_EXSTYLE, exStyle | WS_EX_DLGMODALFRAME);
                SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
                SendMessage(hwnd, WM_SETICON, new IntPtr(1), IntPtr.Zero);                   // Important if there's a native icon resource in the .exe file
                SendMessage(hwnd, WM_SETICON, IntPtr.Zero, IntPtr.Zero);
            }
        }
Пример #8
0
        public new void UnsetClickThrou()
        {
            var hwnd = new WindowInteropHelper(this).Handle;

            if (hwnd.ToInt64() == 0)
            {
                _needRefreshClickThrou = true;
                return;
            }
            _needRefreshClickThrou = false;
            WindowsServices.SetWindowExVisible(hwnd);
            foreach (var players in Controls)
            {
                players.Value.UnsetClickThrou();
            }
            _entityStats.UnsetClickThrou();
            _bossGageBar.UnsetClickThrou();
            _popupNotification.UnsetClickThrou();
            EntityStatsImage.Source = BasicTeraData.Instance.ImageDatabase.EntityStats.Source;
        }