Update to windows-sys 0.59 (#4098)
This commit is contained in:
parent
3a39a6ddb0
commit
23011c6b0a
17 changed files with 166 additions and 137 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use std::ffi::c_void;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use std::{fmt, io, mem};
|
||||
use std::{fmt, io, mem, ptr};
|
||||
|
||||
use cursor_icon::CursorIcon;
|
||||
use windows_sys::core::PCWSTR;
|
||||
|
|
@ -40,7 +40,7 @@ impl RgbaIcon {
|
|||
assert_eq!(and_mask.len(), pixel_count);
|
||||
let handle = unsafe {
|
||||
CreateIcon(
|
||||
0,
|
||||
ptr::null_mut(),
|
||||
self.width as i32,
|
||||
self.height as i32,
|
||||
1,
|
||||
|
|
@ -49,7 +49,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()))
|
||||
|
|
@ -68,6 +68,9 @@ struct RaiiIcon {
|
|||
handle: HICON,
|
||||
}
|
||||
|
||||
unsafe impl Send for RaiiIcon {}
|
||||
unsafe impl Sync for RaiiIcon {}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
pub struct WinIcon {
|
||||
inner: Arc<RaiiIcon>,
|
||||
|
|
@ -91,7 +94,7 @@ impl WinIcon {
|
|||
|
||||
let handle = unsafe {
|
||||
LoadImageW(
|
||||
0,
|
||||
ptr::null_mut(),
|
||||
wide_path.as_ptr(),
|
||||
IMAGE_ICON,
|
||||
width,
|
||||
|
|
@ -99,7 +102,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()))
|
||||
|
|
@ -122,7 +125,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()))
|
||||
|
|
@ -136,7 +139,7 @@ impl WinIcon {
|
|||
|
||||
pub fn set_for_window(&self, hwnd: HWND, icon_type: IconType) {
|
||||
unsafe {
|
||||
SendMessageW(hwnd, WM_SETICON, icon_type as usize, self.as_raw_handle());
|
||||
SendMessageW(hwnd, WM_SETICON, icon_type as usize, self.as_raw_handle() as isize);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -187,13 +190,13 @@ impl WinCursor {
|
|||
let h = image.height as i32;
|
||||
|
||||
unsafe {
|
||||
let hdc_screen = GetDC(0);
|
||||
if hdc_screen == 0 {
|
||||
let hdc_screen = GetDC(ptr::null_mut());
|
||||
if hdc_screen.is_null() {
|
||||
return Err(os_error!(io::Error::last_os_error()).into());
|
||||
}
|
||||
let hbm_color = CreateCompatibleBitmap(hdc_screen, w, h);
|
||||
ReleaseDC(0, hdc_screen);
|
||||
if hbm_color == 0 {
|
||||
ReleaseDC(ptr::null_mut(), hdc_screen);
|
||||
if hbm_color.is_null() {
|
||||
return Err(os_error!(io::Error::last_os_error()).into());
|
||||
}
|
||||
if SetBitmapBits(hbm_color, bgra.len() as u32, bgra.as_ptr() as *const c_void) == 0 {
|
||||
|
|
@ -204,7 +207,7 @@ impl WinCursor {
|
|||
// Mask created according to https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createbitmap#parameters
|
||||
let mask_bits: Vec<u8> = vec![0xff; ((((w + 15) >> 4) << 1) * h) as usize];
|
||||
let hbm_mask = CreateBitmap(w, h, 1, 1, mask_bits.as_ptr() as *const _);
|
||||
if hbm_mask == 0 {
|
||||
if hbm_mask.is_null() {
|
||||
DeleteObject(hbm_color);
|
||||
return Err(os_error!(io::Error::last_os_error()).into());
|
||||
}
|
||||
|
|
@ -220,7 +223,7 @@ impl WinCursor {
|
|||
let handle = CreateIconIndirect(&icon_info as *const _);
|
||||
DeleteObject(hbm_color);
|
||||
DeleteObject(hbm_mask);
|
||||
if handle == 0 {
|
||||
if handle.is_null() {
|
||||
return Err(os_error!(io::Error::last_os_error()).into());
|
||||
}
|
||||
|
||||
|
|
@ -234,6 +237,9 @@ pub struct RaiiCursor {
|
|||
handle: HCURSOR,
|
||||
}
|
||||
|
||||
unsafe impl Send for RaiiCursor {}
|
||||
unsafe impl Sync for RaiiCursor {}
|
||||
|
||||
impl Drop for RaiiCursor {
|
||||
fn drop(&mut self) {
|
||||
unsafe { DestroyCursor(self.handle) };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue