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
#![allow(non_camel_case_types, non_snake_case)]
use crate::co;
use crate::decl::*;
use crate::gdi::ffi;
use crate::guard::*;
use crate::kernel::privs::*;
use crate::prelude::*;
impl GdiObject for HRGN {}
impl HRGN {
/// [`CreateRectRgn`](https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createrectrgn)
/// function.
#[must_use]
pub fn CreateRectRgn(bounds: RECT) -> SysResult<DeleteObjectGuard<HRGN>> {
unsafe {
PtrRet(ffi::CreateRectRgn(bounds.left, bounds.top, bounds.right, bounds.bottom))
.to_invalidparm_handle()
.map(|h| DeleteObjectGuard::new(h))
}
}
/// [`CreateRectRgnIndirect`](https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createrectrgnindirect)
/// function.
#[must_use]
pub fn CreateRectRgnIndirect(rc: RECT) -> SysResult<DeleteObjectGuard<HRGN>> {
unsafe {
PtrRet(ffi::CreateRectRgnIndirect(pcvoid(&rc)))
.to_invalidparm_handle()
.map(|h| DeleteObjectGuard::new(h))
}
}
/// [`CreateRoundRectRgn`](https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createroundrectrgn)
/// function.
#[must_use]
pub fn CreateRoundRectRgn(bounds: RECT, size: SIZE) -> SysResult<DeleteObjectGuard<HRGN>> {
unsafe {
PtrRet(ffi::CreateRoundRectRgn(
bounds.left,
bounds.top,
bounds.right,
bounds.top,
size.cx,
size.cy,
))
.to_invalidparm_handle()
.map(|h| DeleteObjectGuard::new(h))
}
}
/// [`CombineRgn`](https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-combinergn)
/// function.
///
/// # Examples
///
/// Creating a clipping region with a square hole in it:
///
/// ```no_run
/// use winsafe::{self as w, prelude::*, co};
///
/// let hdc: w::HDC; // initialized somewhere
/// # let hdc = w::HDC::NULL;
///
/// let rc_hole = w::RECT { left: 0, top: 0, right: 100, bottom: 100 };
/// let hrgn_hole = w::HRGN::CreateRectRgnIndirect(rc_hole)?;
///
/// let hrgn_clip = w::HRGN::CreateRectRgnIndirect(
/// w::InflateRect(rc_hole, 10, 10)?,
/// )?;
/// hrgn_clip.CombineRgn(&hrgn_clip, &hrgn_hole, co::RGN::DIFF)?;
///
/// hdc.SelectClipRgn(&hrgn_clip)?;
/// # w::SysResult::Ok(())
/// ```
pub fn CombineRgn(&self, src1: &HRGN, src2: &HRGN, mode: co::RGN) -> SysResult<co::REGION> {
match unsafe { ffi::CombineRgn(self.ptr(), src1.ptr(), src2.ptr(), mode.raw()) } {
0 => Err(co::ERROR::INVALID_PARAMETER),
ret => Ok(unsafe { co::REGION::from_raw(ret) }),
}
}
/// [`EqualRgn`](https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-equalrgn)
/// function.
#[must_use]
pub fn EqualRgn(&self, other: &HRGN) -> bool {
unsafe { ffi::EqualRgn(self.ptr(), other.ptr()) != 0 }
}
/// [`OffsetClipRgn`](https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-offsetcliprgn)
/// function.
pub fn OffsetClipRgn(&self, x: i32, y: i32) -> SysResult<co::REGION> {
match unsafe { ffi::OffsetClipRgn(self.ptr(), x, y) } {
0 => Err(co::ERROR::INVALID_PARAMETER),
ret => Ok(unsafe { co::REGION::from_raw(ret) }),
}
}
/// [`OffsetRgn`](https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-offsetrgn)
/// function.
pub fn OffsetRgn(&self, x: i32, y: i32) -> SysResult<co::REGION> {
match unsafe { ffi::OffsetRgn(self.ptr(), x, y) } {
0 => Err(co::ERROR::INVALID_PARAMETER),
ret => Ok(unsafe { co::REGION::from_raw(ret) }),
}
}
/// [`PtInRegion`](https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-ptinregion)
/// function.
#[must_use]
pub fn PtInRegion(&self, x: i32, y: i32) -> bool {
unsafe { ffi::PtInRegion(self.ptr(), x, y) != 0 }
}
/// [`RectInRegion`](https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-rectinregion)
/// function.
#[must_use]
pub fn RectInRegion(&self, rc: RECT) -> bool {
unsafe { ffi::RectInRegion(self.ptr(), pcvoid(&rc)) != 0 }
}
}