Skip to content

Fix close and destroy of modal dialog#1

Merged
iamAbhi-916 merged 1 commit into
iamAbhi-916:masterfrom
sundaramramaswamy:master
Nov 18, 2025
Merged

Fix close and destroy of modal dialog#1
iamAbhi-916 merged 1 commit into
iamAbhi-916:masterfrom
sundaramramaswamy:master

Conversation

@sundaramramaswamy

Copy link
Copy Markdown

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

  1. [Optional] Island.Close
  2. Bridge.Hide
  3. AppWindow.Destroy
  4. 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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants