You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#[allow( unused_variables )]
use uiautomation::core::UIAutomation;
fn main() {
let ui = UIAutomation::new().unwrap();
let el = ui.element_from_handle( 0x2006C6 ).unwrap();
}
error[E0308]: mismatched types
let el = ui.element_from_handle( 0x2006C6 ).unwrap();
---------------------------------- ^^^^^^^^ expected Handle, found integer
-----------|arguments to this method are incorrect
#[allow( unused_variables )]
use winapi::shared::windef::HWND;
use uiautomation::core::UIAutomation;
fn main() {
let ui = UIAutomation::new().unwrap();
let el = ui.element_from_handle( 0x2006C6 as HWND ).unwrap();
}
error[E0308]: mismatched types
let el = ui.element_from_handle( 0x2006C6 as HWND ).unwrap();
-------------------------------- ^^^^^^^^^^^^^^^^ expected Handle, found *mut HWND__
----------|arguments to this method are incorrect
note: expected struct Handle
found raw pointer *mut HWND__
Issue:
Although the errors are understandable, considering the parameters that element_from_handle method takes in, but got no clue how to resolve it !?
P. S. (rant)
Newly migrating from Python to Rust. Python's library uiautomation works like charm to read that integer as HWND, but, its slow. Hence, this migration.
In Python:
import uiautomation as ui
if __name__ == '__main__':
el = ui.ControlFromHandle( 0x2006C6 )
print( el )
Upon digging uiautomation python open source code, ControlFromHandle( integer ) simply returns ElementFromHandle(), like so:
def ControlFromHandle(handle: int) -> Control:
"""
Call IUIAutomation.ElementFromHandle with a native handle.
handle: int, a native window handle.
Return `Control` subclass or None.
"""
if handle:
return Control.CreateControlFromElement(_AutomationClient.instance().IUIAutomation.ElementFromHandle(handle))
Furthermore, CreateControlFromElement() is simply:
@staticmethod
def CreateControlFromElement(element) -> 'Control':
"""
Create a concreate `Control` from a com type `IUIAutomationElement`.
element: `ctypes.POINTER(IUIAutomationElement)`.
Return a subclass of `Control`, an instance of the control's real type.
"""
if element:
controlType = element.CurrentControlType
if controlType in ControlConstructors:
return ControlConstructors[controlType](element=element)
else:
Logger.WriteLine("element.CurrentControlType returns {}, invalid ControlType!".format(controlType), ConsoleColor.Red) # rarely happens
Bottomline
In Python, the IUIAutomation wrapper's method ElementFromHandle accepts integer datatype for its handle parameter.
In Rust, the UIAutomation (same MS IUIAutomation wrapper) method element_from_handle needs what?
Something is missing, may be the answer lies in uiautomation::types::Handle!
The text was updated successfully, but these errors were encountered:
Objective
Owing to stringent time constraints, instead of TreeWalk or via element childrens, directly get
element_from_handle
Failed attempt # 1:
[using cargo.toml]
Failed attempt # 2:
[using cargo.toml]
Issue:
Although the errors are understandable, considering the parameters that
element_from_handle
method takes in, but got no clue how to resolve it !?P. S. (rant)
In Python:
Bingo "straightaway":
Upon digging
uiautomation
python open source code,ControlFromHandle( integer )
simply returnsElementFromHandle()
, like so:Furthermore,
CreateControlFromElement()
is simply:Bottomline
In Python, the
IUIAutomation
wrapper's methodElementFromHandle
acceptsinteger
datatype for itshandle
parameter.In Rust, the
UIAutomation
(same MS IUIAutomation wrapper) methodelement_from_handle
needs what?Something is missing, may be the answer lies in
uiautomation::types::Handle
!The text was updated successfully, but these errors were encountered: