Skip to content

Commit

Permalink
Merge pull request #47 from leexgone/dev
Browse files Browse the repository at this point in the history
v0.8.0
  • Loading branch information
leexgone authored Mar 14, 2024
2 parents 71b0285 + 921af61 commit 5d8ec8e
Show file tree
Hide file tree
Showing 10 changed files with 724 additions and 521 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,11 @@
## v0.7.2

+ support converting `isize` to `Handle`. [issue-44](https://github.com/leexgone/uiautomation-rs/issues/44)

## v0.7.3

+ update to `widnows v0.52.0`

## v0.8.0

+ update to `windows v0.54.0`
8 changes: 4 additions & 4 deletions crates/uiautomation/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "uiautomation"
version = "0.7.2"
version = "0.8.0"
edition = "2021"
license = "Apache-2.0"
authors = ["Steven Lee <[email protected]>"]
Expand All @@ -17,12 +17,12 @@ targets = ["aarch64-pc-windows-msvc", "i686-pc-windows-msvc", "x86_64-pc-windows

[dependencies]

chrono = "0.4.31"
chrono = "0.4.35"
phf = { version = "0.11.2", features = ["macros"] }
uiautomation_derive = { version = "0.2.16", path = "../uiautomation_derive" }
uiautomation_derive = { version = "0.2.20", path = "../uiautomation_derive" }

[dependencies.windows]
version = "0.51.1"
version = "0.54.0"
features = [
"Win32_Foundation",
"Win32_System_Variant",
Expand Down
84 changes: 42 additions & 42 deletions crates/uiautomation/src/controls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,91 +37,91 @@ macro_rules! as_control_ref {
/// Defines enum for `windows::Win32::UI::Accessibility::UIA_CONTROLTYPE_ID`.
///
/// Contains the named constants used to identify Microsoft UI Automation control types.
#[repr(u32)]
#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, EnumConvert)]
pub enum ControlType {
/// Identifies the Button control type.
Button = 50000u32,
Button = 50000i32,
/// Identifies the Calendar control type.
Calendar = 50001u32,
Calendar = 50001i32,
/// Identifies the CheckBox control type.
CheckBox = 50002u32,
CheckBox = 50002i32,
/// Identifies the ComboBox control type.
ComboBox = 50003u32,
ComboBox = 50003i32,
/// Identifies the Edit control type.
Edit = 50004u32,
Edit = 50004i32,
/// Identifies the Hyperlink control type.
Hyperlink = 50005u32,
Hyperlink = 50005i32,
/// Identifies the Image control type.
Image = 50006u32,
Image = 50006i32,
/// Identifies the ListItem control type.
ListItem = 50007u32,
ListItem = 50007i32,
/// Identifies the List control type.
List = 50008u32,
List = 50008i32,
/// Identifies the Menu control type.
Menu = 50009u32,
Menu = 50009i32,
/// Identifies the MenuBar control type.
MenuBar = 50010u32,
MenuBar = 50010i32,
/// Identifies the MenuItem control type.
MenuItem = 50011u32,
MenuItem = 50011i32,
/// Identifies the ProgressBar control type.
ProgressBar = 50012u32,
ProgressBar = 50012i32,
/// Identifies the RadioButton control type.
RadioButton = 50013u32,
RadioButton = 50013i32,
/// Identifies the ScrollBar control type.
ScrollBar = 50014u32,
ScrollBar = 50014i32,
/// Identifies the Slider control type.
Slider = 50015u32,
Slider = 50015i32,
/// Identifies the Spinner control type.
Spinner = 50016u32,
Spinner = 50016i32,
/// Identifies the StatusBar control type.
StatusBar = 50017u32,
StatusBar = 50017i32,
/// Identifies the Tab control type.
Tab = 50018u32,
Tab = 50018i32,
/// Identifies the TabItem control type.
TabItem = 50019u32,
TabItem = 50019i32,
/// Identifies the Text control type.
Text = 50020u32,
Text = 50020i32,
/// Identifies the ToolBar control type.
ToolBar = 50021u32,
ToolBar = 50021i32,
/// Identifies the ToolTip control type.
ToolTip = 50022u32,
ToolTip = 50022i32,
/// Identifies the Tree control type.
Tree = 50023u32,
Tree = 50023i32,
/// Identifies the TreeItem control type.
TreeItem = 50024u32,
TreeItem = 50024i32,
/// Identifies the Custom control type. For more information, see Custom Properties, Events, and Control Patterns.
Custom = 50025u32,
Custom = 50025i32,
/// Identifies the Group control type.
Group = 50026u32,
Group = 50026i32,
/// Identifies the Thumb control type.
Thumb = 50027u32,
Thumb = 50027i32,
/// Identifies the DataGrid control type.
DataGrid = 50028u32,
DataGrid = 50028i32,
/// Identifies the DataItem control type.
DataItem = 50029u32,
DataItem = 50029i32,
/// Identifies the Document control type.
Document = 50030u32,
Document = 50030i32,
/// Identifies the SplitButton control type.
SplitButton = 50031u32,
SplitButton = 50031i32,
/// Identifies the Window control type.
Window = 50032u32,
Window = 50032i32,
/// Identifies the Pane control type.
Pane = 50033u32,
Pane = 50033i32,
/// Identifies the Header control type.
Header = 50034u32,
Header = 50034i32,
/// Identifies the HeaderItem control type.
HeaderItem = 50035u32,
HeaderItem = 50035i32,
/// Identifies the Table control type.
Table = 50036u32,
Table = 50036i32,
/// Identifies the TitleBar control type.
TitleBar = 50037u32,
TitleBar = 50037i32,
/// Identifies the Separator control type.
Separator = 50038u32,
Separator = 50038i32,
/// Identifies the SemanticZoom control type. Supported starting with Windows 8.
SemanticZoom = 50039u32,
SemanticZoom = 50039i32,
/// Identifies the AppBar control type. Supported starting with Windows 8.1.
AppBar = 50040u32
AppBar = 50040i32
}

impl From<windows::Win32::UI::Accessibility::UIA_CONTROLTYPE_ID> for ControlType {
Expand Down
30 changes: 15 additions & 15 deletions crates/uiautomation/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ use std::thread::sleep;
use std::time::Duration;

use chrono::Local;
use windows::Win32::Foundation::BOOL;
use windows::Win32::System::Com::CLSCTX_ALL;
use windows::Win32::System::Com::COINIT_MULTITHREADED;
use windows::Win32::System::Com::CoCreateInstance;
use windows::Win32::System::Com::CoInitializeEx;
use windows::Win32::System::Variant::VARIANT;
use windows::Win32::UI::Accessibility::CUIAutomation;
use windows::Win32::UI::Accessibility::IUIAutomation;
use windows::Win32::UI::Accessibility::IUIAutomationAndCondition;
Expand All @@ -22,7 +20,6 @@ use windows::Win32::UI::Accessibility::IUIAutomationNotCondition;
use windows::Win32::UI::Accessibility::IUIAutomationOrCondition;
use windows::Win32::UI::Accessibility::IUIAutomationPropertyCondition;
use windows::Win32::UI::Accessibility::IUIAutomationTreeWalker;
use windows::core::ComInterface;
use windows::core::IUnknown;
use windows::core::Interface;
use windows::core::IntoParam;
Expand Down Expand Up @@ -64,11 +61,15 @@ impl UIAutomation {
///
/// This method initializes the COM library each time, sets the thread's concurrency model as `COINIT_MULTITHREADED`.
pub fn new() -> Result<UIAutomation> {
unsafe {
CoInitializeEx(None, COINIT_MULTITHREADED)?;
let result = unsafe {
CoInitializeEx(None, COINIT_MULTITHREADED)
};

UIAutomation::new_direct()
if result.is_ok() {
UIAutomation::new_direct()
} else {
Err(result.into())
}
}

/// Creates a uiautomation client instance without initializing the COM library.
Expand Down Expand Up @@ -265,12 +266,12 @@ impl UIAutomation {

/// Creates a condition that selects elements that have a property with the specified value, using optional flags.
pub fn create_property_condition(&self, property: UIProperty, value: Variant, flags: Option<PropertyConditionFlags>) -> Result<UICondition> {
let val: VARIANT = value.into();
// let val: VARIANT = value.into();
let condition = unsafe {
if let Some(flags) = flags {
self.automation.CreatePropertyConditionEx(property.into(), val, flags.into())?
self.automation.CreatePropertyConditionEx(property.into(), value, flags.into())?
} else {
self.automation.CreatePropertyCondition(property.into(), val)?
self.automation.CreatePropertyCondition(property.into(), value)?
}
};
Ok(condition.into())
Expand Down Expand Up @@ -629,10 +630,9 @@ impl UIElement {
/// Retrieves a point on the element that can be clicked.
pub fn get_clickable_point(&self) -> Result<Option<Point>> {
let mut point = Point::default();
let mut got = BOOL::default();
unsafe {
self.element.GetClickablePoint(point.as_mut(), &mut got)?;
}
let got = unsafe {
self.element.GetClickablePoint(point.as_mut())?
};

Ok(if got.as_bool() {
Some(point)
Expand Down Expand Up @@ -789,7 +789,7 @@ impl Into<IUIAutomationElement> for UIElement {
// }

impl IntoParam<IUIAutomationElement> for UIElement {
fn into_param(self) -> windows::core::Param<IUIAutomationElement> {
unsafe fn into_param(self) -> windows::core::Param<IUIAutomationElement> {
windows::core::Param::Owned(self.element)
}
}
Expand Down Expand Up @@ -1285,7 +1285,7 @@ impl AsRef<IUIAutomationCondition> for UICondition {
}

impl IntoParam<IUIAutomationCondition> for UICondition {
fn into_param(self) -> windows::core::Param<IUIAutomationCondition> {
unsafe fn into_param(self) -> windows::core::Param<IUIAutomationCondition> {
windows::core::Param::Owned(self.0)
}
}
Expand Down
12 changes: 7 additions & 5 deletions crates/uiautomation/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ impl Error {
// };

// HRESULT(code).into()
if let Err(e) = error {
e.into()
} else {
HRESULT(0).into()
}
// if let Err(e) = error {
// e.into()
// } else {
// HRESULT(0).into()
// }
let result = HRESULT::from_win32(error.0);
result.into()
}

pub fn code(&self) -> i32 {
Expand Down
Loading

0 comments on commit 5d8ec8e

Please sign in to comment.