Repository: microsoft/PowerToys
File: src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/MainWindow.xaml.cs (C#)

Code before:
                }
            };

            AppWindow.SetIcon("Assets/AdvancedPaste/AdvancedPaste.ico");
            this.ExtendsContentIntoTitleBar = true;
            this.SetTitleBar(titleBar);

            var loader = ResourceLoaderInstance.ResourceLoader;
            Title = loader.GetString("WindowTitle");

            Activated += OnActivated;

            _msgMonitor = new WindowMessageMonitor(this);
            _msgMonitor.WindowMessageReceived += (_, e) =>
            {
                const int WM_NCLBUTTONDBLCLK = 0x00A3;
                if (e.Message.MessageId == WM_NCLBUTTONDBLCLK)
                {
                    // Disable double click on title bar to maximize window
                    e.Result = 0;
                    e.Handled = true;
                }
            };

            WindowHelpers.BringToForeground(this.GetWindowHandle());
            WindowHelpers.ForceTopBorder1PixelInset(this.GetWindowHandle());
        }

        private void OnActivated(object sender, WindowActivatedEventArgs args)
        {
            if (_userSettings.CloseAfterLosingFocus && args.WindowActivationState == WindowActivationState.Deactivated)
            {
                Hide();
            }
        }

        private void Dispose(bool disposing)
        {
            if (!_disposedValue)
            {
                _msgMonitor?.Dispose();
                (Application.Current as App).EtwTrace?.Dispose();

                _disposedValue = true;
            }
        }

        public void Dispose()
        {
            // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
            Dispose(disposing: true);

Review comment (suggestion):
The docs for `DwmExtendFrameIntoClientArea()` say that:
> This function must be called whenever Desktop Window Manager (DWM) composition is toggled. Handle the [WM_DWMCOMPOSITIONCHANGED](https://learn.microsoft.com/en-us/windows/desktop/dwm/wm-dwmcompositionchanged) message for composition change notification.

...however, the docs for `WM_DWMCOMPOSITIONCHANGED` go on to note that:
> As of Windows 8, DWM composition is always enabled, so this message is not sent regardless of video mode changes.

...so I don't think we need to handle this in Window.Activated--just one call at creation time seems to be enough.

Code after:
                }
            };

            AppWindow.SetIcon("Assets/AdvancedPaste/AdvancedPaste.ico");
            this.ExtendsContentIntoTitleBar = true;
            this.SetTitleBar(titleBar);

            var loader = ResourceLoaderInstance.ResourceLoader;
            Title = loader.GetString("WindowTitle");

            Activated += OnActivated;

            _msgMonitor = new WindowMessageMonitor(this);
            _msgMonitor.WindowMessageReceived += (_, e) =>
            {
                const int WM_NCLBUTTONDBLCLK = 0x00A3;
                if (e.Message.MessageId == WM_NCLBUTTONDBLCLK)
                {
                    // Disable double click on title bar to maximize window
                    e.Result = 0;
                    e.Handled = true;
                }
            };

            WindowHelpers.BringToForeground(this.GetWindowHandle());
            WindowHelpers.ForceTopBorder1PixelInsetOnWindows10(this.GetWindowHandle());
        }

        private void OnActivated(object sender, WindowActivatedEventArgs args)
        {
            if (_userSettings.CloseAfterLosingFocus && args.WindowActivationState == WindowActivationState.Deactivated)
            {
                Hide();
            }
        }

        private void Dispose(bool disposing)
        {
            if (!_disposedValue)
            {
                _msgMonitor?.Dispose();
                (Application.Current as App).EtwTrace?.Dispose();

                _disposedValue = true;
            }
        }

        public void Dispose()
        {
            // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
            Dispose(disposing: true);