CmdPal: Ensure cached window data is refreshed when the window style changes#42405
Merged
michaeljolley merged 1 commit intomicrosoft:mainfrom Oct 16, 2025
Conversation
Collaborator
Author
|
I haven't been able to replicate the issue in any environment, but this is probably the cause and the solution. |
zadjii-msft
approved these changes
Oct 16, 2025
khmyznikov
pushed a commit
that referenced
this pull request
Oct 20, 2025
…changes (#42405) ## Summary of the Pull Request This PR resolves the issue where the window style WS_EX_TOOLWINDOW was being set but not properly applied to the window. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [x] Closes: #42395 - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed
Merged
khmyznikov
added a commit
that referenced
this pull request
Oct 21, 2025
Hotfixes #42467 #42434 #42405 #42399 --------- Co-authored-by: Jiří Polášek <me@jiripolasek.com> Co-authored-by: Niels Laute <niels.laute@live.nl> Co-authored-by: Jaylyn Barbee <51131738+Jaylyn-Barbee@users.noreply.github.com> Co-authored-by: Gordon Lam <73506701+yeelam-gordon@users.noreply.github.com> Co-authored-by: Dustin L. Howett <duhowett@microsoft.com>
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds a SetWindowPos call after SetWindowLong in the ToggleExtendedWindowStyle method to properly invalidate the cached window style. This ensures that changes to extended window styles are immediately applied by Windows.
- Captures the return value of
SetWindowLongin a variable instead of returning directly - Adds a
SetWindowPoscall withSWP_FRAMECHANGEDflag to force Windows to recalculate the window frame - Returns the original
SetWindowLongresult to maintain existing behavior
Comments suppressed due to low confidence (1)
src/modules/cmdpal/Microsoft.CmdPal.UI/Helpers/WindowExtensions.cs:38
- The documentation states the return value reflects whether SetWindowLong succeeded, but does not mention the newly added SetWindowPos call. Update the documentation to clarify that the return value only reflects SetWindowLong's success, not the subsequent SetWindowPos call that forces the style to be applied.
/// <returns>True if the call to SetWindowLong succeeded and the style was applied; otherwise false.</returns>
Comment on lines
+57
to
+59
| PInvoke.SetWindowPos(hWnd, new HWND(IntPtr.Zero), 0, 0, 0, 0, SET_WINDOW_POS_FLAGS.SWP_FRAMECHANGED | SET_WINDOW_POS_FLAGS.SWP_NOMOVE | SET_WINDOW_POS_FLAGS.SWP_NOSIZE | SET_WINDOW_POS_FLAGS.SWP_NOZORDER | SET_WINDOW_POS_FLAGS.SWP_NOOWNERZORDER); | ||
|
|
||
| return wasSet; |
There was a problem hiding this comment.
The return value of SetWindowPos is not checked. If this call fails, the window style change may not be applied. Consider checking the return value and logging a warning or adjusting the method's return value to reflect failure of either API call.
Suggested change
| PInvoke.SetWindowPos(hWnd, new HWND(IntPtr.Zero), 0, 0, 0, 0, SET_WINDOW_POS_FLAGS.SWP_FRAMECHANGED | SET_WINDOW_POS_FLAGS.SWP_NOMOVE | SET_WINDOW_POS_FLAGS.SWP_NOSIZE | SET_WINDOW_POS_FLAGS.SWP_NOZORDER | SET_WINDOW_POS_FLAGS.SWP_NOOWNERZORDER); | |
| return wasSet; | |
| var posSet = PInvoke.SetWindowPos( | |
| hWnd, | |
| new HWND(IntPtr.Zero), | |
| 0, 0, 0, 0, | |
| SET_WINDOW_POS_FLAGS.SWP_FRAMECHANGED | SET_WINDOW_POS_FLAGS.SWP_NOMOVE | SET_WINDOW_POS_FLAGS.SWP_NOSIZE | SET_WINDOW_POS_FLAGS.SWP_NOZORDER | SET_WINDOW_POS_FLAGS.SWP_NOOWNERZORDER | |
| ); | |
| if (!posSet) | |
| { | |
| // TODO: Add logging here if a logger is available, e.g. ManagedCommon.Logger.LogWarning(...) | |
| } | |
| return wasSet && posSet; |
mirmirmirr
pushed a commit
to mirmirmirr/PowerToys
that referenced
this pull request
Nov 9, 2025
…changes (microsoft#42405) ## Summary of the Pull Request This PR resolves the issue where the window style WS_EX_TOOLWINDOW was being set but not properly applied to the window. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [x] Closes: microsoft#42395 - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed
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 resolves the issue where the window style WS_EX_TOOLWINDOW was being set but not properly applied to the window.
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed