Platforms to show: All Mac Windows Linux Cross-Platform

/WinFrameworks/UIAutomation/UIAutomation Focus


Last modified Tue, 13th Apr 2026.

You find this example project in your MBS Xojo Plugin download as a Xojo project file within the examples folder: /WinFrameworks/UIAutomation/UIAutomation Focus

Download this example: UIAutomation Focus.zip

Project "UIAutomation Focus.xojo_binary_project"
Class App Inherits DesktopApplication
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits DesktopWindow
Control List Inherits DesktopListBox
ControlInstance List Inherits DesktopListBox
End Control
EventHandler Sub Opening() UIAutomation = new UIAutomationMBS var focussed as UIAutomationElementMBS = UIAutomation.FocusedElement handler = new UIAutomationFocusChangedEventHandler handler.List = list var ca as UIAutomationCacheRequestMBS = UIAutomation.CreateCacheRequest ca.AddProperty UIAutomationElementMBS.PropertyIdClassName ca.AddProperty UIAutomationElementMBS.PropertyIdName ca.AddProperty UIAutomationElementMBS.PropertyIdProcessId ca.AddProperty UIAutomationElementMBS.PropertyIdProviderDescription ca.AddProperty UIAutomationElementMBS.PropertyIdValueValue UIAutomation.AddFocusChangedEventHandler ca, handler End EventHandler
Property Handler As UIAutomationFocusChangedEventHandler
Property UIAutomation As UIAutomationMBS
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
MenuItem WindowMenu = "Window"
MenuItem HelpMenu = "&Help"
End MenuBar
Sign
End Sign
Class UIAutomationFocusChangedEventHandler Inherits UIAutomationFocusChangedEventHandlerMBS
EventHandler Sub HandleFocusChangedEvent(sender as UIAutomationElementMBS) List.AddRow _ sender.CachedProcessId.ToString, _ sender.CachedName, _ sender.CachedClassName, _ sender.CachedPropertyValue(sender.PropertyIdValueValue), _ controltypename(sender.CachedControlType) // if you call current properties, you may cause a deadlock if you query current process End EventHandler
Function controltypename(ControlType as Integer) As string Select Case ControlType Case UIAutomationElementMBS.ControlTypeWindow Return "Window" Case UIAutomationElementMBS.ControlTypeTreeItem Return "TreeItem" Case UIAutomationElementMBS.ControlTypeTree Return "Tree" Case UIAutomationElementMBS.ControlTypeToolTip Return "ToolTip" Case UIAutomationElementMBS.ControlTypeToolBar Return "ToolBar" Case UIAutomationElementMBS.ControlTypeTitleBar Return "TitleBar" Case UIAutomationElementMBS.ControlTypeThumb Return "Thumb" Case UIAutomationElementMBS.ControlTypeText Return "Text" Case UIAutomationElementMBS.ControlTypeTable Return "Table" Case UIAutomationElementMBS.ControlTypeTabItem Return "TabItem" Case UIAutomationElementMBS.ControlTypeTab Return "Tab" Case UIAutomationElementMBS.ControlTypeStatusBar Return "StatusBar" Case UIAutomationElementMBS.ControlTypeSplitButton Return "SplitButton" Case UIAutomationElementMBS.ControlTypeSpinner Return "Spinner" Case UIAutomationElementMBS.ControlTypeSlider Return "Slider" Case UIAutomationElementMBS.ControlTypeSeparator Return "Separator" Case UIAutomationElementMBS.ControlTypeSemanticZoom Return "SemanticZoom" Case UIAutomationElementMBS.ControlTypeScrollBar Return "ScrollBar" Case UIAutomationElementMBS.ControlTypeRadioButton Return "RadioButton" Case UIAutomationElementMBS.ControlTypeProgressBar Return "ProgressBar" Case UIAutomationElementMBS.ControlTypePane Return "Pane" Case UIAutomationElementMBS.ControlTypeMenuItem Return "MenuItem" Case UIAutomationElementMBS.ControlTypeMenuBar Return "MenuBar" Case UIAutomationElementMBS.ControlTypeMenu Return "Menu" Case UIAutomationElementMBS.ControlTypeListItem Return "ListItem" Case UIAutomationElementMBS.ControlTypeList Return "List" Case UIAutomationElementMBS.ControlTypeImage Return "Image" Case UIAutomationElementMBS.ControlTypeHyperlink Return "Hyperlink" Case UIAutomationElementMBS.ControlTypeHeaderItem Return "HeaderItem" Case UIAutomationElementMBS.ControlTypeHeader Return "Header" Case UIAutomationElementMBS.ControlTypeGroup Return "Group" Case UIAutomationElementMBS.ControlTypeEdit Return "Edit" Case UIAutomationElementMBS.ControlTypeDocument Return "Document" Case UIAutomationElementMBS.ControlTypeDataItem Return "DataItem" Case UIAutomationElementMBS.ControlTypeDataGrid Return "DataGrid" Case UIAutomationElementMBS.ControlTypeCustom Return "Custom" Case UIAutomationElementMBS.ControlTypeComboBox Return "ComboBox" Case UIAutomationElementMBS.ControlTypeCheckBox Return "CheckBox" Case UIAutomationElementMBS.ControlTypeCalendar Return "Calendar" Case UIAutomationElementMBS.ControlTypeButton Return "Button" Case UIAutomationElementMBS.ControlTypeAppBar Return "AppBar" End Select End Function
Property List As DesktopListBox
End Class
End Project

See also:

Download this example: UIAutomation Focus.zip

The items on this page are in the following plugins: MBS WinFrameworks Plugin.


The biggest plugin in space...