1,486
社区成员
发帖
与我相关
我的任务
分享
' Form1
' 放一个TextBox
Option Explicit
Private Sub Text1_Change()
MsgBox "收到消息:" & Text1
End Sub
// Form1
// 放一个 TextBox,一个 Button
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;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
#region "API"
[DllImport("User32.dll",EntryPoint= "FindWindow")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll",EntryPoint= "FindWindowEx")]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("User32.dll",EntryPoint= "SendMessage")]
private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, string lParam);
const int WM_SETTEXT = 0xC;
#endregion
private void SendText(String text)
{
string lpszFormClass = "ThunderRT6FormDC"; //如果是在VB-IDE中启动的,用 ThunderFormDC
string lpszTextClass = "ThunderRT6TextBox";//如果是在VB-IDE中启动的,用 ThunderTextBox
string lpszFormWindow = "Form1"; //窗口标题
IntPtr hWndForm = new IntPtr(0);
IntPtr hWndText = new IntPtr(0);
hWndForm = FindWindow(lpszFormClass,lpszFormWindow);
if (hWndForm.Equals(IntPtr.Zero))
{
MessageBox.Show("窗体不存在!");
return;
}
hWndText = FindWindowEx(hWndForm, hWndText, lpszTextClass, null );
if (hWndText.Equals(IntPtr.Zero))
{
MessageBox.Show("TextBox不存在!");
return;
}
SendMessage(hWndText, WM_SETTEXT,0, text);
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SendText(textBox1.Text);
}
}
}