如果该unicode文本实际上是一个带有标题的窗口,您可以通过发送WM_GETTEXT消息来执行此操作.
[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, text.Capacity, text);
Run Code Online (Sandbox Code Playgroud)
如果它只是画在画布上,如果你知道应用程序使用什么框架,你可能会有一些运气.如果它使用WinForms或Borland的VCL,您可以使用该知识来获取文本.
如果您只关心标准的Win32标签,那么WM_GETTEXT将正常工作,如其他答案中所述.
-
有一个辅助功能API - UIAutomation - 用于标准标签,它也在后台使用WM_GETTEXT.然而,它的一个优点是它可以从几种其他类型的控件中获取文本,包括大多数系统控件,以及通常使用非系统控件的UI - 包括WPF,IE和Firefox中的文本等.
// compile as:
// csc file.cs /r:UIAutomationClient.dll /r:UIAutomationTypes.dll /r:WindowsBase.dll
using System.Windows.Automation;
using System.Windows.Forms;
using System;
class Test
{
public static void Main()
{
// Get element under pointer. You can also get an AutomationElement from a
// HWND handle, or by navigating the UI tree.
System.Drawing.Point pt = Cursor.Position;
AutomationElement el = AutomationElement.FromPoint(new System.Windows.Point(pt.X, pt.Y));
// 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.
Console.WriteLine( el.Current.Name );
}
}
Run Code Online (Sandbox Code Playgroud)