1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
use super::{
InstanceHandle,
bitmap::BitmapHandle,
};
use core::{
mem::{
transmute,
transmute_copy,
size_of,
},
ptr::{
null_mut,
NonNull
},
};
use winapi::{
shared::windef::HICON,
um::{
winuser::{
ICONINFO,
CopyIcon,
CreateIcon,
CreateIconFromResource,
CreateIconFromResourceEx,
CreateIconIndirect,
}
}
};
#[derive(Clone,Copy)]
#[repr(transparent)]
pub struct IconHandle{
inner:NonNull<HICON>,
}
implement_handle_wrapper!(IconHandle,HICON);
pub struct Icon;
impl Icon{
pub const fn new()->Icon{
Self
}
}
impl Icon{
/// Creates an icon that has the specified size, colors, and bit patterns.
///
/// `planes` - The number of planes in the XOR bitmask of the icon.
///
/// `pixel_bits` - The number of bits-per-pixel in the XOR bitmask of the icon.
///
/// `and_plane` - An array of bytes that contains the bit values for the AND bitmask of the icon.
/// This bitmask describes a monochrome bitmap.
///
/// `xor_plane` - An array of bytes that contains the bit values for the XOR bitmask of the icon.
/// This bitmask describes a monochrome or device-dependent color bitmap.
///
/// The nWidth and nHeight parameters must specify a width and height supported by the current display driver,
/// because the system cannot create icons of other sizes.
/// To determine the width and height supported by the display driver,
/// use the `GetSystemMetrics` function, specifying the `SM_CXICON` or `SM_CYICON` value.
///
/// CreateIcon applies the following truth table to the AND and XOR bitmasks.
///
/// AND bitmask | XOR bitmask | Display
/// 0 | 0 | Black
/// 0 | 1 | White
/// 1 | 0 | Screen
/// 1 | 1 | Reverse screen
///
/// When you are finished using the icon, destroy it using the `Icon::destroy` function.
///
/// If the function succeeds, the return value is a handle to an icon.
///
/// If the function fails, the return value is `None`. To get extended error information, call `WinCore::get_last_error`.
pub fn create(
&self,
instance:Option<InstanceHandle>,
[width,height]:[i32;2],
planes:u8,
pixel_bits:u8,
and_plane:*const u8,
xor_plane:*const u8,
)->Option<IconHandle>{
unsafe{
IconHandle::from_raw(
CreateIcon(
InstanceHandle::to_raw(instance),
width,height,
planes,
pixel_bits,
transmute(and_plane),
transmute(xor_plane),
)
)
}
}
// pub fn create_from_resource(
// &self,
// instance:Option<InstanceHandle>,
// [width,height]:[i32;2],
// planes:u8,
// pixel_bits:u8,
// and_plane:*const u8,
// xor_plane:*const u8,
// )->Option<IconHandle>{
// unsafe{
// IconHandle::from_raw(
// CreateIconFromResource(
// InstanceHandle::to_raw(instance),
// width,height,
// planes,
// pixel_bits,
// transmute(and_plane),
// transmute(xor_plane),
// )
// )
// }
// }
/// Creates an icon.
pub fn create_indirect(
&self,
mask:BitmapHandle,
colour:BitmapHandle,
)->Option<IconHandle>{
unsafe{
let mut icon_info=ICONINFO{
fIcon:0,
xHotspot:0,
yHotspot:0,
hbmMask:mask.as_raw(),
hbmColor:colour.as_raw()
};
IconHandle::from_raw(CreateIconIndirect(&mut icon_info))
}
}
/// Copies the specified icon from another module to the current module.
///
/// The CopyIcon function enables an application or DLL to get its own handle to an icon owned by another module.
/// If the other module is freed, the application icon will still be able to use the icon.
///
/// Before closing, an application must call the `Icon::destroy` function to free any system resources associated with the icon.
///
/// If the function succeeds, the return value is a handle to the duplicate icon.
///
/// If the function fails, the return value is `None`. To get extended error information, call `WinCore::get_last_error`.
pub fn copy(&self,icon:IconHandle)->Option<IconHandle>{
unsafe{
IconHandle::from_raw(CopyIcon(icon.as_raw()))
}
}
}