Created
July 29, 2021 14:59
-
-
Save kennykerr/5eaf5d576ba5030be77c03d16adcf53b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Windows::Win32::System::Com::*; | |
use Windows::Win32::UI::Accessibility::*; | |
use Windows::Win32::UI::WindowsAndMessaging::*; | |
use Windows::UI::UIAutomation::*; | |
fn main() -> Result<()> { | |
unsafe { | |
CoInitializeEx(std::ptr::null_mut(), COINIT_MULTITHREADED)?; | |
let window = FindWindowA(None, "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.get_CurrentName()?; | |
println!("window name: {}", name); | |
// Query for WinRT API (will fail on earlier versions of Windows) | |
let element: AutomationElement = element.cast()?; | |
// Use WinRT API | |
println!("file name: {}", element.ExecutableFileName()?); | |
} | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment