for example, I created an application called "Example" for you.then added a text box. this is a C # application, but you can also use this method for all Win32 applications. First create a C # application called Example, and then add a text box to it. you need to specify the class name of the text field in order to use this application. Then create the application and paste these codes.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, StringBuilder lParam);
[DllImport("user32.dll")]
public static extern IntPtr FindWindowEx(IntPtr Parent,IntPtr child, string classname, string WindowTitle);
const int WM_GETTEXT = 0x00D;
const int WM_GETTEXTLENGTH = 0x00E;
private void Form1_Load(object sender, EventArgs e)
{
Process procc = GetProcByName("Example");
if (procc != null)
{
IntPtr child = FindWindowEx(procc.MainWindowHandle, IntPtr.Zero, "WindowsForms10.EDIT.app.0.2bf8098_r16_ad1", null);
int length = SendMessage(child, WM_GETTEXTLENGTH, 0, 0);
StringBuilder text = new StringBuilder();
text = new StringBuilder(length + 1);
int retr2 = SendMessage(child, WM_GETTEXT, length + 1, text);
MessageBox.Show(text.ToString());
}
}
public Process GetProcByName(string Name)
{
Process proc = null;
Process[] processes = Process.GetProcesses();
for (int i = 0; i < processes.Length; i++)
{ if (processes[i].ProcessName == Name)proc = processes[i]; }
return proc;
}
}
}
I hope for this help.
source
share