[ZoomIt] Fix issue with .png extension not being appended to screenshots. Add datetime suffix to screenshots #43172
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 a flaw with ZoomIt's screenshot save feature where the
.pngfile extension would not be included when a period was present anywhere in the path.Includes an update to create unique screenshot filenames, saving the user from having to manually type a new filename each time they save a new screenshot in the same location.
PR Checklist
Detailed Description of the Pull Request / Additional comments
Extension addition error
This code in
Zoomit.cppcontains the error:openFileName.lpstrFile = filePath; if( GetSaveFileName( &openFileName ) ) { TCHAR targetFilePath[MAX_PATH]; _tcscpy( targetFilePath, filePath ); if( !_tcsrchr( targetFilePath, '.' ) ) { _tcscat( targetFilePath, L".png" ); }(https://github.com/microsoft/PowerToys/blob/main/src/modules/ZoomIt/ZoomIt/Zoomit.cpp#L6253-L6261)
The intention appears to be to append the extension when it doesn't already exist, but the check is flawed. Instead of checking for the extension explicitly, it is assumed to exist if a period exists anywhere in the entire path. If the path is something like:
C:\Users\John.Smith\Pictures\zoomitthen it will fail to add the required extension.
There is actually no need for this manual check, as the appending of the extension will be done automatically when the file is saved if the
lpstrDefExtproperty is set on theOPENFILENAMEstructure. Oddly, the intention to do this is hinted at in the existing code, but the implementation is commented out:PowerToys/src/modules/ZoomIt/ZoomIt/Zoomit.cpp
Line 6247 in 957b653
This may have been done when the transition was being made from BMP screenshots to PNGs, or the issue may have been attempting to use
"*.png"when only"png"is required.This PR fixes the issue by:
pngas the default filename extension -lpstrDefExt.Unique filename issue
The PR also fixes the user's other complaint about the screenshots always being called "zoomit" by adding a
GetUniqueScreenshotFilename()method which creates a unique filename based on the current date and time, e.g.ZoomIt 2025-11-01 004723.png. This is consistent with other tools like the Windows Snipping Tool and provides files which sort correctly when ordered by name, which is not the case for files with simple numeric suffixes.Validation Steps Performed
Tested on a local build.