<p>Is it possible to get UI text from an external application in C#. </p>

<p>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.</p>

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

<p>Edit: Currently looking into using something like the <a href="http://msdn.microsoft.com/en-us/magazine/cc163617.aspx" rel="nofollow noreferrer">Managed Spy App</a> but would still appreciate any other leads.</p>

[{'answer_id': 18698, 'author': 'Lars Truijens', 'author_id': 1242, 'author_profile': 'https://Stackoverflow.com/users/1242', 'pm_score': 3, 'selected': False, 'text': '<p>You could do it if that unicode text is actually a window with a caption by sending a <a href="http://msdn.microsoft.com/en-us/library/ms632627.aspx" rel="nofollow noreferrer">WM_GETTEXT</a> message. </p>\n\n<pre><code>[DllImport("user32.dll")]\npublic static extern int SendMessage (IntPtr hWnd, int msg, int Param, System.Text.StringBuilder text);\n\nSystem.Text.StringBuilder text = new System.Text.StringBuilder(255) ;  // or length from call with GETTEXTLENGTH\nint RetVal = Win32.SendMessage( hWnd , WM_GETTEXT, text.Capacity, text);\n</code></pre>\n\n<p>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.</p>\n'}, {'answer_id': 18855, 'author': 'sieben', 'author_id': 1147, 'author_profile': 'https://Stackoverflow.com/users/1147', 'pm_score': 2, 'selected': False, 'text': "<p>didn't see the values for wm_gettext or wm_gettextlength in that article, so just in case..</p>\n\n<pre><code>const int WM_GETTEXT = 0x0D;\nconst int WM_GETTEXTLENGTH = 0x0E;\n</code></pre>\n"}, {'answer_id': 11042272, 'author': 'BrendanMcK', 'author_id': 660175, 'author_profile': 'https://Stackoverflow.com/users/660175', 'pm_score': 3, 'selected': False, 'text': '<p>If you just care about the standard Win32 label, then <A HREF="http://msdn.microsoft.com/en-us/library/windows/desktop/ms632627(v=vs.85).aspx" rel="noreferrer">WM_GETTEXT</a> will work fine, as outlined in the other answers.</p>\n\n<p>--</p>\n\n<p>There is an accessibility API - <A href="http://msdn.microsoft.com/en-us/library/ms747327.aspx" rel="noreferrer">UIAutomation</A> - for standard labels, it too uses WM_GETTEXT behind the scenes. One advantage to it, however, is that it can get text from several other types of controls, including most system controls, and often UI using non-system controls - including WPF, text in IE and Firefox, and others.</p>\n\n<pre><code>// compile as:\n// csc file.cs /r:UIAutomationClient.dll /r:UIAutomationTypes.dll /r:WindowsBase.dll\nusing System.Windows.Automation;\nusing System.Windows.Forms;\nusing System;\n\nclass Test\n{\n    public static void Main()\n    {\n        // Get element under pointer. You can also get an AutomationElement from a\n            // HWND handle, or by navigating the UI tree.\n        System.Drawing.Point pt = Cursor.Position;\n        AutomationElement el = AutomationElement.FromPoint(new System.Windows.Point(pt.X, pt.Y));\n        // Prints its name - often the context, but would be corresponding label text for editable controls. Can also get the type of control, location, and other properties.\n        Console.WriteLine( el.Current.Name );\n    }\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/18661', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/838/']