pub struct HCLIPBOARD(/* private fields */);
user
only.Expand description
Handle to the clipboard.
This handle doesn’t exist natively, it’s just an abstraction to safely group the related clipboard operations.
Implementations§
Source§impl HCLIPBOARD
impl HCLIPBOARD
Sourcepub const unsafe fn from_ptr(p: *mut c_void) -> Self
pub const unsafe fn from_ptr(p: *mut c_void) -> Self
Constructs a new handle object by wrapping a pointer.
This method can be used as an escape hatch to interoperate with other libraries.
§Safety
Be sure the pointer has the correct type and isn’t owned by anyone else, otherwise you may cause memory access violations.
Sourcepub const unsafe fn raw_copy(&self) -> Self
pub const unsafe fn raw_copy(&self) -> Self
Returns a raw copy of the underlying handle pointer.
§Safety
As the name implies, raw_copy
returns a raw copy of the
handle, so closing one of the copies won’t close the others.
This means a handle can be used after it has been closed, what
can lead to errors and undefined behavior. Even worse: sometimes
Windows reuses handle values, so you can call a method on a
completely different handle type, what can be catastrophic.
However, in some cases the Windows API demands a copy of the
handle – raw_copy
is an escape hatch to fill this gap.
Sourcepub const unsafe fn as_mut(&mut self) -> &mut *mut c_void
pub const unsafe fn as_mut(&mut self) -> &mut *mut c_void
Returns a mutable reference to the underlying raw pointer.
This method can be used as an escape hatch to interoperate with other libraries.
§Safety
This method exposes the raw pointer used by raw Windows calls. It’s an opaque pointer to an internal Windows structure, and no dereferencings should be attempted.
Sourcepub const fn ptr(&self) -> *mut c_void
pub const fn ptr(&self) -> *mut c_void
Returns the underlying raw pointer.
This method exposes the raw pointer used by raw Windows calls. It’s an opaque pointer to an internal Windows structure, and no dereferencings should be attempted.
This method can be used as an escape hatch to interoperate with other libraries.
Source§impl HCLIPBOARD
impl HCLIPBOARD
Sourcepub fn EmptyClipboard(&self) -> SysResult<()>
pub fn EmptyClipboard(&self) -> SysResult<()>
EmptyClipboard
function.
Sourcepub fn GetClipboardData(&self, format: CF) -> SysResult<Vec<u8>>
pub fn GetClipboardData(&self, format: CF) -> SysResult<Vec<u8>>
GetClipboardData
function.
Calls HGLOBAL::GlobalSize
and
HGLOBAL::GlobalLock
internally to
retrieve a copy of the raw clipboard data.
Note that you should not trust the clipboard format – the binary data can be anything, despite what the format says. Be careful when parsing the binary into your desired format.
§Examples
use winsafe::{self as w, prelude::*, co};
let hclip = w::HWND::NULL.OpenClipboard()?;
let data = hclip.GetClipboardData(co::CF::TEXT)?;
Sourcepub fn GetClipboardSequenceNumber(&self) -> u32
pub fn GetClipboardSequenceNumber(&self) -> u32
GetClipboardSequenceNumber
function.
Sourcepub fn SetClipboardData(&self, format: CF, data: &[u8]) -> SysResult<()>
pub fn SetClipboardData(&self, format: CF, data: &[u8]) -> SysResult<()>
SetClipboardData
function.
Calls HGLOBAL::GlobalAlloc
and
HGLOBAL::GlobalLock
internally before
copying the data into the clipboard.
§Examples
use winsafe::{self as w, prelude::*, co};
let hclip = w::HWND::NULL.OpenClipboard()?;
let str_nullt = "foo"
.as_bytes()
.iter()
.map(|ch| *ch)
.chain(std::iter::once(0)) // null-terminated
.collect::<Vec<_>>();
hclip.SetClipboardData(co::CF::TEXT, &str_nullt)?;
Trait Implementations§
Source§impl Debug for HCLIPBOARD
impl Debug for HCLIPBOARD
Source§impl Display for HCLIPBOARD
impl Display for HCLIPBOARD
Source§impl Handle for HCLIPBOARD
impl Handle for HCLIPBOARD
Source§const NULL: Self
const NULL: Self
kernel
only.0
.Source§const INVALID: Self
const INVALID: Self
kernel
only.-1
. Read moreSource§unsafe fn from_ptr(p: *mut c_void) -> Self
unsafe fn from_ptr(p: *mut c_void) -> Self
kernel
only.Source§unsafe fn raw_copy(&self) -> Self
unsafe fn raw_copy(&self) -> Self
kernel
only.Source§unsafe fn as_mut(&mut self) -> &mut *mut c_void
unsafe fn as_mut(&mut self) -> &mut *mut c_void
kernel
only.