diff --git a/.changes/windows-0.59.md b/.changes/windows-0.59.md new file mode 100644 index 00000000..c51a520f --- /dev/null +++ b/.changes/windows-0.59.md @@ -0,0 +1,5 @@ +--- +"muda": "patch" +--- + +Update `window-sys` crate to `0.59` diff --git a/Cargo.toml b/Cargo.toml index eeb1cda4..05a681c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ serde = { version = "1", optional = true } dpi = "0.1" [target."cfg(target_os = \"windows\")".dependencies.windows-sys] -version = "0.52" +version = "0.59" features = [ "Win32_UI_WindowsAndMessaging", "Win32_Foundation", @@ -45,7 +45,7 @@ gtk = "0.18" libxdo = { version = "0.6.0", optional = true } [target."cfg(target_os = \"macos\")".dependencies] -cocoa = "0.25" +cocoa = "0.26" objc = "0.2" png = "0.17" diff --git a/examples/tao.rs b/examples/tao.rs index cfef0663..22cfb4a6 100644 --- a/examples/tao.rs +++ b/examples/tao.rs @@ -33,7 +33,7 @@ fn main() { use windows_sys::Win32::UI::WindowsAndMessaging::{TranslateAcceleratorW, MSG}; unsafe { let msg = msg as *const MSG; - let translated = TranslateAcceleratorW((*msg).hwnd, menu_bar.haccel(), msg); + let translated = TranslateAcceleratorW((*msg).hwnd, menu_bar.haccel() as _, msg); translated == 1 } }); diff --git a/examples/windows-common-controls-v6/Cargo.toml b/examples/windows-common-controls-v6/Cargo.toml index 0e3fcfb8..f397c825 100644 --- a/examples/windows-common-controls-v6/Cargo.toml +++ b/examples/windows-common-controls-v6/Cargo.toml @@ -7,11 +7,11 @@ edition = "2021" [dependencies] muda = { path = "../../", features = ["common-controls-v6"] } -tao = "0.26" -image = "0.24" +tao = "0.28" +image = "0.25" [target."cfg(target_os = \"windows\")".dependencies.windows-sys] -version = "0.52" +version = "0.59" features = ["Win32_UI_WindowsAndMessaging", "Win32_Foundation"] [build-dependencies] diff --git a/examples/windows-common-controls-v6/src/main.rs b/examples/windows-common-controls-v6/src/main.rs index 872ac8b4..480746d8 100644 --- a/examples/windows-common-controls-v6/src/main.rs +++ b/examples/windows-common-controls-v6/src/main.rs @@ -31,7 +31,7 @@ fn main() { use windows_sys::Win32::UI::WindowsAndMessaging::{TranslateAcceleratorW, MSG}; unsafe { let msg = msg as *const MSG; - let translated = TranslateAcceleratorW((*msg).hwnd, menu_bar.haccel(), msg); + let translated = TranslateAcceleratorW((*msg).hwnd, menu_bar.haccel() as _, msg); translated == 1 } }); diff --git a/examples/winit.rs b/examples/winit.rs index 11a30892..9fb84b66 100644 --- a/examples/winit.rs +++ b/examples/winit.rs @@ -31,7 +31,7 @@ fn main() { use windows_sys::Win32::UI::WindowsAndMessaging::{TranslateAcceleratorW, MSG}; unsafe { let msg = msg as *const MSG; - let translated = TranslateAcceleratorW((*msg).hwnd, menu_bar.haccel(), msg); + let translated = TranslateAcceleratorW((*msg).hwnd, menu_bar.haccel() as _, msg); translated == 1 } }); diff --git a/examples/wry.rs b/examples/wry.rs index 6d213934..adab2e24 100644 --- a/examples/wry.rs +++ b/examples/wry.rs @@ -38,7 +38,7 @@ fn main() -> wry::Result<()> { use windows_sys::Win32::UI::WindowsAndMessaging::{TranslateAcceleratorW, MSG}; unsafe { let msg = msg as *const MSG; - let translated = TranslateAcceleratorW((*msg).hwnd, menu_bar.haccel(), msg); + let translated = TranslateAcceleratorW((*msg).hwnd, menu_bar.haccel() as _, msg); translated == 1 } }); diff --git a/src/items/submenu.rs b/src/items/submenu.rs index 6c3acc5b..55fc70ad 100644 --- a/src/items/submenu.rs +++ b/src/items/submenu.rs @@ -212,7 +212,7 @@ impl Submenu { impl ContextMenu for Submenu { #[cfg(target_os = "windows")] - fn hpopupmenu(&self) -> windows_sys::Win32::UI::WindowsAndMessaging::HMENU { + fn hpopupmenu(&self) -> isize { self.inner.borrow().hpopupmenu() } diff --git a/src/lib.rs b/src/lib.rs index fa522c69..75b8293e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -304,7 +304,7 @@ pub trait ContextMenu { /// /// [`HMENU`]: windows_sys::Win32::UI::WindowsAndMessaging::HMENU #[cfg(target_os = "windows")] - fn hpopupmenu(&self) -> windows_sys::Win32::UI::WindowsAndMessaging::HMENU; + fn hpopupmenu(&self) -> isize; /// Shows this menu as a context menu inside a win32 window. /// diff --git a/src/menu.rs b/src/menu.rs index 7e9c87c5..429b146f 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -209,8 +209,8 @@ impl Menu { /// let menu = Menu::new(); /// unsafe { /// let mut msg: MSG = std::mem::zeroed(); - /// while GetMessageW(&mut msg, 0, 0, 0) == 1 { - /// let translated = TranslateAcceleratorW(msg.hwnd, menu.haccel(), &msg as *const _); + /// while GetMessageW(&mut msg, std::ptr::null_mut(), 0, 0) == 1 { + /// let translated = TranslateAcceleratorW(msg.hwnd, menu.haccel() as _, &msg as *const _); /// if translated != 1{ /// TranslateMessage(&msg); /// DispatchMessageW(&msg); @@ -247,7 +247,7 @@ impl Menu { /// It can be used with [`TranslateAcceleratorW`](windows_sys::Win32::UI::WindowsAndMessaging::TranslateAcceleratorW) /// in the event loop to enable accelerators #[cfg(target_os = "windows")] - pub fn haccel(&self) -> windows_sys::Win32::UI::WindowsAndMessaging::HACCEL { + pub fn haccel(&self) -> isize { self.inner.borrow_mut().haccel() } @@ -336,7 +336,7 @@ impl Menu { impl ContextMenu for Menu { #[cfg(target_os = "windows")] - fn hpopupmenu(&self) -> windows_sys::Win32::UI::WindowsAndMessaging::HMENU { + fn hpopupmenu(&self) -> isize { self.inner.borrow().hpopupmenu() } diff --git a/src/platform_impl/windows/dark_menu_bar.rs b/src/platform_impl/windows/dark_menu_bar.rs index 685d82a0..ac105ada 100644 --- a/src/platform_impl/windows/dark_menu_bar.rs +++ b/src/platform_impl/windows/dark_menu_bar.rs @@ -10,7 +10,7 @@ use once_cell::sync::Lazy; use windows_sys::{ s, Win32::{ - Foundation::{HMODULE, HWND, LPARAM, RECT, WPARAM}, + Foundation::{HWND, LPARAM, RECT, WPARAM}, Graphics::Gdi::*, System::LibraryLoader::{GetProcAddress, LoadLibraryA}, UI::{ @@ -97,7 +97,7 @@ fn selected_background_brush() -> HBRUSH { } /// Draws a dark menu bar if needed and returns whether it draws it or not -pub fn draw(hwnd: HWND, msg: u32, _wparam: WPARAM, lparam: LPARAM) { +pub fn draw(hwnd: super::Hwnd, msg: u32, _wparam: WPARAM, lparam: LPARAM) { match msg { // draw over the annoying white line blow menubar // ref: https://github.com/notepad-plus-plus/notepad-plus-plus/pull/9985 @@ -106,16 +106,21 @@ pub fn draw(hwnd: HWND, msg: u32, _wparam: WPARAM, lparam: LPARAM) { cbSize: std::mem::size_of::() as _, ..unsafe { std::mem::zeroed() } }; - unsafe { GetMenuBarInfo(hwnd, OBJID_MENU, 0, &mut mbi) }; + unsafe { GetMenuBarInfo(hwnd as _, OBJID_MENU, 0, &mut mbi) }; let mut client_rc: RECT = unsafe { std::mem::zeroed() }; unsafe { - GetClientRect(hwnd, &mut client_rc); - MapWindowPoints(hwnd, 0, &mut client_rc as *mut _ as *mut _, 2); + GetClientRect(hwnd as _, &mut client_rc); + MapWindowPoints( + hwnd as _, + std::ptr::null_mut(), + &mut client_rc as *mut _ as *mut _, + 2, + ); }; let mut window_rc: RECT = unsafe { std::mem::zeroed() }; - unsafe { GetWindowRect(hwnd, &mut window_rc) }; + unsafe { GetWindowRect(hwnd as _, &mut window_rc) }; unsafe { OffsetRect(&mut client_rc, -window_rc.left, -window_rc.top) }; @@ -124,9 +129,9 @@ pub fn draw(hwnd: HWND, msg: u32, _wparam: WPARAM, lparam: LPARAM) { annoying_rc.top -= 1; unsafe { - let hdc = GetWindowDC(hwnd); + let hdc = GetWindowDC(hwnd as _); FillRect(hdc, &annoying_rc, background_brush()); - ReleaseDC(hwnd, hdc); + ReleaseDC(hwnd as _, hdc); } } @@ -140,10 +145,10 @@ pub fn draw(hwnd: HWND, msg: u32, _wparam: WPARAM, lparam: LPARAM) { cbSize: std::mem::size_of::() as _, ..unsafe { std::mem::zeroed() } }; - unsafe { GetMenuBarInfo(hwnd, OBJID_MENU, 0, &mut mbi) }; + unsafe { GetMenuBarInfo(hwnd as _, OBJID_MENU, 0, &mut mbi) }; let mut window_rc: RECT = unsafe { std::mem::zeroed() }; - unsafe { GetWindowRect(hwnd, &mut window_rc) }; + unsafe { GetWindowRect(hwnd as _, &mut window_rc) }; let mut rc = mbi.rcBar; // the rcBar is offset by the window rect @@ -244,11 +249,11 @@ pub fn draw(hwnd: HWND, msg: u32, _wparam: WPARAM, lparam: LPARAM) { }; } -pub fn should_use_dark_mode(hwnd: HWND) -> bool { - should_apps_use_dark_mode() && !is_high_contrast() && is_dark_mode_allowed_for_window(hwnd) +pub fn should_use_dark_mode(hwnd: super::Hwnd) -> bool { + should_apps_use_dark_mode() && !is_high_contrast() && is_dark_mode_allowed_for_window(hwnd as _) } -static HUXTHEME: Lazy = Lazy::new(|| unsafe { LoadLibraryA(s!("uxtheme.dll")) }); +static HUXTHEME: Lazy = Lazy::new(|| unsafe { LoadLibraryA(s!("uxtheme.dll")) as _ }); fn should_apps_use_dark_mode() -> bool { const UXTHEME_SHOULDAPPSUSEDARKMODE_ORDINAL: u16 = 132; @@ -259,7 +264,7 @@ fn should_apps_use_dark_mode() -> bool { } GetProcAddress( - *HUXTHEME, + (*HUXTHEME) as *mut _, UXTHEME_SHOULDAPPSUSEDARKMODE_ORDINAL as usize as *mut _, ) .map(|handle| std::mem::transmute(handle)) @@ -280,7 +285,7 @@ fn is_dark_mode_allowed_for_window(hwnd: HWND) -> bool { } GetProcAddress( - *HUXTHEME, + (*HUXTHEME) as *mut _, UXTHEME_ISDARKMODEALLOWEDFORWINDOW_ORDINAL as usize as *mut _, ) .map(|handle| std::mem::transmute(handle)) diff --git a/src/platform_impl/windows/icon.rs b/src/platform_impl/windows/icon.rs index e2e469c3..c1c32a22 100644 --- a/src/platform_impl/windows/icon.rs +++ b/src/platform_impl/windows/icon.rs @@ -45,7 +45,7 @@ impl RgbaIcon { assert_eq!(and_mask.len(), pixel_count); let handle = unsafe { CreateIcon( - 0, + std::ptr::null_mut(), self.width as i32, self.height as i32, 1, @@ -54,7 +54,7 @@ impl RgbaIcon { rgba.as_ptr(), ) }; - if handle != 0 { + if !handle.is_null() { Ok(WinIcon::from_handle(handle)) } else { Err(BadIcon::OsError(io::Error::last_os_error())) @@ -76,7 +76,7 @@ unsafe impl Send for WinIcon {} impl WinIcon { pub unsafe fn to_hbitmap(&self) -> HBITMAP { - let hdc = CreateCompatibleDC(0); + let hdc = CreateCompatibleDC(std::ptr::null_mut()); let rc = RECT { left: 0, @@ -93,11 +93,18 @@ impl WinIcon { bitmap_info.bmiHeader.biBitCount = 32; bitmap_info.bmiHeader.biCompression = BI_RGB as _; - let h_dc_bitmap = GetDC(0); + let h_dc_bitmap = GetDC(std::ptr::null_mut()); - let hbitmap = CreateDIBSection(h_dc_bitmap, &bitmap_info, DIB_RGB_COLORS, 0 as _, 0, 0); + let hbitmap = CreateDIBSection( + h_dc_bitmap, + &bitmap_info, + DIB_RGB_COLORS, + 0 as _, + std::ptr::null_mut(), + 0, + ); - ReleaseDC(0, h_dc_bitmap); + ReleaseDC(std::ptr::null_mut(), h_dc_bitmap); let h_bitmap_old = SelectObject(hdc, hbitmap); @@ -109,7 +116,7 @@ impl WinIcon { rc.right, rc.bottom, 0, - 0, + std::ptr::null_mut(), DI_NORMAL, ); @@ -126,6 +133,7 @@ impl WinIcon { fn from_handle(handle: HICON) -> Self { Self { + #[allow(clippy::arc_with_non_send_sync)] inner: Arc::new(RaiiIcon { handle }), } } @@ -141,7 +149,7 @@ impl WinIcon { let handle = unsafe { LoadImageW( - 0, + std::ptr::null_mut(), wide_path.as_ptr(), IMAGE_ICON, width as i32, @@ -149,7 +157,7 @@ impl WinIcon { LR_DEFAULTSIZE | LR_LOADFROMFILE, ) }; - if handle != 0 { + if !handle.is_null() { Ok(WinIcon::from_handle(handle as HICON)) } else { Err(BadIcon::OsError(io::Error::last_os_error())) @@ -172,7 +180,7 @@ impl WinIcon { LR_DEFAULTSIZE, ) }; - if handle != 0 { + if !handle.is_null() { Ok(WinIcon::from_handle(handle as HICON)) } else { Err(BadIcon::OsError(io::Error::last_os_error())) diff --git a/src/platform_impl/windows/mod.rs b/src/platform_impl/windows/mod.rs index 6ac0bf51..ee32388b 100644 --- a/src/platform_impl/windows/mod.rs +++ b/src/platform_impl/windows/mod.rs @@ -26,7 +26,7 @@ use std::{ }; use util::{decode_wide, encode_wide, Accel}; use windows_sys::Win32::{ - Foundation::{HWND, LPARAM, LRESULT, POINT, WPARAM}, + Foundation::{LPARAM, LRESULT, POINT, WPARAM}, Graphics::Gdi::{ClientToScreen, HBITMAP}, UI::{ Input::KeyboardAndMouse::{SendInput, INPUT, INPUT_KEYBOARD, KEYEVENTF_KEYUP, VK_CONTROL}, @@ -44,6 +44,8 @@ use windows_sys::Win32::{ }, }; +type Hwnd = isize; + static COUNTER: Counter = Counter::new_with_start(1000); macro_rules! inner_menu_child_and_flags { @@ -100,7 +102,7 @@ pub(crate) struct Menu { internal_id: u32, hmenu: HMENU, hpopupmenu: HMENU, - hwnds: HashMap, + hwnds: HashMap, haccel_store: Rc>, children: Vec>>, } @@ -138,8 +140,8 @@ impl Drop for Menu { unsafe { for hwnd in self.hwnds.keys() { - SetMenu(*hwnd, 0); - RemoveWindowSubclass(*hwnd, Some(menu_subclass_proc), MENU_SUBCLASS_ID); + SetMenu(*hwnd as _, std::ptr::null_mut()); + RemoveWindowSubclass(*hwnd as _, Some(menu_subclass_proc), MENU_SUBCLASS_ID); } DestroyMenu(self.hmenu); DestroyMenu(self.hpopupmenu); @@ -155,7 +157,7 @@ impl Menu { internal_id, hmenu: unsafe { CreateMenu() }, hpopupmenu: unsafe { CreatePopupMenu() }, - haccel_store: Rc::new(RefCell::new((0, HashMap::new()))), + haccel_store: Rc::new(RefCell::new((std::ptr::null_mut(), HashMap::new()))), children: Vec::new(), hwnds: HashMap::new(), } @@ -233,7 +235,7 @@ impl Menu { .icon .as_ref() .map(|i| unsafe { i.inner.to_hbitmap() }) - .unwrap_or(0); + .unwrap_or(std::ptr::null_mut()); let info = create_icon_item_info(hbitmap); unsafe { @@ -245,7 +247,7 @@ impl Menu { // redraw the menu bar for hwnd in self.hwnds.keys() { - unsafe { DrawMenuBar(*hwnd) }; + unsafe { DrawMenuBar(*hwnd as _) }; } { @@ -272,7 +274,7 @@ impl Menu { // redraw the menu bar for hwnd in self.hwnds.keys() { - DrawMenuBar(*hwnd); + DrawMenuBar(*hwnd as _); } } @@ -315,12 +317,12 @@ impl Menu { find_by_id(id, &self.children) } - pub fn haccel(&self) -> HACCEL { - self.haccel_store.borrow().0 + pub fn haccel(&self) -> isize { + self.haccel_store.borrow().0 as _ } - pub fn hpopupmenu(&self) -> HMENU { - self.hpopupmenu + pub fn hpopupmenu(&self) -> isize { + self.hpopupmenu as _ } pub fn init_for_hwnd_with_theme(&mut self, hwnd: isize, theme: MenuTheme) -> crate::Result<()> { @@ -331,14 +333,14 @@ impl Menu { self.hwnds.insert(hwnd, theme); unsafe { - SetMenu(hwnd, self.hmenu); + SetMenu(hwnd as _, self.hmenu); SetWindowSubclass( - hwnd, + hwnd as _, Some(menu_subclass_proc), MENU_SUBCLASS_ID, Box::into_raw(Box::new(self)) as _, ); - DrawMenuBar(hwnd); + DrawMenuBar(hwnd as _); }; Ok(()) @@ -353,8 +355,8 @@ impl Menu { .ok_or(crate::Error::NotInitialized)?; unsafe { - SetMenu(hwnd, 0); - DrawMenuBar(hwnd); + SetMenu(hwnd as _, std::ptr::null_mut()); + DrawMenuBar(hwnd as _); } Ok(()) @@ -363,7 +365,7 @@ impl Menu { pub fn attach_menu_subclass_for_hwnd(&self, hwnd: isize) { unsafe { SetWindowSubclass( - hwnd, + hwnd as _, Some(menu_subclass_proc), MENU_SUBCLASS_ID, Box::into_raw(Box::new(self)) as _, @@ -373,7 +375,7 @@ impl Menu { pub fn detach_menu_subclass_from_hwnd(&self, hwnd: isize) { unsafe { - RemoveWindowSubclass(hwnd, Some(menu_subclass_proc), MENU_SUBCLASS_ID); + RemoveWindowSubclass(hwnd as _, Some(menu_subclass_proc), MENU_SUBCLASS_ID); } } @@ -383,8 +385,8 @@ impl Menu { } unsafe { - SetMenu(hwnd, HMENU::default()); - DrawMenuBar(hwnd); + SetMenu(hwnd as _, std::ptr::null_mut()); + DrawMenuBar(hwnd as _); } Ok(()) @@ -396,8 +398,8 @@ impl Menu { } unsafe { - SetMenu(hwnd, self.hmenu); - DrawMenuBar(hwnd); + SetMenu(hwnd as _, self.hmenu); + DrawMenuBar(hwnd as _); } Ok(()) @@ -406,7 +408,7 @@ impl Menu { pub fn is_visible_on_hwnd(&self, hwnd: isize) -> bool { self.hwnds .get(&hwnd) - .map(|_| unsafe { GetMenu(hwnd) } != HMENU::default()) + .map(|_| !unsafe { GetMenu(hwnd as _) }.is_null()) .unwrap_or(false) } @@ -414,13 +416,13 @@ impl Menu { let hpopupmenu = self.hpopupmenu; unsafe { SetWindowSubclass( - hwnd, + hwnd as _, Some(menu_subclass_proc), CONTEXT_MENU_SUBCLASS_ID, Box::into_raw(Box::new(self)) as _, ); } - show_context_menu(hwnd, hpopupmenu, position) + show_context_menu(hwnd as _, hpopupmenu, position) } pub fn set_theme_for_hwnd(&self, hwnd: isize, theme: MenuTheme) -> crate::Result<()> { @@ -428,14 +430,14 @@ impl Menu { return Err(crate::Error::NotInitialized); } - unsafe { SendMessageW(hwnd, MENU_UPDATE_THEME, 0, theme as _) }; + unsafe { SendMessageW(hwnd as _, MENU_UPDATE_THEME, 0, theme as _) }; Ok(()) } } /// A generic child in a menu -#[derive(Debug, Default)] +#[derive(Debug)] pub(crate) struct MenuChild { // shared fields between submenus and menu items item_type: MenuItemType, @@ -503,8 +505,8 @@ impl MenuChild { icon: None, checked: false, children: None, - hmenu: 0, - hpopupmenu: 0, + hmenu: std::ptr::null_mut(), + hpopupmenu: std::ptr::null_mut(), } } @@ -543,8 +545,8 @@ impl MenuChild { icon: None, checked: false, children: None, - hmenu: 0, - hpopupmenu: 0, + hmenu: std::ptr::null_mut(), + hpopupmenu: std::ptr::null_mut(), } } @@ -569,8 +571,8 @@ impl MenuChild { predefined_item_type: None, icon: None, children: None, - hmenu: 0, - hpopupmenu: 0, + hmenu: std::ptr::null_mut(), + hpopupmenu: std::ptr::null_mut(), } } @@ -595,8 +597,8 @@ impl MenuChild { predefined_item_type: None, checked: false, children: None, - hmenu: 0, - hpopupmenu: 0, + hmenu: std::ptr::null_mut(), + hpopupmenu: std::ptr::null_mut(), } } @@ -621,8 +623,8 @@ impl MenuChild { icon: None, checked: false, children: None, - hmenu: 0, - hpopupmenu: 0, + hmenu: std::ptr::null_mut(), + hpopupmenu: std::ptr::null_mut(), } } } @@ -768,7 +770,9 @@ impl MenuChild { pub fn set_icon(&mut self, icon: Option) { self.icon.clone_from(&icon); - let hbitmap = icon.map(|i| unsafe { i.inner.to_hbitmap() }).unwrap_or(0); + let hbitmap = icon + .map(|i| unsafe { i.inner.to_hbitmap() }) + .unwrap_or(std::ptr::null_mut()); let info = create_icon_item_info(hbitmap); for parent in &self.parents_hemnu { unsafe { SetMenuItemInfoW(*parent, self.internal_id(), false.into(), &info) }; @@ -778,8 +782,8 @@ impl MenuChild { /// Submenu methods impl MenuChild { - pub fn hpopupmenu(&self) -> HMENU { - self.hpopupmenu + pub fn hpopupmenu(&self) -> isize { + self.hpopupmenu as _ } pub fn add_menu_item(&mut self, item: &dyn IsMenuItem, op: AddOp) -> crate::Result<()> { @@ -848,7 +852,7 @@ impl MenuChild { .icon .as_ref() .map(|i| unsafe { i.inner.to_hbitmap() }) - .unwrap_or(0); + .unwrap_or(std::ptr::null_mut()); let info = create_icon_item_info(hbitmap); unsafe { @@ -923,19 +927,19 @@ impl MenuChild { let hpopupmenu = self.hpopupmenu; unsafe { SetWindowSubclass( - hwnd, + hwnd as _, Some(menu_subclass_proc), CONTEXT_SUBMENU_SUBCLASS_ID, Box::into_raw(Box::new(self)) as _, ); } - show_context_menu(hwnd, hpopupmenu, position) + show_context_menu(hwnd as _, hpopupmenu, position) } pub fn attach_menu_subclass_for_hwnd(&self, hwnd: isize) { unsafe { SetWindowSubclass( - hwnd, + hwnd as _, Some(menu_subclass_proc), SUBMENU_SUBCLASS_ID, Box::into_raw(Box::new(self)) as _, @@ -945,7 +949,7 @@ impl MenuChild { pub fn detach_menu_subclass_from_hwnd(&self, hwnd: isize) { unsafe { - RemoveWindowSubclass(hwnd, Some(menu_subclass_proc), SUBMENU_SUBCLASS_ID); + RemoveWindowSubclass(hwnd as _, Some(menu_subclass_proc), SUBMENU_SUBCLASS_ID); } } } @@ -974,7 +978,11 @@ fn find_by_id(id: u32, children: &Vec>>) -> Option) { +fn show_context_menu( + hwnd: windows_sys::Win32::Foundation::HWND, + hmenu: HMENU, + position: Option, +) { unsafe { let pt = if let Some(pos) = position { let dpi = util::hwnd_dpi(hwnd); @@ -1040,7 +1048,7 @@ const CONTEXT_MENU_SUBCLASS_ID: usize = 203; const CONTEXT_SUBMENU_SUBCLASS_ID: usize = 204; unsafe extern "system" fn menu_subclass_proc( - hwnd: HWND, + hwnd: windows_sys::Win32::Foundation::HWND, msg: u32, wparam: WPARAM, lparam: LPARAM, @@ -1051,7 +1059,7 @@ unsafe extern "system" fn menu_subclass_proc( MENU_UPDATE_THEME if uidsubclass == MENU_SUBCLASS_ID => { let menu = dwrefdata as *mut Box; let theme: MenuTheme = std::mem::transmute(wparam); - (*menu).hwnds.insert(hwnd, theme); + (*menu).hwnds.insert(hwnd as _, theme); 0 } @@ -1119,7 +1127,7 @@ unsafe extern "system" fn menu_subclass_proc( PostQuitMessage(0); } PredefinedMenuItemType::About(Some(ref metadata)) => { - show_about_dialog(hwnd, metadata) + show_about_dialog(hwnd as _, metadata) } _ => {} @@ -1138,35 +1146,43 @@ unsafe extern "system" fn menu_subclass_proc( 0 } else { - DefSubclassProc(hwnd, msg, wparam, lparam) + DefSubclassProc(hwnd as _, msg, wparam, lparam) } } WM_UAHDRAWMENUITEM | WM_UAHDRAWMENU if uidsubclass == MENU_SUBCLASS_ID => { let menu = dwrefdata as *mut Box; - let theme = (*menu).hwnds.get(&hwnd).copied().unwrap_or(MenuTheme::Auto); - if theme.should_use_dark(hwnd) { - dark_menu_bar::draw(hwnd, msg, wparam, lparam); + let theme = (*menu) + .hwnds + .get(&(hwnd as _)) + .copied() + .unwrap_or(MenuTheme::Auto); + if theme.should_use_dark(hwnd as _) { + dark_menu_bar::draw(hwnd as _, msg, wparam, lparam); 0 } else { - DefSubclassProc(hwnd, msg, wparam, lparam) + DefSubclassProc(hwnd as _, msg, wparam, lparam) } } WM_NCACTIVATE | WM_NCPAINT => { // DefSubclassProc needs to be called before calling the // custom dark menu redraw - let res = DefSubclassProc(hwnd, msg, wparam, lparam); + let res = DefSubclassProc(hwnd as _, msg, wparam, lparam); let menu = dwrefdata as *mut Box; - let theme = (*menu).hwnds.get(&hwnd).copied().unwrap_or(MenuTheme::Auto); - if theme.should_use_dark(hwnd) { - dark_menu_bar::draw(hwnd, msg, wparam, lparam); + let theme = (*menu) + .hwnds + .get(&(hwnd as _)) + .copied() + .unwrap_or(MenuTheme::Auto); + if theme.should_use_dark(hwnd as _) { + dark_menu_bar::draw(hwnd as _, msg, wparam, lparam); } res } - _ => DefSubclassProc(hwnd, msg, wparam, lparam), + _ => DefSubclassProc(hwnd as _, msg, wparam, lparam), } } @@ -1174,7 +1190,7 @@ impl MenuTheme { fn should_use_dark(&self, hwnd: isize) -> bool { match self { MenuTheme::Dark => true, - MenuTheme::Auto if dark_menu_bar::should_use_dark_mode(hwnd) => true, + MenuTheme::Auto if dark_menu_bar::should_use_dark_mode(hwnd as _) => true, _ => false, } } @@ -1217,7 +1233,7 @@ fn execute_edit_command(command: EditCommand) { } } -fn show_about_dialog(hwnd: HWND, metadata: &AboutMetadata) { +fn show_about_dialog(hwnd: Hwnd, metadata: &AboutMetadata) { use std::fmt::Write; let mut message = String::new(); @@ -1261,7 +1277,12 @@ fn show_about_dialog(hwnd: HWND, metadata: &AboutMetadata) { #[cfg(not(feature = "common-controls-v6"))] std::thread::spawn(move || unsafe { use windows_sys::Win32::UI::WindowsAndMessaging::{MessageBoxW, MB_ICONINFORMATION}; - MessageBoxW(hwnd, message.as_ptr(), title.as_ptr(), MB_ICONINFORMATION); + MessageBoxW( + hwnd as _, + message.as_ptr(), + title.as_ptr(), + MB_ICONINFORMATION, + ); }); #[cfg(feature = "common-controls-v6")] @@ -1274,7 +1295,7 @@ fn show_about_dialog(hwnd: HWND, metadata: &AboutMetadata) { std::thread::spawn(move || unsafe { let task_dialog_config = TASKDIALOGCONFIG { cbSize: core::mem::size_of::() as u32, - hwndParent: hwnd, + hwndParent: hwnd as _, dwFlags: TDF_ALLOW_DIALOG_CANCELLATION, pszWindowTitle: title.as_ptr(), pszContent: message.as_ptr(), @@ -1290,7 +1311,7 @@ fn show_about_dialog(hwnd: HWND, metadata: &AboutMetadata) { pRadioButtons: std::ptr::null(), cRadioButtons: 0, cxWidth: 0, - hInstance: 0, + hInstance: std::ptr::null_mut(), pfCallback: None, lpCallbackData: 0, nDefaultButton: 0, diff --git a/src/platform_impl/windows/util.rs b/src/platform_impl/windows/util.rs index e5191d49..08d5a7b3 100644 --- a/src/platform_impl/windows/util.rs +++ b/src/platform_impl/windows/util.rs @@ -89,7 +89,7 @@ fn get_function_impl(library: &str, function: &str) -> FARPROC { // Library names we will use are ASCII so we can use the A version to avoid string conversion. let module = unsafe { LoadLibraryW(library.as_ptr()) }; - if module == 0 { + if module.is_null() { return None; } @@ -136,7 +136,7 @@ pub unsafe fn hwnd_dpi(hwnd: HWND) -> u32 { } else if let Some(GetDpiForMonitor) = *GET_DPI_FOR_MONITOR { // We are on Windows 8.1 or later. let monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); - if monitor == 0 { + if monitor.is_null() { return BASE_DPI; } @@ -150,7 +150,7 @@ pub unsafe fn hwnd_dpi(hwnd: HWND) -> u32 { } } else { let hdc = GetDC(hwnd); - if hdc == 0 { + if hdc.is_null() { return BASE_DPI; }