fix(windows): draw menubar for window after changes

This commit is contained in:
amrbashir 2022-06-07 18:53:42 +02:00
parent 0201895d74
commit 6f1c8cc9c9
No known key found for this signature in database
GPG key ID: BBD7A47A2003FF33

View file

@ -11,9 +11,10 @@ use windows_sys::Win32::{
UI::{ UI::{
Shell::{DefSubclassProc, RemoveWindowSubclass, SetWindowSubclass}, Shell::{DefSubclassProc, RemoveWindowSubclass, SetWindowSubclass},
WindowsAndMessaging::{ WindowsAndMessaging::{
AppendMenuW, CreateAcceleratorTableW, CreateMenu, EnableMenuItem, GetMenuItemInfoW, AppendMenuW, CreateAcceleratorTableW, CreateMenu, DrawMenuBar, EnableMenuItem,
SetMenu, SetMenuItemInfoW, ACCEL, HACCEL, HMENU, MENUITEMINFOW, MFS_DISABLED, GetMenuItemInfoW, SetMenu, SetMenuItemInfoW, ACCEL, HACCEL, HMENU, MENUITEMINFOW,
MF_DISABLED, MF_ENABLED, MF_GRAYED, MF_POPUP, MIIM_STATE, MIIM_STRING, WM_COMMAND, MFS_DISABLED, MF_DISABLED, MF_ENABLED, MF_GRAYED, MF_POPUP, MIIM_STATE, MIIM_STRING,
WM_COMMAND,
}, },
}, },
}; };
@ -66,6 +67,7 @@ impl Menu {
unsafe { unsafe {
SetMenu(hwnd, self.0.borrow().hmenu); SetMenu(hwnd, self.0.borrow().hmenu);
SetWindowSubclass(hwnd, Some(menu_subclass_proc), MENU_SUBCLASS_ID, 0); SetWindowSubclass(hwnd, Some(menu_subclass_proc), MENU_SUBCLASS_ID, 0);
DrawMenuBar(hwnd);
}; };
} }
@ -84,18 +86,21 @@ impl Menu {
unsafe { unsafe {
RemoveWindowSubclass(hwnd, Some(menu_subclass_proc), MENU_SUBCLASS_ID); RemoveWindowSubclass(hwnd, Some(menu_subclass_proc), MENU_SUBCLASS_ID);
SetMenu(hwnd, 0); SetMenu(hwnd, 0);
DrawMenuBar(hwnd);
} }
} }
pub fn hide_for_hwnd(&self, hwnd: isize) { pub fn hide_for_hwnd(&self, hwnd: isize) {
unsafe { unsafe {
SetMenu(hwnd, 0); SetMenu(hwnd, 0);
DrawMenuBar(hwnd);
} }
} }
pub fn show_for_hwnd(&self, hwnd: isize) { pub fn show_for_hwnd(&self, hwnd: isize) {
unsafe { unsafe {
SetMenu(hwnd, self.0.borrow().hmenu); SetMenu(hwnd, self.0.borrow().hmenu);
DrawMenuBar(hwnd);
} }
} }
} }