How to specify maxLength on the text size while getting the text from text box supporting ValuePattern?

Ashwin Mittal 5 Reputation points
2024-06-22T09:20:21.86+00:00

I'm using the IUIAutomation textRange GetText method if my text box supports the text pattern. There, I can specify the maxLength as given here: https://video2.skills-academy.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-gettext.

However, if a text box doesn't support TextPattern but ValuePattern, then I'm using IValueProvider. Unfortunately, this doesn't allow specifying the limit on the text to be retrieved.

    IValueProvider* pValueProvider;
    hr = pFocusedElement->GetCurrentPattern(UIA_ValuePatternId, reinterpret_cast<IUnknown**> (&pValueProvider));
    if (S_OK != hr)
    {
        printf("GetCurrentPattern error: %d\n", GetLastError());
        return FALSE;
    }

    BSTR text;
    hr = pValueProvider->get_Value(&text);
    if (S_OK != hr)
    {
        printf("get_Value error: %d\n", GetLastError());
        return FALSE;
    }
    wprintf(L"%s\n", text);
    SysFreeString(text);

I want to set the limit because I want to optimize my code and avoid spending too much time retrieving text from the box.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,491 questions
{count} vote