Skip to content

Commit

Permalink
update inspect-windows
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden committed Nov 5, 2023
1 parent e5d7817 commit c49784e
Showing 1 changed file with 24 additions and 28 deletions.
52 changes: 24 additions & 28 deletions tools/inspect-windows/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,12 @@ use windows::Win32::Foundation::{BOOL, HWND, LPARAM};
use windows::Win32::UI::WindowsAndMessaging::{EnumWindows, GetWindow, GW_OWNER};

fn main() -> Result<()> {
for window_info in collect_windows_info()? {
let WindowInfo {
hwnd,
title,
owner_hwnd,
owner_title,
size,
is_visible,
is_cloaked,
is_iconic,
is_topmost,
} = window_info;

let size = format!("{}x{}", size.0, size.1);

println!(
"visible:{}cloacked{}iconic{}topmost:{} {:>10} {:>10}:{} {}:{}",
pretty_bool(is_visible),
pretty_bool(is_cloaked),
pretty_bool(is_iconic),
pretty_bool(is_topmost),
size,
hwnd.0,
title,
owner_hwnd.0,
owner_title
);
}
let output = collect_windows_info()?
.iter()
.map(|v| v.stringify())
.collect::<Vec<String>>()
.join("\n");
println!("{output}");
Ok(())
}

Expand All @@ -49,6 +27,24 @@ struct WindowInfo {
is_topmost: bool,
}

impl WindowInfo {
pub fn stringify(&self) -> String {
let size = format!("{}x{}", self.size.0, self.size.1);
format!(
"visible:{}cloacked{}iconic{}topmost:{} {:>10} {:>10}:{} {}:{}",
pretty_bool(self.is_visible),
pretty_bool(self.is_cloaked),
pretty_bool(self.is_iconic),
pretty_bool(self.is_topmost),
size,
self.hwnd.0,
self.title,
self.owner_hwnd.0,
self.owner_title
)
}
}

fn collect_windows_info() -> anyhow::Result<Vec<WindowInfo>> {
let mut hwnds: Vec<HWND> = Default::default();
unsafe { EnumWindows(Some(enum_window), LPARAM(&mut hwnds as *mut _ as isize)) }
Expand Down

0 comments on commit c49784e

Please sign in to comment.