Repository navigation
[Crop and Lock] Use GetWindowRect instead of DwmGetWindowAttribute for window bounds - #49736
Merged
Merged
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
Author
|
@microsoft-github-policy-service agree |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates Crop and Lockâs window-bound calculations to use GetWindowRect (GDI-style window bounds) instead of DwmGetWindowAttribute(DWMWA_EXTENDED_FRAME_BOUNDS), aligning the coordinate space used for cropping math with what PrintWindow/GDI capture produces and addressing misalignment under DPI scaling.
Changes:
- Switched window bounds retrieval to
GetWindowRectin the screenshot capture path. - Switched window bounds retrieval to
GetWindowRectin the DWM thumbnail crop path and updated the related inline comment.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/modules/CropAndLock/CropAndLock/ThumbnailCropAndLockWindow.cpp | Uses GetWindowRect for target window bounds when translating the overlayâs client-relative crop rect into window-space for DWM thumbnail source rects. |
| src/modules/CropAndLock/CropAndLock/ScreenshotCropAndLockWindow.cpp | Uses GetWindowRect for target window bounds to compute correct client-to-window offsets before cropping the PrintWindow bitmap. |
|
čĶæŊč―åŋŦįđåå ĨæĢåžįå°ąåĨ―äšð |
Contributor
|
/azp run |
Muyuan Li (MuyuanMS)
approved these changes
Sep 3, 2026
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Muyuan Li (MuyuanMS)
enabled auto-merge (squash)
September 3, 2026 02:12
This was referenced Sep 30, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary of the Pull Request
This PR fixes the coordinate misalignment and cropping inaccuracies in the Crop and Lock utility by aligning the coordinate calculation system with GDI boundaries.
The root cause was a mismatch between GDI and DWM coordinate spaces.
PrintWindowdraws the target window using standard GDI boundaries (which include invisible resize borders and drop shadows). However, the code was calculatingwindowRectusingDwmGetWindowAttributewithDWMWA_EXTENDED_FRAME_BOUNDS(DWM visible boundaries). This discrepancy caused the calculatedoffsetXandoffsetYoffsets to be too small, resulting in the cropped image being shifted (capturing empty margins/shadows on one side and clipping the actual content on the other).By switching to
::GetWindowRect, all coordinate and offset math is unified into the GDI coordinate space, ensuring pixel-perfect cropping alignment.PR Checklist
Detailed Description of the Pull Request / Additional comments
ScreenshotCropAndLockWindow.cppandThumbnailCropAndLockWindow.cppto use::GetWindowRectinstead ofDwmGetWindowAttributewhen querying target window bounds.ThumbnailCropAndLockWindow.cppto reflect that bounds are now reported byGetWindowRect.Validation Steps Performed
(Note: The thin black borders remaining on the left and right sides in the modified version (right) are not a cropping alignment artifact; they are the actual internal borders/padding belonging to the targeted application window itself).