-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
acb1c91
commit 1cf0245
Showing
9 changed files
with
159 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use crate::*; | ||
use bytemuck::*; | ||
use std::fmt::{self, Debug, Formatter}; | ||
use std::marker::PhantomData; | ||
|
||
|
||
|
||
/// \[[docs.microsoft.com](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-loadiconw)\] | ||
/// HICON | ||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
#[derive(Default)] | ||
pub struct HIcon<'a>(usize, PhantomData<&'a ()>); | ||
|
||
impl HIcon<'_> { | ||
/// ### Safety | ||
/// * `hicon` must currently be valid or null | ||
/// * `hicon` must outlive `'_` | ||
pub unsafe fn from_unchecked(hicon: HICON) -> Self { Self(hicon as _, PhantomData) } | ||
} | ||
|
||
unsafe impl Zeroable for HIcon<'_> {} | ||
|
||
impl From<HIcon<'_>> for HICON { fn from(c: HIcon) -> Self { c.0 as _ } } | ||
impl From<()> for HIcon<'_> { fn from(_: ()) -> Self { Self(0, PhantomData) } } | ||
|
||
impl Debug for HIcon<'_> { fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { write!(fmt, "HIcon(0x{:X})", self.0) } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//! \[[docs.microsoft.com](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-loadicona)\] | ||
//! IDI_\* flags for [load_icon_w] | ||
#![allow(non_snake_case)] | ||
|
||
use crate::*; | ||
|
||
|
||
|
||
// XXX: is Atom sufficient typing? | ||
pub const APPLICATION : Atom = Atom(32512); | ||
pub const HAND : Atom = Atom(32513); | ||
pub const QUESTION : Atom = Atom(32514); | ||
pub const EXCLAMATION : Atom = Atom(32515); | ||
pub const ASTERISK : Atom = Atom(32516); | ||
pub const WINLOGO : Atom = Atom(32517); // WINVER >= 0x0400 | ||
pub const SHIELD : Atom = Atom(32518); // WINVER >= 0x0600 | ||
|
||
pub const WARNING : Atom = self::EXCLAMATION; // WINVER >= 0x0400 | ||
pub const ERROR : Atom = self::HAND; // WINVER >= 0x0400 | ||
pub const INFORMATION : Atom = self::ASTERISK; // WINVER >= 0x0400 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use crate::*; | ||
use winapi::um::winuser::*; | ||
|
||
|
||
|
||
/// \[[docs.microsoft.com](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-loadicona)\] | ||
/// LoadIconA | ||
/// | ||
/// Loads an icon, animated icon, or bitmap. | ||
/// | ||
/// ### Errors | ||
/// * [ERROR::RESOURCE_DATA_NOT_FOUND] if `icon_name` cannot be found for `Some(hinstance)` | ||
/// * ~~[ERROR::RESOURCE_NAME_NOT_FOUND]~~ never? (returned by [load_cursor_a]) | ||
/// * [ERROR::RESOURCE_TYPE_NOT_FOUND] if `icon_name` cannot be found for the system (e.g. `hinstance` is `None`) | ||
/// | ||
/// ### Example | ||
/// ```rust | ||
/// # use abistr::*; | ||
/// # use hwnd::*; | ||
/// # use winresult::*; | ||
/// let idi_error = load_icon_a(None, IDI::ERROR).unwrap(); | ||
/// | ||
/// let exe = get_module_handle_entry_exe().unwrap(); | ||
/// assert_eq!(ERROR::RESOURCE_TYPE_NOT_FOUND, load_icon_a(None, IDC::SIZE).unwrap_err(), "cursor-only atom to load_icon"); | ||
/// assert_eq!(ERROR::RESOURCE_TYPE_NOT_FOUND, load_icon_a(None, 42).unwrap_err(), "(None, 42)"); | ||
/// assert_eq!(ERROR::RESOURCE_DATA_NOT_FOUND, load_icon_a(exe, 42).unwrap_err(), "(exe, 42)"); | ||
/// assert_eq!(ERROR::RESOURCE_TYPE_NOT_FOUND, load_icon_a(None, cstr!("nonexistant")).unwrap_err(), "(None, \"nonexistant\")"); | ||
/// assert_eq!(ERROR::RESOURCE_DATA_NOT_FOUND, load_icon_a(exe, cstr!("nonexistant")).unwrap_err(), "(exe, \"nonexistant\")"); | ||
/// ``` | ||
/// | ||
/// ### See Also | ||
/// * [load_icon_w] — wide equivalent | ||
/// * [load_cursor_a] — cursor equivalent | ||
pub fn load_icon_a<'h, 't>(hinstance: impl Into<HInstance<'h>>, icon_name: impl Into<NameAtomOrZero<'t, u8>>) -> Result<HIcon<'h>, Error> { | ||
fn_context!(load_icon_a => LoadIconA); | ||
let hicon = unsafe { LoadIconA(hinstance.into().into(), icon_name.into().as_atom_or_cstr_ptr()) }; | ||
fn_succeeded!(!hicon.is_null())?; | ||
Ok(unsafe { HIcon::from_unchecked(hicon) }) | ||
} | ||
|
||
/// \[[docs.microsoft.com](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-loadiconw)\] | ||
/// LoadIconW | ||
/// | ||
/// Loads an icon, animated icon, or bitmap. | ||
/// | ||
/// ### Errors | ||
/// * [ERROR::RESOURCE_DATA_NOT_FOUND] if `icon_name` cannot be found for `Some(hinstance)` | ||
/// * ~~[ERROR::RESOURCE_NAME_NOT_FOUND]~~ never? (returned by [load_cursor_w]) | ||
/// * [ERROR::RESOURCE_TYPE_NOT_FOUND] if `icon_name` cannot be found for the system (e.g. `hinstance` is `None`) | ||
/// | ||
/// ### Example | ||
/// ```rust | ||
/// # use abistr::*; | ||
/// # use hwnd::*; | ||
/// # use winresult::*; | ||
/// let idi_error = load_icon_w(None, IDI::ERROR).unwrap(); | ||
/// | ||
/// let exe = get_module_handle_entry_exe().unwrap(); | ||
/// assert_eq!(ERROR::RESOURCE_TYPE_NOT_FOUND, load_icon_w(None, IDC::SIZE).unwrap_err(), "cursor-only atom to load_icon"); | ||
/// assert_eq!(ERROR::RESOURCE_TYPE_NOT_FOUND, load_icon_w(None, 42).unwrap_err(), "(None, 42)"); | ||
/// assert_eq!(ERROR::RESOURCE_DATA_NOT_FOUND, load_icon_w(exe, 42).unwrap_err(), "(exe, 42)"); | ||
/// assert_eq!(ERROR::RESOURCE_TYPE_NOT_FOUND, load_icon_w(None, cstr16!("nonexistant")).unwrap_err(), "(None, \"nonexistant\")"); | ||
/// assert_eq!(ERROR::RESOURCE_DATA_NOT_FOUND, load_icon_w(exe, cstr16!("nonexistant")).unwrap_err(), "(exe, \"nonexistant\")"); | ||
/// ``` | ||
/// | ||
/// ### See Also | ||
/// * [load_icon_a] — narrow equivalent | ||
/// * [load_cursor_w] — cursor equivalent | ||
pub fn load_icon_w<'h, 't>(hinstance: impl Into<HInstance<'h>>, icon_name: impl Into<NameAtomOrZero<'t, u16>>) -> Result<HIcon<'h>, Error> { | ||
fn_context!(load_icon_w => LoadIconW); | ||
let hicon = unsafe { LoadIconW(hinstance.into().into(), icon_name.into().as_atom_or_cstr_ptr()) }; | ||
fn_succeeded!(!hicon.is_null())?; | ||
Ok(unsafe { HIcon::from_unchecked(hicon) }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters