-
Notifications
You must be signed in to change notification settings - Fork 991
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
Fix regression in ParkHandle method from .NET framework #4796
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
da33211
Seems this changes was missed from Day 1 and a regression from .NET f…
dreddy-work ed13c84
Merge branch 'main' of https://github.com/dotnet/winforms into dev/dr…
dreddy-work 2480252
Merge branch 'main' of https://github.com/dotnet/winforms into dev/dr…
dreddy-work dbe2f06
Adding tests around Parking window creation in various contexts.
dreddy-work 67fb2f4
Fixing build failure by analyzer.
dreddy-work d4e5778
Review feedback.
dreddy-work 7cc8993
Fixing test failures. Given that these failures are reproduced only i…
dreddy-work f95f4da
reformatting tests.
dreddy-work fa48427
Review suggestions.
dreddy-work ea3802e
Running tests only on Windows 10
dreddy-work File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
124 changes: 0 additions & 124 deletions
124
...Windows.Forms/tests/UnitTests/HDPI/System/Windows/Forms/Application.ParkingWindowTests.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,5 +57,137 @@ private Form InitFormWithControlToGarbageCollect() | |
|
||
return form; | ||
} | ||
|
||
|
||
[WinFormsFact] | ||
public void ParkingWindow_Unaware() | ||
{ | ||
// set thread awareness context to PermonitorV2(PMv2). | ||
// if process/thread is not in PMv2, calling 'EnterDpiAwarenessScope' is a no-op and that is by design. | ||
// In this case, we will be setting thread to PMv2 mode and then scope to UNAWARE | ||
IntPtr originalAwarenessContext = User32.SetThreadDpiAwarenessContext(User32.DPI_AWARENESS_CONTEXT.PER_MONITOR_AWARE_V2); | ||
|
||
try | ||
{ | ||
using (DpiHelper.EnterDpiAwarenessScope(User32.DPI_AWARENESS_CONTEXT.UNAWARE)) | ||
{ | ||
using var control = new Control(); | ||
ThreadContext cxt = GetContextForHandle(new HandleRef(this, control.Handle)); | ||
Assert.NotNull(cxt); | ||
ParkingWindow parkingWindow = cxt.GetParkingWindowForContext(User32.DPI_AWARENESS_CONTEXT.UNAWARE); | ||
Assert.NotNull(parkingWindow); | ||
|
||
IntPtr dpiContext = User32.GetWindowDpiAwarenessContext(parkingWindow.Handle); | ||
Assert.True(User32.AreDpiAwarenessContextsEqual(User32.DPI_AWARENESS_CONTEXT.UNAWARE, dpiContext)); | ||
} | ||
} | ||
finally | ||
{ | ||
// reset back to original awareness context. | ||
User32.SetThreadDpiAwarenessContext(originalAwarenessContext); | ||
} | ||
} | ||
|
||
[WinFormsFact] | ||
public void ParkingWindow_SystemAware() | ||
{ | ||
// set thread awareness context to PermonitorV2(PMv2). | ||
// if process/thread is not in PMv2, calling 'EnterDpiAwarenessScope' is a no-op and that is by design. | ||
// In this case, we will be setting thread to PMv2 mode and then scope to UNAWARE | ||
IntPtr originalAwarenessContext = User32.SetThreadDpiAwarenessContext(User32.DPI_AWARENESS_CONTEXT.PER_MONITOR_AWARE_V2); | ||
|
||
try | ||
{ | ||
using (DpiHelper.EnterDpiAwarenessScope(User32.DPI_AWARENESS_CONTEXT.SYSTEM_AWARE)) | ||
{ | ||
using var control = new Control(); | ||
ThreadContext cxt = GetContextForHandle(new HandleRef(this, control.Handle)); | ||
Assert.NotNull(cxt); | ||
ParkingWindow parkingWindow = cxt.GetParkingWindowForContext(User32.DPI_AWARENESS_CONTEXT.SYSTEM_AWARE); | ||
Assert.NotNull(parkingWindow); | ||
|
||
IntPtr dpiContext = User32.GetWindowDpiAwarenessContext(parkingWindow.Handle); | ||
Assert.True(User32.AreDpiAwarenessContextsEqual(User32.DPI_AWARENESS_CONTEXT.SYSTEM_AWARE, dpiContext)); | ||
} | ||
} | ||
finally | ||
{ | ||
// reset back to original awareness context. | ||
User32.SetThreadDpiAwarenessContext(originalAwarenessContext); | ||
} | ||
} | ||
|
||
[WinFormsFact] | ||
public void ParkingWindow_PermonitorV2() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: ParkingWindow_PerMonitorV2 |
||
{ | ||
// set thread awareness context to PermonitorV2(PMv2). | ||
// if process/thread is not in PMv2, calling 'EnterDpiAwarenessScope' is a no-op and that is by design. | ||
// In this case, we will be setting thread to PMv2 mode and then scope to UNAWARE | ||
IntPtr originalAwarenessContext = User32.SetThreadDpiAwarenessContext(User32.DPI_AWARENESS_CONTEXT.PER_MONITOR_AWARE_V2); | ||
|
||
try | ||
{ | ||
using var control = new Control(); | ||
ThreadContext cxt = GetContextForHandle(new HandleRef(this, control.Handle)); | ||
Assert.NotNull(cxt); | ||
|
||
ParkingWindow parkingWindow = cxt.GetParkingWindowForContext(User32.DPI_AWARENESS_CONTEXT.PER_MONITOR_AWARE_V2); | ||
Assert.NotNull(parkingWindow); | ||
|
||
IntPtr dpiContext = User32.GetWindowDpiAwarenessContext(parkingWindow.Handle); | ||
Assert.True(User32.AreDpiAwarenessContextsEqual(User32.DPI_AWARENESS_CONTEXT.PER_MONITOR_AWARE_V2, dpiContext)); | ||
} | ||
finally | ||
{ | ||
// reset back to original awareness context. | ||
User32.SetThreadDpiAwarenessContext(originalAwarenessContext); | ||
} | ||
} | ||
|
||
[WinFormsFact] | ||
public void ParkingWindow_Multiple() | ||
{ | ||
// set thread awareness context to PermonitorV2(PMv2). | ||
// if process/thread is not in PMv2, calling 'EnterDpiAwarenessScope' is a no-op and that is by design. | ||
// In this case, we will be setting thread to PMv2 mode and then scope to UNAWARE | ||
IntPtr originalAwarenessContext = User32.SetThreadDpiAwarenessContext(User32.DPI_AWARENESS_CONTEXT.PER_MONITOR_AWARE_V2); | ||
|
||
try | ||
{ | ||
using var control = new Control(); | ||
ThreadContext cxt = GetContextForHandle(new HandleRef(this, control.Handle)); | ||
Assert.NotNull(cxt); | ||
ParkingWindow parkingWindow = cxt.GetParkingWindowForContext(User32.DPI_AWARENESS_CONTEXT.PER_MONITOR_AWARE_V2); | ||
Assert.NotNull(parkingWindow); | ||
|
||
|
||
IntPtr dpiContext = User32.GetWindowDpiAwarenessContext(parkingWindow.Handle); | ||
Assert.True(User32.AreDpiAwarenessContextsEqual(User32.DPI_AWARENESS_CONTEXT.PER_MONITOR_AWARE_V2, dpiContext)); | ||
|
||
using (DpiHelper.EnterDpiAwarenessScope(User32.DPI_AWARENESS_CONTEXT.SYSTEM_AWARE)) | ||
{ | ||
using var systemControl = new Control(); | ||
cxt = GetContextForHandle(new HandleRef(this, systemControl.Handle)); | ||
Assert.NotNull(cxt); | ||
parkingWindow = cxt.GetParkingWindowForContext(User32.DPI_AWARENESS_CONTEXT.SYSTEM_AWARE); | ||
Assert.NotNull(parkingWindow); | ||
|
||
dpiContext = User32.GetWindowDpiAwarenessContext(parkingWindow.Handle); | ||
Assert.True(User32.AreDpiAwarenessContextsEqual(User32.DPI_AWARENESS_CONTEXT.SYSTEM_AWARE, dpiContext)); | ||
|
||
// check PMv2 parking window still available. | ||
parkingWindow = cxt.GetParkingWindowForContext(User32.DPI_AWARENESS_CONTEXT.PER_MONITOR_AWARE_V2); | ||
Assert.NotNull(parkingWindow); | ||
|
||
dpiContext = User32.GetWindowDpiAwarenessContext(parkingWindow.Handle); | ||
Assert.True(User32.AreDpiAwarenessContextsEqual(User32.DPI_AWARENESS_CONTEXT.PER_MONITOR_AWARE_V2, dpiContext)); | ||
} | ||
} | ||
finally | ||
{ | ||
// reset back to original awareness context. | ||
User32.SetThreadDpiAwarenessContext(originalAwarenessContext); | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AssertExtention that compares DPI awareness contexts would be helpful here and in the future. You can factor out this line into a helper method.