外部アプリケーションのテキスト ボックスからテキストを抽出するアプリケーションを C# で開発しました。user32.dll を使用しています。アプリケーションは正常に動作していますが、問題はこれです。外部アプリケーションのテキスト ボックスには Unicode 形式のテキストが含まれているため、 「??????」と表示されるアプリケーション 文章。charset.unicode を設定しようとしましたが、RichTextBox を使用してアプリケーションにテキストを表示しました。外部アプリケーションから Unicode テキストを抽出する方法を教えてください。
これが私が使用しているコードです
private void button1_Click(object sender, EventArgs e)
{ IntPtr MytestHandle = new IntPtr(0x00060342);
HandleRef hrefHWndTarget = new HandleRef(null, MytestHandle);
// encode text into
richTextBox1.Text = ModApi.GetText(hrefHWndTarget.Handle);
}
public static class ModApi {
[DllImport("user32.dll", EntryPoint = "SendMessageTimeout", SetLastError = true, CharSet = CharSet.Unicode)] public static extern uint SendMessageTimeoutText(IntPtr hWnd, int Msg, int countOfChars, StringBuilder text, uintフラグ、uint uTImeoutj、uint 結果);
public static string GetText(IntPtr hwnd)
{
var text = new StringBuilder(1024);
if (SendMessageTimeoutText(hwnd, 0xd, 1024, text, 0x2, 1000, 0) != 0)
{
return text.ToString();
}
MessageBox.Show(text.ToString());
return "";
}
}