请教:调用API 传送数据,但是只有第一次Sendmessge成功,再次send就不行了。
程序如下:从textbox 传输数据给计算器。只能在程序第一次运行时可以send成功,想再次send时就不灵了,必须关闭程序,重新运行。
不知道为什么?请各位帮忙看看.多谢!
namespace WinAPI
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
[DllImport("user32.dll",EntryPoint = "FindWindow",SetLastError = true)]
public static extern IntPtr FindWindow(string IpClassName,string IpWindowName);
[DllImport("user32.dll",EntryPoint = "FindWindowEx")]
public static extern IntPtr FindWindowEx
(IntPtr hwndParent,IntPtr hwndChildAfter,string IpClassName,string IpWindowName);
[DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
public MainForm()
{
InitializeComponent();
}
void Button1Click(object sender, EventArgs e)
{
IntPtr ParentHand = FindWindow ("SciCalc","Calculator");
IntPtr handle = FindWindowEx (ParentHand,IntPtr.Zero,"Edit",null);
if (!handle.Equals(IntPtr.Zero))
{
if (SetForegroundWindow(handle))
{
SendKeys.Send(textBox1.Text);
SendKeys.Send("{ENTER}");
}
}
}
}
}
--------------------编程问答-------------------- 你必须确保计算机位于前景且编辑框有焦点。。。
补充:.NET技术 , C#