elementFromHandle method

IUIAutomationElement? elementFromHandle(
  1. HWND hwnd
)

Retrieves a UI Automation element for the specified window.

Throws a WindowsException on failure.

To learn more, see learn.microsoft.com/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomation-elementfromhandle.

Implementation

IUIAutomationElement? elementFromHandle(HWND hwnd) {
  final element = adaptiveCalloc<VTablePointer>();
  final hr$ = HRESULT(_ElementFromHandleFn(ptr, hwnd, element));
  if (hr$.isError) {
    free(element);
    throw WindowsException(hr$);
  }
  final result$ = element.value;
  free(element);
  if (result$.isNull) return null;
  return .new(result$);
}