tags:

views:

810

answers:

2

Is it possible to get UI text from an external application in C#.

In particular, is there a way to read Unicode text from a label (I assume it's a normal Windows label control) from an external Win32 app that was written by a 3rd party? The text is visible, but not selectable by mouse in the UI.

I assume there is some accessibility API (e.g. meant for screen readers) that allows this.

Edit: Currently looking into using something like the Managed Spy App but would still appreciate any other leads.

+2  A: 

You could do it if that unicode text is actually a window with a caption by sending a WM_GETTEXT message.

[DllImport("user32.dll")]
public static extern int SendMessage (IntPtr hWnd, int msg, int Param, System.Text.StringBuilder text);

System.Text.StringBuilder text = new System.Text.StringBuilder(255) ;  // or length from call with GETTEXTLENGTH
int RetVal = Win32.SendMessage( hWnd , WM_GETTEXT, sb.Capacity, text);

If it is just painted on the canvas you might have some luck if you know what framework the application uses. If it uses WinForms or Borland's VCL you could use that knowledge to get to the text.

Lars Truijens
A: 

didn't see the values for wmgettext or wmgettextlength in that article, so just in case..

const int WM_GETTEXT = 0x0D;
const int WM_GETTEXTLENGTH = 0x0E;
sieben