pub mod cursor;
pub mod h_instance;
mod rect;
pub mod uuid;
pub mod window;
pub use rect::Rect;
use std::ptr::null_mut;
use windows_core::{Error, Result, HRESULT};
use windows_sys::Win32::Foundation::{S_FALSE, S_OK};
use windows_sys::Win32::System::Ole::OleInitialize;
use windows_sys::Win32::UI::HiDpi::{
SetProcessDpiAwarenessContext, DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE,
};
use windows_sys::Win32::UI::WindowsAndMessaging::{
DispatchMessageW, GetMessageW, TranslateMessage, MSG,
};
pub fn ole_initialize() -> Result<()> {
match unsafe { OleInitialize(null_mut()) } {
S_OK | S_FALSE => Ok(()),
result => Err(Error::new(HRESULT(result), "OLE initialization failed")),
}
}
pub fn run_thread_message_loop_until(until: impl Fn() -> bool) -> Result<()> {
let mut msg = MSG::default();
loop {
let result = unsafe { GetMessageW(&mut msg, null_mut(), 0, 0) };
match result {
-1 => return Err(Error::from_win32()), 0 => return Ok(()), _ => {} }
let _ = unsafe { TranslateMessage(&msg) };
unsafe { DispatchMessageW(&msg) };
if until() {
return Ok(());
}
}
}
pub fn set_process_per_monitor_dpi_aware() {
unsafe { SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE) };
}