See also: acc
In QM, you can work not only with top-level windows, but also with user interface (UI) objects that are parts of window. Most of them are child windows ("controls") and can be identified by handle. You can use function id or child to retrieve child window handle. But not all objects are child windows. For example, links or controls in web page are not true child windows, and functions id and child cannot find them. The alternative is accessible objects.
Accessible objects are user interface objects contained in a window or desktop: buttons, menus, links, etc. Accessible objects are based on Microsoft® Active Accessibility®, which is based on COM. Active Accessibility allows you to identify more UI objects than just windows and controls. In addition, it provides alternative ways to interact with UI objects - select, click, navigate, get dimensions, etc.
Differently than windows and controls, that are identified by handle, accessible object is identified by pointer to object's IAccessible interface. Some objects also have simple elements that are identified by a numeric identifier (in addition to pointer to parent's IAccessible interface). For example, list object can have list items as elements. QM defines Acc class (type) to store IAccessible pointer and element identifier together. Definition:
class Acc IAccessible'a elem
A variable of class Acc fully identifies accessible object. You don't care whether object is simple element or not.
To find object and populate Acc variable, use function acc. The Find Accessible Object dialog (floating toolbar -> Windows, controls, menus -> Find accessible object) will help you with acc function. The Acc class has several simple functions that you can use to interact with object. The Accessible Object dialog will help you with Acc functions. Common call syntax is:
[result = ]a.Function([arguments])
Example:
Acc ok=acc("OK" "PUSHBUTTON" "Notepad" "Button") if(!a.a) ret ;;object not found str name = ok.Name ok.DoDefaultAction ...
On failure, all functions throw run-time error, therefore you should understand error handling. Note that different kinds of accessible objects support different sets of functions. You should call only supported functions, or be prepared to handle error. You should also remember that function acc clears Acc variable if object is not found. To test for object validity, use code similar to second line in example above.
There are more functions that you can call. They are members of IAccessible interface, therefore you use member a of Acc variable. When calling IAccessible interface functions directly, you can use element identifier to identify simple element, or 0 (or omit it) to identify object itself. Example:
Acc a=acc("Tools" "MENUITEM" "Quick Macros" "ToolbarWindow32" "" 0x1) out a.a.KeyboardShortcut(a.elem)
Drag the picture to find an object. While dragging, right-click (without releasing the left button) to switch to another window.
When you find an object, do not forget to click the Test button. If it says "Object not found", try to change some values in the dialog. For example, if the object is invisible (or may be invisible when the macro runs), click Options and check Search Invisible Objects (this is not necesary for menus). Or, maybe it searches in wrong window (try to change the Window field). Some applications report bad class name (try to delete it).
If it finds wrong object, try to capture an adjacent object, Test it, check Navigate, and enter post-navigation string in the Navigate field. It can contain one or more of the following words or abbreviations: up, down, left, right, next, previous, first, last, parent, child. A word can be followed by a number. Read more about navig argument of function acc. Example: pa n2 c15 f. Explanation: get parent object, get next object two times, get 15-th child object, get first child object.
If the search time is too long, try to click Options and check Search In Reverse Order. The post-navigation also can be used for this purpose.
You cannot find a menu item by dragging. But you can drag and drop on menu bar, and then select the required menu item in the hierarchy (the bottom part of the Find Accessible Object dialog), if available. Generally, it is better to use the men command to click menu items, and you can record it (menu Tools -> Record Menu).
The coordinates (x, y) are in the client area of the window.
Max length of various text properties is 4095 characters.
One drawback of Active Accessibility - searching for an object can take quite
long time, especially with some large applications and web pages. For web pages,
you can use function htm (find html
element) instead of acc.