这样可以吗,
使用System.Diagnostics名称空间中的Process类.如:
using System.Diagnostics;
...
private void button1_Click(object sender, System.EventArgs e)
{
Process myProcess=new Process ();
myProcess.StartInfo.FileName ="d:\\s1.txt";
//控制启动窗口的风格,(正常,或最小化,最大化等)
myProcess.StartInfo.WindowStyle=ProcessWindowStyle.Normal;
myProcess.Start();
}
使用System.Diagnostics名称空间中的Process类.如:
using System.Diagnostics;
...
private void button1_Click(object sender, System.EventArgs e)
{
Process myProcess=new Process ();
myProcess.StartInfo.FileName ="d:\\s1.txt";
//控制启动窗口的风格,(正常,或最小化,最大化等)
myProcess.StartInfo.WindowStyle=ProcessWindowStyle.Normal;
myProcess.Start();
}
----------------------------------
则可使用SendKeys方法来模拟输入按键事件
SendKeys.SendWait("{TAB}");
可在不同的EDIT控件中切换
另一个Form启动时再从这个固定的地方把文本读出来然后放EDIT里面……这样就什么也不用传了……^_^
给你写了个例子——using System.Runtime.InteropServices;
using System.Diagnostics;public class Test
{
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern int SetWindowPos(IntPtr hWnd, IntPtr hWndAfter, int X, int Y, int Width, int Height, uint flags); private int pos_x;//窗口位置X坐标
private int pos_y;//窗口位置Y坐标
private int width;//窗口宽度
private int height;//窗口高度
privtte string path;//要调用得应用程序路径 //在构造函数中传入设置信息
public Test(int x,int y,int width,int height,string path)
{
this.pos_x=x;
this.pos_y=y;
this.width=width;
this.height=height;
this.path=path;
}
//启动运用程序并设置其窗口位置及大小
public void StartProcess()
{
Process p=new Process();
p.StartInfo.FileName=this.path;
p.Start();
p.WaitForInputIdle(); SetWindowPos(p.MainWindowHandle,IntPtr.Zero,this.pos_x,this.pos_y,this.width,this.heigth, (uint)(0x0020|0x0040));
}
}
麻烦,解决立即给分,分不够再加
hwnd_win = FindWindow(null, "用户登录 - 中心营业部");
if (hwnd_win == IntPtr.Zero)
{
MessageBox.Show("警告:找不到目标窗口");
return;
}
SetFocus(hwnd_win);
input1(hwnd_win);public void input1(IntPtr myptr)
{
SetFocus(myptr);
SendKeys.SendWait("11");
Thread.Sleep(200);
Application.DoEvents();
SendKeys.SendWait("{ENTER}"); SendKeys.SendWait("123456");
Thread.Sleep(200);
Application.DoEvents();
SendKeys.SendWait("{ENTER}");
SendKeys.Send("666666");
Thread.Sleep(200);
Application.DoEvents();
SendKeys.SendWait("{ENTER}");
return;
}
但在运行中有问题,输入的字符容易多发一遍,若不加延时,发送的位置也容易错位,
不知怎样真正解决这个问题。大家也帮着看看