winsafe\uxtheme\handles/
htheme.rs

1#![allow(non_camel_case_types, non_snake_case)]
2
3use crate::co;
4use crate::decl::*;
5use crate::guard::*;
6use crate::kernel::privs::*;
7use crate::macros::*;
8use crate::ole::privs::*;
9use crate::prelude::*;
10use crate::uxtheme::ffi;
11
12handle! { HTHEME;
13	/// Handle to a
14	/// [theme](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/).
15}
16
17impl HTHEME {
18	/// [`DrawThemeBackground`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-drawthemebackground)
19	/// function.
20	pub fn DrawThemeBackground(
21		&self,
22		hdc: &HDC,
23		part_state: co::VS,
24		rc: RECT,
25		rc_clip: Option<RECT>,
26	) -> HrResult<()> {
27		HrRet(unsafe {
28			ffi::DrawThemeBackground(
29				self.ptr(),
30				hdc.ptr(),
31				part_state.part,
32				part_state.state,
33				pcvoid(&rc),
34				pcvoid_or_null(rc_clip.as_ref()),
35			)
36		})
37		.to_hrresult()
38	}
39
40	/// [`GetThemeAppProperties`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthemeappproperties)
41	/// function.
42	#[must_use]
43	pub fn GetThemeAppProperties() -> co::STAP {
44		unsafe { co::STAP::from_raw(ffi::GetThemeAppProperties()) }
45	}
46
47	/// [`GetThemeBackgroundContentRect`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthemebackgroundcontentrect)
48	/// function.
49	#[must_use]
50	pub fn GetThemeBackgroundContentRect(
51		&self,
52		hdc: &HDC,
53		part_state: co::VS,
54		bounds: RECT,
55	) -> HrResult<RECT> {
56		let mut rc_content = RECT::default();
57		HrRet(unsafe {
58			ffi::GetThemeBackgroundContentRect(
59				self.ptr(),
60				hdc.ptr(),
61				part_state.part,
62				part_state.state,
63				pcvoid(&bounds),
64				pvoid(&mut rc_content),
65			)
66		})
67		.to_hrresult()
68		.map(|_| rc_content)
69	}
70
71	/// [`GetThemeBackgroundExtent`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthemebackgroundextent)
72	/// function.
73	#[must_use]
74	pub fn GetThemeBackgroundExtent(
75		&self,
76		hdc: &HDC,
77		part_state: co::VS,
78		rc_content: RECT,
79	) -> HrResult<RECT> {
80		let mut rc_extent = RECT::default();
81
82		HrRet(unsafe {
83			ffi::GetThemeBackgroundExtent(
84				self.ptr(),
85				hdc.ptr(),
86				part_state.part,
87				part_state.state,
88				pcvoid(&rc_content),
89				pvoid(&mut rc_extent),
90			)
91		})
92		.to_hrresult()
93		.map(|_| rc_extent)
94	}
95
96	/// [`GetThemeBackgroundRegion`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthemebackgroundregion)
97	/// function.
98	#[must_use]
99	pub fn GetThemeBackgroundRegion(
100		&self,
101		hdc: &HDC,
102		part_state: co::VS,
103		rc: RECT,
104	) -> HrResult<DeleteObjectGuard<HRGN>> {
105		let mut hrgn = HRGN::NULL;
106		unsafe {
107			HrRet(ffi::GetThemeBackgroundRegion(
108				self.ptr(),
109				hdc.ptr(),
110				part_state.part,
111				part_state.state,
112				pcvoid(&rc),
113				hrgn.as_mut(),
114			))
115			.to_hrresult()
116			.map(|_| DeleteObjectGuard::new(hrgn))
117		}
118	}
119
120	/// [`GetThemeColor`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthemecolor)
121	/// function.
122	#[must_use]
123	pub fn GetThemeColor(&self, part_state: co::VS, prop: co::TMT) -> HrResult<COLORREF> {
124		let mut color = COLORREF::default();
125		HrRet(unsafe {
126			ffi::GetThemeColor(
127				self.ptr(),
128				part_state.part,
129				part_state.state,
130				prop.raw(),
131				color.as_mut(),
132			)
133		})
134		.to_hrresult()
135		.map(|_| color)
136	}
137
138	/// [`GetThemeMargins`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthememargins)
139	/// function.
140	#[must_use]
141	pub fn GetThemeMargins(
142		&self,
143		hdc_fonts: Option<&HDC>,
144		part_state: co::VS,
145		prop: co::TMT,
146		draw_dest: Option<&RECT>,
147	) -> HrResult<MARGINS> {
148		let mut margins = MARGINS::default();
149		HrRet(unsafe {
150			ffi::GetThemeMargins(
151				self.ptr(),
152				hdc_fonts.map_or(std::ptr::null_mut(), |h| h.ptr()),
153				part_state.part(),
154				part_state.state(),
155				prop.raw(),
156				pcvoid_or_null(draw_dest),
157				pvoid(&mut margins),
158			)
159		})
160		.to_hrresult()
161		.map(|_| margins)
162	}
163
164	/// [`GetThemeMetric`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthememetric)
165	/// function.
166	#[must_use]
167	pub fn GetThemeMetric(
168		&self,
169		hdc_fonts: Option<&HDC>,
170		part_state: co::VS,
171		prop: co::TMT,
172	) -> HrResult<i32> {
173		let mut val = 0i32;
174		HrRet(unsafe {
175			ffi::GetThemeMetric(
176				self.ptr(),
177				hdc_fonts.map_or(std::ptr::null_mut(), |h| h.ptr()),
178				part_state.part(),
179				part_state.state(),
180				prop.raw(),
181				&mut val,
182			)
183		})
184		.to_hrresult()
185		.map(|_| val)
186	}
187
188	/// [`GetThemePartSize`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthemepartsize)
189	/// function.
190	#[must_use]
191	pub fn GetThemePartSize(
192		&self,
193		hdc_fonts: Option<&HDC>,
194		part_state: co::VS,
195		draw_dest: Option<&RECT>,
196		esize: co::THEMESIZE,
197	) -> HrResult<SIZE> {
198		let mut sz = SIZE::default();
199		HrRet(unsafe {
200			ffi::GetThemePartSize(
201				self.ptr(),
202				hdc_fonts.map_or(std::ptr::null_mut(), |h| h.ptr()),
203				part_state.part(),
204				part_state.state(),
205				pcvoid_or_null(draw_dest),
206				esize.raw(),
207				pvoid(&mut sz),
208			)
209		})
210		.to_hrresult()
211		.map(|_| sz)
212	}
213
214	/// [`GetThemePosition`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthemeposition)
215	/// function.
216	#[must_use]
217	pub fn GetThemePosition(&self, part_state: co::VS, prop: co::TMT) -> HrResult<POINT> {
218		let mut pt = POINT::default();
219		HrRet(unsafe {
220			ffi::GetThemePosition(
221				self.ptr(),
222				part_state.part(),
223				part_state.state(),
224				prop.raw(),
225				pvoid(&mut pt),
226			)
227		})
228		.to_hrresult()
229		.map(|_| pt)
230	}
231
232	/// [`GetThemePropertyOrigin`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthemepropertyorigin)
233	/// function.
234	#[must_use]
235	pub fn GetThemePropertyOrigin(
236		&self,
237		part_state: co::VS,
238		prop: co::TMT,
239	) -> HrResult<co::PROPERTYORIGIN> {
240		let mut origin = co::PROPERTYORIGIN::default();
241		HrRet(unsafe {
242			ffi::GetThemePropertyOrigin(
243				self.ptr(),
244				part_state.part(),
245				part_state.state(),
246				prop.raw(),
247				origin.as_mut(),
248			)
249		})
250		.to_hrresult()
251		.map(|_| origin)
252	}
253
254	/// [`GetThemeRect`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthemerect)
255	/// function.
256	#[must_use]
257	pub fn GetThemeRect(&self, part_state: co::VS, prop: co::TMT) -> HrResult<RECT> {
258		let mut rc = RECT::default();
259		HrRet(unsafe {
260			ffi::GetThemeRect(
261				self.ptr(),
262				part_state.part(),
263				part_state.state(),
264				prop.raw(),
265				pvoid(&mut rc),
266			)
267		})
268		.to_hrresult()
269		.map(|_| rc)
270	}
271
272	/// [`IsThemeBackgroundPartiallyTransparent`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-isthemebackgroundpartiallytransparent)
273	/// function.
274	#[must_use]
275	pub fn IsThemeBackgroundPartiallyTransparent(&self, part_state: co::VS) -> bool {
276		unsafe {
277			ffi::IsThemeBackgroundPartiallyTransparent(
278				self.ptr(),
279				part_state.part,
280				part_state.state,
281			) != 0
282		}
283	}
284
285	/// [`IsThemePartDefined`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-isthemepartdefined)
286	/// function.
287	#[must_use]
288	pub fn IsThemePartDefined(&self, part_state: co::VS) -> bool {
289		unsafe { ffi::IsThemePartDefined(self.ptr(), part_state.part, part_state.state) != 0 }
290	}
291}