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
#![allow(non_camel_case_types, non_snake_case)]
use crate::co;
use crate::decl::*;
use crate::kernel::privs::*;
use crate::user::{callbacks, ffi};
handle! { HDC;
/// Handle to a
/// [device context](https://learn.microsoft.com/en-us/windows/win32/winprog/windows-data-types#hdc).
}
impl HDC {
/// [`DrawFocusRect`](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-drawfocusrect)
/// function.
pub fn DrawFocusRect(&self, rect: RECT) -> SysResult<()> {
BoolRet(unsafe { ffi::DrawFocusRect(self.ptr(), pcvoid(&rect)) }).to_sysresult()
}
/// [`DrawText`](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-drawtextw)
/// function.
pub fn DrawText(&self, text: &str, bounds: RECT, format: co::DT) -> SysResult<i32> {
let mut bounds = bounds;
let wtext = WString::from_str(text);
match unsafe {
ffi::DrawTextW(
self.ptr(),
wtext.as_ptr(),
wtext.str_len() as _,
pvoid(&mut bounds),
format.raw(),
)
} {
0 => Err(GetLastError()),
i => Ok(i),
}
}
/// [`DrawTextExW`](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-drawtextexw)
/// function.
pub fn DrawTextEx(
&self,
text: &str,
bounds: RECT,
format: co::DT,
dtp: Option<&DRAWTEXTPARAMS>,
) -> SysResult<i32> {
let mut bounds = bounds;
let wtext = WString::from_str(text);
match unsafe {
ffi::DrawTextExW(
self.ptr(),
wtext.as_ptr(),
wtext.str_len() as _,
pvoid(&mut bounds),
format.raw(),
pcvoid_or_null(dtp),
)
} {
0 => Err(GetLastError()),
i => Ok(i),
}
}
/// [`EnumDisplayMonitors`](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enumdisplaymonitors)
/// function.
///
/// # Examples
///
/// ```no_run
/// use winsafe::{self as w, prelude::*};
///
/// let hdc: w::HDC; // initialized somewhere
/// # let hdc = w::HDC::NULL;
///
/// hdc.EnumDisplayMonitors(
/// None,
/// |hmon: w::HMONITOR, hdc: w::HDC, rc: &w::RECT| -> bool {
/// println!("HMONITOR: {}, ", hmon);
/// true
/// },
/// )?;
/// # w::SysResult::Ok(())
/// ```
pub fn EnumDisplayMonitors<F>(&self, rc_clip: Option<RECT>, func: F) -> SysResult<()>
where
F: FnMut(HMONITOR, HDC, &RECT) -> bool,
{
BoolRet(unsafe {
ffi::EnumDisplayMonitors(
self.ptr(),
pcvoid_or_null(rc_clip.as_ref()),
callbacks::hdc_enum_display_monitors::<F> as _,
pcvoid(&func),
)
})
.to_sysresult()
}
/// [`ExcludeUpdateRgn`](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-excludeupdatergn)
/// function.
pub fn ExcludeUpdateRgn(&self, hwnd: &HWND) -> SysResult<co::REGION> {
match unsafe { ffi::ExcludeUpdateRgn(self.ptr(), hwnd.ptr()) } {
0 => Err(co::ERROR::INVALID_PARAMETER),
v => Ok(unsafe { co::REGION::from_raw(v) }),
}
}
/// [`FrameRect`](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-framerect)
/// function.
pub fn FrameRect(&self, rc: RECT, hbr: &HBRUSH) -> SysResult<()> {
BoolRet(unsafe { ffi::FrameRect(self.ptr(), pcvoid(&rc), hbr.ptr()) }).to_sysresult()
}
/// [`InvertRect`](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-invertrect)
/// function.
pub fn InvertRect(&self, rc: RECT) -> SysResult<()> {
BoolRet(unsafe { ffi::InvertRect(self.ptr(), pcvoid(&rc)) }).to_sysresult()
}
/// [`PaintDesktop`](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-paintdesktop)
/// function.
pub fn PaintDesktop(&self) -> SysResult<()> {
BoolRet(unsafe { ffi::PaintDesktop(self.ptr()) }).to_sysresult()
}
/// [`WindowFromDC`](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-windowfromdc)
/// function.
#[must_use]
pub fn WindowFromDC(&self) -> Option<HWND> {
PtrRet(unsafe { ffi::WindowFromDC(self.ptr()) }).to_opt_handle()
}
}