How to specify maxLength on the text size while getting the text from text box supporting ValuePattern?
Ashwin Mittal
5
Reputation points
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.