Repository: flutter
Issue: [Windows] Window flickering after SetWindowPos
Labels: engine,platform-windows,c: rendering,a: desktop,has reproducible steps,P2,found in release: 3.10,found in release: 3.13,team-windows,triaged-windows

### Is there an existing issue for this?

- [X] I have searched the [existing issues](https://github.com/flutter/flutter/issues)
- [X] I have read the [guide to filing a bug](https://flutter.dev/docs/resources/bug-reports)


### Description

During recent work on a Windows application, I noticed a very annoying problem when resizing a window using a _SetWindowPos_ method. When the window is resized and repositioned, the content renders incorrectly for a fraction of a second, leading to a strange flicker.
I'm not entirely sure, but it seems to me that the problem occurs during _WM_WINDOWPOSCHANGING_.
The problem is best seen in the video below

### Steps to reproduce

1. Set window as frameless
2. Move and resize window using Window's SetWindowPos method
3. In some cases, the window starts flashing/flickering

### Expected results

The window should resize without flickering

### Actual results

The content of the window display incorrectly for a few milliseconds, which looks like the application is flickering.

### Code sample

Here is repo with sample project
[https://github.com/pawlik92/flutter_win_resize_bug](https://github.com/pawlik92/flutter_win_resize_bug)

To make it easier, I used the [window_manager ](https://pub.dev/packages/window_manager) package and setBounds method to change the position and size of the window. This method uses _SetWindowPos_ underhood ([setBounds()](https://github.com/leanflutter/window_manager/blob/8caf178456968fee5ee82dd90d95a01dd4b1137b/windows/window_manager.cpp#L698)),

### Screenshots or Video

<details>
<summary>Video demonstration</summary>

https://github.com/flutter/flutter/assets/9088664/be3758e3-92bb-4428-ac76-2db18353a118

</details>

<details>
<summary>Screenshots</summary>

Correct screen
![good](https://github.com/flutter/flutter/assets/9088664/6976acd0-ac69-4780-ac67-fb6b0cdb621f)

Invalid screen - offset from the original
![bad_1](https://github.com/flutter/flutter/assets/9088664/7bb15344-be1e-47d6-83af-336214f126ee)

Invalid screen - distortion
![bad_2](https://github.com/flutter/flutter/assets/9088664/edd865d1-bf5e-4012-becc-b50a75f041b3)

</details>


### Logs

_No response_

### Flutter Doctor output

<details><summary>Doctor output</summary>

```console
[√] Flutter (Channel stable, 3.10.5, on Microsoft Windows [Version 10.0.22000.2057], locale pl-PL)
    • Flutter version 3.10.5 on channel stable at C:\src\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 796c8ef792 (5 weeks ago), 2023-06-13 15:51:02 -0700
    • Engine revision 45f6e00911
    • Dart version 3.0.5
    • DevTools version 2.23.1

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at C:\Users\Dev\AppData\Local\Android\sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: D:\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.6.3)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.6.33801.468
    • Windows 10 SDK version 10.0.22621.0

[√] Android Studio (version 2021.2)
    • Android Studio at D:\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)

[√] VS Code (version 1.80.1)
    • VS Code at C:\Users\Dev\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.68.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22000.2057]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 114.0.5735.199
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 114.0.1823.67

[√] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>