Skip to content

Commit

Permalink
LoadImage variable name parameter; fix #38.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigocfd committed Jun 22, 2022
1 parent 6ce4e82 commit 2fc72c5
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 30 deletions.
8 changes: 5 additions & 3 deletions src/gui/dlg_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::gui::runtime_error::RunResult;
use crate::kernel::decl::{ErrResult, HINSTANCE, IdStr};
use crate::msg::wm;
use crate::prelude::{GuiEvents, KernelHinstance, UserHinstance, UserHwnd};
use crate::user::decl::{HWND, PostQuitMessage};
use crate::user::decl::{HWND, IdOicStr, PostQuitMessage, SIZE};

struct Obj { // actual fields of DlgMain
dlg_base: DlgBase,
Expand Down Expand Up @@ -104,14 +104,16 @@ impl DlgMain {
if let Some(id) = self.0.icon_id {
self.hwnd().SendMessage(
wm::SetIcon {
hicon: hinst.LoadImageIcon(id, 16, 16, co::LR::DEFAULTCOLOR).unwrap(),
hicon: hinst.LoadImageIcon(
IdOicStr::Id(id), SIZE::new(16, 16), co::LR::DEFAULTCOLOR).unwrap(),
size: co::ICON_SZ::SMALL,
},
);

self.hwnd().SendMessage(
wm::SetIcon {
hicon: hinst.LoadImageIcon(id, 32, 32, co::LR::DEFAULTCOLOR).unwrap(),
hicon: hinst.LoadImageIcon(
IdOicStr::Id(id), SIZE::new(32, 32), co::LR::DEFAULTCOLOR).unwrap(),
size: co::ICON_SZ::BIG,
},
);
Expand Down
93 changes: 77 additions & 16 deletions src/user/co.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1309,10 +1309,9 @@ const_ordinary! { ICON_SZ: u8: "user";
BIG 1
}

const_ordinary! { IDC: isize: "user";
const_ordinary! { IDC: u32: "user";
/// [`HINSTANCE::LoadCursor`](crate::prelude::UserHinstance::LoadCursor)
/// `lpCursorName`
/// (`isize`).
/// `lpCursorName` (`u32`).
=>
=>
ARROW 32512
Expand All @@ -1333,9 +1332,9 @@ const_ordinary! { IDC: isize: "user";
PERSON 32672
}

const_ordinary! { IDI: isize: "user";
const_ordinary! { IDI: u32: "user";
/// [`HINSTANCE::LoadIcon`](crate::prelude::UserHinstance::LoadIcon)
/// `lpIconName` (`isize`).
/// `lpIconName` (`u32`).
=>
=>
APPLICATION 32512
Expand Down Expand Up @@ -1791,25 +1790,70 @@ const_ordinary! { OBJID: u32: "user";
SYSMENU 0xffff_ffff
}

const_ordinary! { OBM: u32: "user";
/// [`HINSTANCE::LoadImageBitmap`](crate::prelude::UserHinstance::LoadImageBitmap)
/// OEM image identifier (`u32`).
=>
=>
CLOSE 32754
UPARROW 32753
DNARROW 32752
RGARROW 32751
LFARROW 32750
REDUCE 32749
ZOOM 32748
RESTORE 32747
REDUCED 32746
ZOOMD 32745
RESTORED 32744
UPARROWD 32743
DNARROWD 32742
RGARROWD 32741
LFARROWD 32740
MNARROW 32739
COMBO 32738
UPARROWI 32737
DNARROWI 32736
RGARROWI 32735
LFARROWI 32734

OLD_CLOSE 32767
SIZE 32766
OLD_UPARROW 32765
OLD_DNARROW 32764
OLD_RGARROW 32763
OLD_LFARROW 32762
BTSIZE 32761
CHECK 32760
CHECKBOXES 32759
BTNCORNERS 32758
OLD_REDUCE 32757
OLD_ZOOM 32756
OLD_RESTORE 32755
}

const_ordinary! { OCR: u32: "user";
/// [`HINSTANCE::LoadImageCursor`](crate::prelude::UserHinstance::LoadImageCursor)
/// and
/// [`HCURSOR::SetSystemCursor`](crate::prelude::UserHcursor::SetSystemCursor)
/// `id` (`u32`).
/// OEM cursor identifier (`u32`).
=>
=>
APPSTARTING 32650
NORMAL 32512
CROSS 32515
HAND 32649
HELP 32651
IBEAM 32513
NO 32648
SIZEALL 32646
SIZENESW 32643
SIZENS 32645
WAIT 32514
CROSS 32515
UP 32516
SIZENWSE 32642
SIZENESW 32643
SIZEWE 32644
UP 32516
WAIT 32514
SIZENS 32645
SIZEALL 32646
WINLOGO 32517
NO 32648
HAND 32649
APPSTARTING 32650
HELP 32651
}

const_bitflag! { ODA: u32: "user";
Expand Down Expand Up @@ -1862,6 +1906,23 @@ const_ordinary! { ODT_C: u32: "user";
COMBOBOX ODT::COMBOBOX.0
}

const_ordinary! { OIC: u32: "user";
/// [`HINSTANCE::LoadImageIcon`](crate::prelude::UserHinstance::LoadImageIcon)
/// OEM icon identifier (`u32`).
=>
=>
SAMPLE 32512
HAND 32513
QUES 32514
BANG 32515
NOTE 32516
WINLOGO 32517
WARNING Self::BANG.0
ERROR Self::HAND.0
INFORMATION Self::NOTE.0
SHIELD 32518
}

const_bitflag! { PM: u32: "user";
/// [`PeekMessage`](crate::PeekMessage) `remove_msg` (`u32`).
=>
Expand Down
94 changes: 92 additions & 2 deletions src/user/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ impl IdIdcStr {
pub fn as_ptr(&self) -> *const u16 {
match self {
Self::Id(id) => MAKEINTRESOURCE(*id as _),
Self::Idc(idc) => MAKEINTRESOURCE(idc.0),
Self::Idc(idc) => MAKEINTRESOURCE(idc.0 as _),
Self::Str(ws) => unsafe { ws.as_ptr() },
}
}
Expand Down Expand Up @@ -300,7 +300,7 @@ impl IdIdiStr {
pub fn as_ptr(&self) -> *const u16 {
match self {
Self::Id(id) => MAKEINTRESOURCE(*id as _),
Self::Idi(idi) => MAKEINTRESOURCE(idi.0),
Self::Idi(idi) => MAKEINTRESOURCE(idi.0 as _),
Self::Str(ws) => unsafe { ws.as_ptr() },
}
}
Expand Down Expand Up @@ -341,6 +341,96 @@ impl IdMenu {
}
}

/// Variant parameter for:
///
/// * [`HINSTANCE::LoadImageBitmap`](crate::prelude::UserHinstance::LoadImageBitmap) `name`.
#[cfg_attr(docsrs, doc(cfg(feature = "user")))]
#[derive(Clone)]
pub enum IdObmStr {
/// A resource ID.
Id(u16),
/// A [`co::OBM`](crate::co::OBM) constant for an OEM bitmap.
Obm(co::OBM),
/// A resource string identifier or file path.
Str(WString),
}

impl IdObmStr {
#[must_use]
pub fn from_str(v: &str) -> Self {
Self::Str(WString::from_str(v))
}

#[must_use]
pub fn as_ptr(&self) -> *const u16 {
match self {
Self::Id(id) => MAKEINTRESOURCE(*id as _),
Self::Obm(obm) => MAKEINTRESOURCE(obm.0 as _),
Self::Str(ws) => unsafe { ws.as_ptr() },
}
}
}

/// Variant parameter for:
///
/// * [`HINSTANCE::LoadImageCursor`](crate::prelude::UserHinstance::LoadImageCursor) `name`.
#[cfg_attr(docsrs, doc(cfg(feature = "user")))]
#[derive(Clone)]
pub enum IdOcrStr {
/// A resource ID.
Id(u16),
/// A [`co::OCR`](crate::co::OCR) constant for an OEM cursor.
Ocr(co::OCR),
/// A resource string identifier or file path.
Str(WString),
}

impl IdOcrStr {
#[must_use]
pub fn from_str(v: &str) -> Self {
Self::Str(WString::from_str(v))
}

#[must_use]
pub fn as_ptr(&self) -> *const u16 {
match self {
Self::Id(id) => MAKEINTRESOURCE(*id as _),
Self::Ocr(ocr) => MAKEINTRESOURCE(ocr.0 as _),
Self::Str(ws) => unsafe { ws.as_ptr() },
}
}
}

/// Variant parameter for:
///
/// * [`HINSTANCE::LoadImageIcon`](crate::prelude::UserHinstance::LoadImageIcon) `name`.
#[cfg_attr(docsrs, doc(cfg(feature = "user")))]
#[derive(Clone)]
pub enum IdOicStr {
/// A resource ID.
Id(u16),
/// A [`co::OIC`](crate::co::OIC) constant for an OEM icon.
Oic(co::OIC),
/// A resource string identifier or file path.
Str(WString),
}

impl IdOicStr {
#[must_use]
pub fn from_str(v: &str) -> Self {
Self::Str(WString::from_str(v))
}

#[must_use]
pub fn as_ptr(&self) -> *const u16 {
match self {
Self::Id(id) => MAKEINTRESOURCE(*id as _),
Self::Oic(oic) => MAKEINTRESOURCE(oic.0 as _),
Self::Str(ws) => unsafe { ws.as_ptr() },
}
}
}

/// Variant parameter for:
///
/// * [`HMENU::CheckMenuItem`](crate::prelude::UserHmenu::CheckMenuItem) `uIDCheckItem`;
Expand Down
20 changes: 11 additions & 9 deletions src/user/handles/hinstance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::kernel::decl::{GetLastError, HINSTANCE, IdStr, WinResult, WString};
use crate::prelude::Handle;
use crate::user::decl::{
ATOM, DLGPROC, HACCEL, HBITMAP, HCURSOR, HICON, HMENU, HWND, IdIdcStr,
IdIdiStr, SIZE, WNDCLASSEX,
IdIdiStr, IdObmStr, IdOcrStr, IdOicStr, SIZE, WNDCLASSEX,
};

impl UserHinstance for HINSTANCE {}
Expand Down Expand Up @@ -149,11 +149,11 @@ pub trait UserHinstance: Handle {
/// method for [`HBITMAP`](crate::HBITMAP).
#[must_use]
fn LoadImageBitmap(self,
name: u16, sz: SIZE, load: co::LR) -> WinResult<HBITMAP>
name: IdObmStr, sz: SIZE, load: co::LR) -> WinResult<HBITMAP>
{
unsafe {
user::ffi::LoadImageW(
self.as_ptr(), name as _, 0, sz.cx, sz.cy, load.0,
self.as_ptr(), name.as_ptr(), 0, sz.cx, sz.cy, load.0,
).as_mut()
}.map(|ptr| HBITMAP(ptr))
.ok_or_else(|| GetLastError())
Expand All @@ -163,11 +163,12 @@ pub trait UserHinstance: Handle {
/// method for [`HCURSOR`](crate::HCURSOR).
#[must_use]
fn LoadImageCursor(self,
name: u16, cx: i32, cy: i32, load: co::LR) -> WinResult<HCURSOR>
name: IdOcrStr, sz: SIZE, load: co::LR) -> WinResult<HCURSOR>
{
unsafe {
user::ffi::LoadImageW(self.as_ptr(), name as _, 2, cx, cy, load.0)
.as_mut()
user::ffi::LoadImageW(
self.as_ptr(), name.as_ptr(), 2, sz.cx, sz.cy, load.0,
).as_mut()
}.map(|ptr| HCURSOR(ptr))
.ok_or_else(|| GetLastError())
}
Expand All @@ -176,11 +177,12 @@ pub trait UserHinstance: Handle {
/// method for [`HICON`](crate::HICON).
#[must_use]
fn LoadImageIcon(self,
name: u16, cx: i32, cy: i32, load: co::LR) -> WinResult<HICON>
name: IdOicStr, sz: SIZE, load: co::LR) -> WinResult<HICON>
{
unsafe {
user::ffi::LoadImageW(self.as_ptr(), name as _, 1, cx, cy, load.0)
.as_mut()
user::ffi::LoadImageW(
self.as_ptr(), name.as_ptr(), 1, sz.cx, sz.cy, load.0,
).as_mut()
}.map(|ptr| HICON(ptr))
.ok_or_else(|| GetLastError())
}
Expand Down

0 comments on commit 2fc72c5

Please sign in to comment.