Skip to content

Commit

Permalink
Fix(close) Do destroy window when closing notification
Browse files Browse the repository at this point in the history
  • Loading branch information
Guiguiprim committed Sep 28, 2023
1 parent 052ea49 commit 1083073
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ unsafe fn close_notification(hwnd: HWND) {
ShowWindow(hwnd, SW_HIDE);
CloseWindow(hwnd);

// We can NOT call `DestroyWindow` from this window
// Sending WM_CLOSE will by default make the windows call it on itself.
// Note WM_DESTROY should not be sent directly as it would create a leak
// see https://devblogs.microsoft.com/oldnewthing/20110926-00/?p=9553
SendMessageA(hwnd, WM_CLOSE, 0, 0);

if let Ok(mut active_noti) = ACTIVE_NOTIFICATIONS.lock() {
if let Some(index) = active_noti.iter().position(|e| *e == hwnd) {
active_noti.remove(index);
Expand Down Expand Up @@ -463,6 +469,7 @@ pub unsafe extern "system" fn window_proc(
w32wm::WM_DESTROY => {
let userdata = userdata as *mut WindowData;
drop(Box::from_raw(userdata));
println!("WM_DESTROY");

DefWindowProcW(hwnd, msg, wparam, lparam)
}
Expand Down

0 comments on commit 1083073

Please sign in to comment.