use winapi::um::winuser::{EnumWindows, };
use winapi::shared::windef::HWND;
use winapi::shared::minwindef::LPARAM;
use winvd::helpers::get_desktop_number_by_window;
use winvd::Error;
#[derive(Debug)]
pub struct Window {
hwnd: HWND,
}
impl Window {
pub fn init(hwnd: HWND) -> Window {
Window {
hwnd,
}
}
pub fn desktop_number(&self) -> Result<usize, Error> {
get_desktop_number_by_window(self.hwnd as u32)
}
pub fn hwnd(&self) -> HWND {
self.hwnd
}
}
pub fn get_all_windows() -> Result<Vec<Window>, &'static str> {
let mut windows = Vec::<Window>::new();
let result = unsafe {
EnumWindows(Some(_get_all_windows_callback), &mut windows as *mut _ as LPARAM)
};
if result == 0 {
return Err("Could not get a list of all active windows");
}
Ok(windows)
}
unsafe extern "system" fn _get_all_windows_callback(hwnd: HWND, vec_pointer: LPARAM) -> i32 {
let windows = vec_pointer as *mut Vec<Window>;
windows.as_mut().unwrap().push(Window::init(hwnd));
1
}