Skip to content

Commit

Permalink
Sample: show visible windows and include coordinates (#2284)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessemcdowell committed Jan 16, 2023
1 parent f5373bb commit 50b241e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions crates/samples/windows/enum_windows/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use windows::{
Win32::Foundation::{BOOL, HWND, LPARAM},
Win32::UI::WindowsAndMessaging::{EnumWindows, GetWindowTextW},
Win32::UI::WindowsAndMessaging::{
EnumWindows, GetWindowInfo, GetWindowTextW, WINDOWINFO, WS_VISIBLE,
},
};

fn main() -> windows::core::Result<()> {
Expand All @@ -13,8 +15,14 @@ extern "system" fn enum_window(window: HWND, _: LPARAM) -> BOOL {
let len = GetWindowTextW(window, &mut text);
let text = String::from_utf16_lossy(&text[..len as usize]);

if !text.is_empty() {
println!("{text}");
let mut info = WINDOWINFO {
cbSize: core::mem::size_of::<WINDOWINFO>() as u32,
..Default::default()
};
GetWindowInfo(window, &mut info).unwrap();

if !text.is_empty() && info.dwStyle & WS_VISIBLE.0 != 0 {
println!("{} ({}, {})", text, info.rcWindow.left, info.rcWindow.top);
}

true.into()
Expand Down

0 comments on commit 50b241e

Please sign in to comment.