Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the Accessible Name associated with a TEdit control?

If a user is using a screen reader (e.g. Microsoft Narrator), and their focus enters a text box:

enter image description here

All they hear is:

Editing text

Meanwhile in accessible applications,

  • such as Microsoft File Explorer
  • Microsoft Word
  • Microsoft Excel
  • Microsoft Outlook

the accessibility system is able to get the control's "Accessible Name":

enter image description here

Batch separator. Editing text

This works though the window implementing the IAccessible interface. It obtains a window's implementation of IAccessible by sending the hWnd the WM_GETOBJECT message. Applications never send this message though:

Sent by both Microsoft Active Accessibility and Microsoft UI Automation to obtain information about an accessible object contained in a server application.

Applications never send this message directly. Microsoft Active Accessibility sends this message in response to calls to AccessibleObjectFromPoint, AccessibleObjectFromEvent, or AccessibleObjectFromWindow.

But we can handle the message, and return an IAccessible interface to the caller:

case Message.Msg of
WM_GETOBJECT: 
   begin
      if DWORD(Message.LParam) = OBJID_CLIENT then
         Message.Result := LResultFromObject(IAccessible, Message.WParam, FAccessible);
   end;
end;

In the .NET world, their wrapper around an Edit control, exposes a way to set the accessible name of an TextBox using the Control.AccessibleName property:

Control.AccessibleName Property

Gets or sets the name of the control used by accessibility client applications.

public string AccessibleName { get; set; }

I don't know how the underlying Microsoft Edit control exposes accessibility features. I couldn't find any reference to IAccessible in the VCL except for TCustomActionMenuBar.

How does the VCL expose accessibility features?

How do i set the Accessible Name associated with a TEdit control?

How do i set the Accessible Name associated with an Edit control?

Bonus Chatter

The name of an accessible item is returned through the read-only IAccessible.accName property.

Property  Access Type  Description
--------  -----------  ----------------------------------------------------------
accName   Read-only    The name of the object. All objects support this property.
                       See get_accName.

Bonus Reading

  • Edit Control (MSAA UI Element Reference)
like image 306
Ian Boyd Avatar asked Mar 28 '18 15:03

Ian Boyd


1 Answers

How does the VCL expose accessibility features?

It doesn't, at all.

If you want this feature, you have to manually implement everything related to IAccessible yourself in your own code, and then subclass your VCL controls to respond to the WM_GETOBJECT message, just like you showed in your question.

For example:

Creating Accessible UI components in Delphi

like image 65
Remy Lebeau Avatar answered Nov 13 '22 04:11

Remy Lebeau