Skip to content

Update SetScreenCaptureModeInternal by reset WINDOW_DISPLAY_AFFINITY to NONE before setting new affinity #13684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

LeafShi1
Copy link
Member

@LeafShi1 LeafShi1 commented Jul 8, 2025

Fixes #13680

Proposed changes

  • Update SetScreenCaptureModeInternal by reset WINDOW_DISPLAY_AFFINITY to NONE before setting new affinity

Customer Impact

  • FormScreenCaptureMode still works properly after multiple calls

Regression?

  • Yes

Risk

  • Minimal

Screenshots

Before

When the FormScreenCaptureMode property is set twice in succession, ScreenCaptureMode always retains the first setting.

FormScreenCaptureModeIssue.mp4

After

AfterChange.mp4

Test methodology

  • Manually

Test environment(s)

  • .net 10.0.0-preview.7.25320.118
Microsoft Reviewers: Open in CodeFlow

@LeafShi1 LeafShi1 requested a review from a team as a code owner July 8, 2025 06:30
@LeafShi1 LeafShi1 requested review from Copilot and removed request for a team July 8, 2025 06:30
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR ensures that SetScreenCaptureModeInternal properly clears any existing WINDOW_DISPLAY_AFFINITY before applying a new screen-capture mode, fixing a regression when setting the property multiple times.

  • Always reset window display affinity to WDA_NONE before computing the new affinity.
  • Retains the existing switch logic to map ScreenCaptureMode to the correct WINDOW_DISPLAY_AFFINITY.
Comments suppressed due to low confidence (1)

src/System.Windows.Forms/System/Windows/Forms/Form.cs:1794

  • Add automated tests that set FormScreenCaptureMode multiple times and verify the display affinity resets correctly, ensuring this change is covered by unit tests.
        PInvoke.SetWindowDisplayAffinity(HWND, WINDOW_DISPLAY_AFFINITY.WDA_NONE);

Copy link

codecov bot commented Jul 8, 2025

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 76.69345%. Comparing base (9856a7c) to head (19e74a5).
Report is 14 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main      #13684         +/-   ##
===================================================
+ Coverage   76.60680%   76.69345%   +0.08664%     
===================================================
  Files           3253        3255          +2     
  Lines         641011      641605        +594     
  Branches       47442       47491         +49     
===================================================
+ Hits          491058      492069       +1011     
+ Misses        146303      145882        -421     
- Partials        3650        3654          +4     
Flag Coverage Δ
Debug 76.69345% <0.00000%> (+0.08664%) ⬆️
integration 18.99518% <0.00000%> (+0.00762%) ⬆️
production 51.21181% <0.00000%> (+0.14732%) ⬆️
test 97.41503% <ø> (+0.00316%) ⬆️
unit 48.59080% <0.00000%> (+0.14113%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@Epica3055 Epica3055 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

Copy link
Member

@ricardobossan ricardobossan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All LGTM!

@LeafShi1 LeafShi1 added the waiting-review This item is waiting on review by one or more members of team label Jul 10, 2025
Copy link
Member

@KlausLoeffelmann KlausLoeffelmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! :shipit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-area-label waiting-review This item is waiting on review by one or more members of team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FormScreenCaptureMode transitions between HideContent and HideWindow do not apply correctly
4 participants