网上找的,将内容写到记事本中, [DllImport("user32.dll", EntryPoint = "FindWindowEx")]
public static extern IntPtr FindWindowEx(IntPtr hWnd1, int hWnd2, string lpsz1, string lpsz2);
[DllImport("user32.dll", EntryPoint = "GetWindowText")]
public static extern IntPtr GetWindowText(IntPtr hwnd, StringBuilder lpString, int cch);
[DllImport("User32 ")]
public static extern bool SendMessage(IntPtr hWnd, int Msg, int wParam, IntPtr lParam);
[DllImport("User32 ")]
public static extern bool SendMessage(IntPtr hWnd, int Msg, int wParam, string lParam);
public const int WM_GETTEXT = 0xD;
public const int WM_SETTEXT = 0xC;
private void button11_Click(object sender, EventArgs e)
{
Process p1 = Process.Start("Notepad.exe");
p1.WaitForInputIdle();
Process[] process_array = Process.GetProcesses();
IntPtr hNotepad = IntPtr.Zero;
foreach (Process p in process_array)
{
if (p.MainWindowTitle.IndexOf("记事本") != -1)//找到了
{
hNotepad = p.MainWindowHandle;
break;
}
}
if (hNotepad != IntPtr.Zero)
{
IntPtr hEdit = FindWindowEx(hNotepad, 0, "Edit", "");
SendMessage(hEdit, WM_SETTEXT, 100, "这里是测试文本");
string w = " ";
IntPtr ptr = Marshal.StringToHGlobalAnsi(w);
if (SendMessage(hEdit, WM_GETTEXT, 100, ptr)) Console.WriteLine(Marshal.PtrToStringAnsi(ptr));
} }
public static extern IntPtr FindWindowEx(IntPtr hWnd1, int hWnd2, string lpsz1, string lpsz2);
[DllImport("user32.dll", EntryPoint = "GetWindowText")]
public static extern IntPtr GetWindowText(IntPtr hwnd, StringBuilder lpString, int cch);
[DllImport("User32 ")]
public static extern bool SendMessage(IntPtr hWnd, int Msg, int wParam, IntPtr lParam);
[DllImport("User32 ")]
public static extern bool SendMessage(IntPtr hWnd, int Msg, int wParam, string lParam);
public const int WM_GETTEXT = 0xD;
public const int WM_SETTEXT = 0xC;
private void button11_Click(object sender, EventArgs e)
{
Process p1 = Process.Start("Notepad.exe");
p1.WaitForInputIdle();
Process[] process_array = Process.GetProcesses();
IntPtr hNotepad = IntPtr.Zero;
foreach (Process p in process_array)
{
if (p.MainWindowTitle.IndexOf("记事本") != -1)//找到了
{
hNotepad = p.MainWindowHandle;
break;
}
}
if (hNotepad != IntPtr.Zero)
{
IntPtr hEdit = FindWindowEx(hNotepad, 0, "Edit", "");
SendMessage(hEdit, WM_SETTEXT, 100, "这里是测试文本");
string w = " ";
IntPtr ptr = Marshal.StringToHGlobalAnsi(w);
if (SendMessage(hEdit, WM_GETTEXT, 100, ptr)) Console.WriteLine(Marshal.PtrToStringAnsi(ptr));
} }
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货