Replies: 3 comments 6 replies
-
You can use SetWindowSubclass and WM_CLOSE :
Declarations :
In MainWindow constructor :
|
Beta Was this translation helpful? Give feedback.
-
I cannot reproduce this with Windows App SDK 1.1.0-preview1 on Windows 10 21H1 (packaged or unpackaged) |
Beta Was this translation helpful? Give feedback.
-
@castorix Thank you for your kind feedback.
I finally found a way. I found that AppWindow provides Closing events The Closing event worked well and solved my current problem. Anyway, in Windows App SDK 1.0.2 or 1.1.0-preview1, |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
WinUI 3 does not yet support window close event.
If you are developing an 'editing program' with WinUI 3, you should see a dialog asking if you want to save your edits before closing the window.
This should be implemented via the Closing event, but is currently not available in WinUI 3.
If I want to create a close event I need to intercept the window message and handle the close event to listen for the window close event.
Ok, so I implemented this using the win32 API. The package I used to do this is cswin32.
The following source code only intercepts window messages and does not process anything. So I think it should work normally, but it doesn't.
| Register WNDPROC to intercept
| WNDPROC func
If you have experience implementing relevant features, please let me know what the problem is.
It doesn't seem to happen with Packaged.
But in Unpackaged, the program exits with an exception.

ExecutionEngineException is thrown and it seems to be due to the way Windows App SDK handles Unpackaged, but I can't find the cause.
Below is the reproducible source code.
https://github.com/dimohy/csharp-check/tree/main/WinUI3/WinUI3UnpackagedWinProcTest
Beta Was this translation helpful? Give feedback.
All reactions