Exemple #1
0
        /// <summary>
        ///     Hides close (X) button in top right window
        /// </summary>
        /// <param name="window"></param>
        /// <param name="addClosingHook">
        ///     If true, adds delegate to Closing event which sets Cancel to true causing Window to note
        ///     close. Please note, calling Close() method will not close the window either.
        /// </param>
        internal static void HideCloseButton(this Window window, bool addClosingHook = false)
        {
            var hwnd = new WindowInteropHelper(window).Handle;

            PInvoke.SetWindowLong(hwnd, PInvoke.GwlStyle,
                                  PInvoke.GetWindowLong(hwnd, PInvoke.GwlStyle) & ~PInvoke.WsSysmenu);

            if (addClosingHook)
            {
                // Cancel Closing event (if it occurs)
                window.Closing += delegate(object sender, CancelEventArgs args) { args.Cancel = true; };
            }
        }
Exemple #2
0
        /// <summary>
        ///     Hides icon for window.
        ///     If this is called before InitializeComponent() then the icon will be completely removed from the title bar
        ///     If this is called after InitializeComponent() then an empty image is used but there will be empty space between
        ///     window border and title
        /// </summary>
        /// <param name="window">Window class</param>
        internal static void HideIcon(this Window window)
        {
            if (window.IsInitialized)
            {
                window.Icon = BitmapSource.Create(1, 1, 96, 96, PixelFormats.Bgra32, null, new byte[] { 0, 0, 0, 0 }, 4);
            }
            else
            {
                window.SourceInitialized += delegate
                {
                    // Get this window's handle
                    var hwnd = new WindowInteropHelper(window).Handle;

                    // Change the extended window style to not show a window icon
                    var extendedStyle = PInvoke.GetWindowLong(hwnd, PInvoke.GwlExstyle);
                    PInvoke.SetWindowLong(hwnd, PInvoke.GwlExstyle, extendedStyle | PInvoke.WsExDlgmodalframe);

                    // Update the window's non-client area to reflect the changes
                    PInvoke.SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0,
                                         PInvoke.SwpNomove | PInvoke.SwpNosize | PInvoke.SwpNozorder | PInvoke.SwpFramechanged);
                };
            }
        }