-
Notifications
You must be signed in to change notification settings - Fork 497
/
main.rs
29 lines (23 loc) · 924 Bytes
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use windows::{
core::*, Win32::System::Com::*, Win32::UI::Accessibility::*, Win32::UI::WindowsAndMessaging::*,
UI::UIAutomation::*,
};
fn main() -> Result<()> {
unsafe {
CoInitializeEx(None, COINIT_MULTITHREADED).ok()?;
let window = FindWindowA(None, s!("Calculator"))?;
// Start with COM API
let automation: IUIAutomation = CoCreateInstance(&CUIAutomation, None, CLSCTX_ALL)?;
let element: IUIAutomationElement = automation.ElementFromHandle(window)?;
// Use COM API
let name = element.CurrentName()?;
println!("window name: {name}");
// Query for WinRT API (will fail on earlier versions of Windows)
let element: Result<AutomationElement> = element.cast();
if let Ok(element) = element {
// Use WinRT API
println!("file name: {}", element.ExecutableFileName()?);
}
}
Ok(())
}