Repository: microsoft/PowerToys
File: src/modules/MeasureTool/MeasureToolUI/MeasureToolXAML/MainWindow.xaml.cs (C#)

Code before:
        private PointInt32 _initialPosition;

        protected override void OnPositionChanged(PointInt32 position)
        {
            _appWindow.Move(_initialPosition);
            this.SetWindowSize(WindowWidth, WindowHeight);
        }

        public MainWindow(PowerToys.MeasureToolCore.Core core)
        {
            InitializeComponent();

            var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
            WindowId windowId = Win32Interop.GetWindowIdFromWindow(hwnd);
            _appWindow = AppWindow.GetFromWindowId(windowId);
            SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
            var presenter = _appWindow.Presenter as OverlappedPresenter;
            presenter.IsAlwaysOnTop = true;
            this.SetIsAlwaysOnTop(true);
            this.SetIsShownInSwitchers(false);
            this.SetIsResizable(false);
            this.SetIsMinimizable(false);
            this.SetIsMaximizable(false);
            IsTitleBarVisible = false;

            // Remove the caption style from the window style. Windows App SDK 1.6 upgraded added it, which made the title bar and borders appear for Measure Tool. This code removes it.
            var windowStyle = GetWindowLong(hwnd, GWL_STYLE);
            windowStyle = windowStyle & (~WS_CAPTION);
            _ = SetWindowLong(hwnd, GWL_STYLE, windowStyle);

            _coreLogic = core;
            Closed += MainWindow_Closed;
            DisplayArea displayArea = DisplayArea.GetFromWindowId(windowId, DisplayAreaFallback.Nearest);
            float dpiScale = _coreLogic.GetDPIScaleForWindow((int)hwnd);

            _initialPosition = new PointInt32(displayArea.WorkArea.X + (displayArea.WorkArea.Width / 2) - (int)(dpiScale * WindowWidth / 2), displayArea.WorkArea.Y + (int)(dpiScale * 12));

            _coreLogic.SetToolbarBoundingBox(
                _initialPosition.X,
                _initialPosition.Y,
                _initialPosition.X + (int)(dpiScale * WindowWidth),
                _initialPosition.Y + (int)(dpiScale * WindowHeight));
            OnPositionChanged(_initialPosition);
            SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
        }

        private void StackPanel_Loaded(object sender, RoutedEventArgs e)
        {
            SelectDefaultMeasureStyle();
        }


Review comment (suggestion):
```suggestion
            // Remove the caption style from the window style. Windows App SDK 1.6 added it, which made the title bar and borders appear for Measure Tool. This code removes it.
```

Code after:
        private PointInt32 _initialPosition;

        protected override void OnPositionChanged(PointInt32 position)
        {
            _appWindow.Move(_initialPosition);
            this.SetWindowSize(WindowWidth, WindowHeight);
        }

        public MainWindow(PowerToys.MeasureToolCore.Core core)
        {
            InitializeComponent();

            var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
            WindowId windowId = Win32Interop.GetWindowIdFromWindow(hwnd);
            _appWindow = AppWindow.GetFromWindowId(windowId);
            SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
            var presenter = _appWindow.Presenter as OverlappedPresenter;
            presenter.IsAlwaysOnTop = true;
            this.SetIsAlwaysOnTop(true);
            this.SetIsShownInSwitchers(false);
            this.SetIsResizable(false);
            this.SetIsMinimizable(false);
            this.SetIsMaximizable(false);
            IsTitleBarVisible = false;

            // Remove the caption style from the window style. Windows App SDK 1.6 added it, which made the title bar and borders appear for Measure Tool. This code removes it.
            var windowStyle = GetWindowLong(hwnd, GWL_STYLE);
            windowStyle = windowStyle & (~WS_CAPTION);
            _ = SetWindowLong(hwnd, GWL_STYLE, windowStyle);

            _coreLogic = core;
            Closed += MainWindow_Closed;
            DisplayArea displayArea = DisplayArea.GetFromWindowId(windowId, DisplayAreaFallback.Nearest);
            float dpiScale = _coreLogic.GetDPIScaleForWindow((int)hwnd);

            _initialPosition = new PointInt32(displayArea.WorkArea.X + (displayArea.WorkArea.Width / 2) - (int)(dpiScale * WindowWidth / 2), displayArea.WorkArea.Y + (int)(dpiScale * 12));

            _coreLogic.SetToolbarBoundingBox(
                _initialPosition.X,
                _initialPosition.Y,
                _initialPosition.X + (int)(dpiScale * WindowWidth),
                _initialPosition.Y + (int)(dpiScale * WindowHeight));
            OnPositionChanged(_initialPosition);
            SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
        }

        private void StackPanel_Loaded(object sender, RoutedEventArgs e)
        {
            SelectDefaultMeasureStyle();
        }