Reputation: 57
I've used spy++ to find the right handle of the wanted windows control, which belongs to a standalone application which isn't managed. Note that the spy++ "property inspector" mentions that this window doesn't have any child (or parent) windows.
I've also managed to get back the name of the window with the following code:
//the invokes are included aswell
const int WM_GETTEXT = 0x000D;
static void Main(string[] args)
{
IntPtr handle = new IntPtr(Convert.ToInt32("00070818", 16));
int nChars = GetWindowTextLength(handle); //win32 function
int length = 200;
StringBuilder sb = new StringBuilder(length);
SendMessage(handle, WM_GETTEXT, length, sb);
Console.WriteLine(sb.ToString());
}
This window has a lot more information than it's title, and that's all I seem to get back with WM_GETTEXT (changing the value of length to 200 didnt help, was a long shot anyway).
Next, I've tried a different approach using UI Automation:
static void Main(string[] args)
{
AutomationElement target = AutomationElement.FromHandle(handle);
TextPattern textPattern = target.GetCurrentPattern(TextPattern.Pattern) as TextPattern;
}
but I got this error back:
An unhandled exception of type 'System.InvalidOperationException' occurred in UIAutomationClient.dll
Additional information: Unsupported Pattern.
To top it off, I've also tried using Microsoft Inspect.exe, but it failed to focus on the text in the window, both in UI automation and MSAA mode.
Does it mean that the data cant be achieved with UI Automation?? or should am I just using the wrong methods/types?
Is there another way to get the data from this window other than using GetWindowText, WM_GETTEXT, or UI automation??
I'm fairly new to this stuff, but I'm trying my best to learn. In addition I've have no current leads so any helpful comment/answer would be much appreciated!! if you do answer please be sure to include helpful keywords so i'll be able to learn more about your solutions
Upvotes: 0
Views: 5604
Reputation: 16896
Labels (i.e. static controls) and text boxes are child windows with their own handles, hence they are visible to Spy++. If your target Window has no children then it's not using a label or text box, it's painting the text itself, and you won't be able to retrieve it using GetWindowText
or WM_GETTEXT
.
The text might be exposed through UI Automation, the API used by screen readers. Use UISpy.exe or Inspect.exe to see if the text is accessible.
Upvotes: 2