Fix close and destroy of modal dialog#1
Merged
Conversation
ISSUE
Moving the parent window after dismissal of modal pop-up leads to a
crash in `DefWindowProc`.
FIX
AppWindow.Destroy not getting called and hence the parent window
wasn’t receiving input events consumed by the popup. The right order
of popup close/destroy is
0. [Optional] `Island.Close`
1. `Bridge.Hide`
2. `AppWindow.Destroy`
3. `Bridge.Close`
This is the reverse of the creation/show order.
CLEAN-UP
* Drop `EnableWindow` as it’s unneeded
+ This masked the underlying issue of not calling
`AppWindow.Destroy` by forcing the parent to receive inputs
without cleanly destroying the popup
+ This is automatically done by `AppWindow.Destroy`
* Call `init_apartment` first
+ Should be the very first call as it initializes COM internally
+ This should precede `MddBootstrapInitialize2` call as noted
* Call `SetForegroundWindow` both on show and close modal
+ Former with popup as arg while latter with parent window
+ This is needed for proper focus on respective windows
* `AppWindow` pointer needn’t be global
+ Can always be obtained from the `DesktopPopupSiteBridge`
+ `AppWindow` can never outlive `DesktopPopupSiteBridge`
+ No need to check for validity of `modalAppWindow` as it’d
always be true if we’ve a popup bridge
* Drop modal visibility state
+ It’s never separately handled
+ It can always be queried from the `AppWindow/Bridge`
* Show parent bridge as it wasn’t shown earlier
+ Set a colour for it to be visible
+ Use `MoveAndResize` to give it a non-trivial size
+ Call `Bridge.Show()`
* Call `UpdateWindow()` which usually follows a `ShowWindow()`
* Call `CloseModal()` in `WM_DESTROY` handler as it takes care of
checking for popup’s validity
This was referenced Nov 19, 2025
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.
ISSUE
Moving the parent window after dismissal of modal pop-up leads to a crash in
DefWindowProc.FIX
AppWindow.Destroy not getting called and hence the parent window wasn’t receiving input events consumed by the popup. The right order of popup close/destroy is
Island.CloseBridge.HideAppWindow.DestroyBridge.CloseThis is the reverse of the creation/show order.
CLEAN-UP
EnableWindowas it’s unneededAppWindow.Destroyby forcing the parent to receive inputs without cleanly destroying the popupAppWindow.Destroyinit_apartmentfirstMddBootstrapInitialize2call as notedSetForegroundWindowboth on show and close modalAppWindowpointer needn’t be globalDesktopPopupSiteBridgeAppWindowcan never outliveDesktopPopupSiteBridgemodalAppWindowas it’d always be true if we’ve a popup bridgeAppWindow/BridgeMoveAndResizeto give it a non-trivial sizeBridge.Show()UpdateWindow()which usually follows aShowWindow()CloseModal()inWM_DESTROYhandler as it takes care of checking for popup’s validity