I’m not aware of a crate for it, but the code (using windows-sys
in this case) is not too complicated:
use std::{os::windows::prelude::OsStrExt, iter::once, ptr::null};
use windows_sys::Win32::{UI::WindowsAndMessaging::{FindWindowW, GetWindowRect}, Foundation::{HWND, RECT}};
fn main() {
let name_or_id = std::env::args_os().nth(1).unwrap();
let id: HWND = match name_or_id.to_str().and_then(|s| s.parse().ok()) {
Some(id) => id,
None => {
let name: Vec<u16> = name_or_id.as_os_str().encode_wide().chain(once(0)).collect();
unsafe { FindWindowW(null(), name.as_ptr()) }
}
};
let mut rect = RECT { left: 0, top: 0, right: 0, bottom: 0 };
if id != 0 && unsafe { GetWindowRect(id, &mut rect) } != 0 {
println!("{} {} {}", id, rect.right - rect.left, rect.bottom - rect.top);
}
}
I've done Windows Rust development on an Azure Windows Server, but I know that would be a bit inconvenient. You should be able to cross-compile to x86_64-pc-windows-gnu
from Linux to at least see if the code builds:
rustup target add x86_64-pc-windows-gnu
cargo build -v --target x86_64-pc-windows-gnu