0

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

Bar
  • 57
  • 1
  • 2
  • 9

1 Answers1

2

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.

Community
  • 1
  • 1
arx
  • 16,686
  • 2
  • 44
  • 61
  • are there any other possibilities other that UI automation and the first method I've tried?? – Bar Mar 02 '13 at 23:40
  • They are the two standard methods. Other possibilities depend on how the application is written. e.g. If it's using GDI you could inject a DLL and intercept the TextOut function. But it might be using Direct2D. Or it might be using an internal library to render text to a bitmap and outputting that. You'd need to debug the application, find out how it's outputting its text and intercept that. It's not straightforward. – arx Mar 02 '13 at 23:58
  • so you're saying that getting into debugging with "API Hooking" will help me advance forward?? or did you refer to a different debugging method? thanks for all the help, and sorry for being such a noob – Bar Mar 03 '13 at 07:29
  • Not exactly. I'm suggesting that you find out what the application is doing. A debugger is one tool that might assist in this. Once you know how the application is outputting text then API hooking might be one way of intercepting it. – arx Mar 03 '13 at 11:21
  • could you name any relevant keywords/terms which i can use to continue my search for answers?? i'm just a little stuck with "debug" "external application" "how" "output" "text" T_T – Bar Mar 03 '13 at 19:25
  • The only thing I can think of is "reverse engineering". – arx Mar 05 '13 at 13:12