我正在尝试从C#运行交互式RPG / MAPICS程序。为此,我正在尝试通过PCSWS.EXE启动.ws文件,并从C#向其写入输入。
仿真器可以正常启动,但是我似乎无法通过标准输入或SendMessage(我通过SETTEXT和KEYDOWN尝试过)向其发送输入。
我在做什么错,在这里?我应该如何从C#启动交互式RPG程序?
public void LaunchRPGApp(Application program)
{
var processInfo = new ProcessStartInfo("pcsws.exe")
{
WindowStyle = ProcessWindowStyle.Normal,
Arguments = "\"C:\\Program Files (x86)\\IBM\\Client Access\\Emulator\\Private\\veflast1.ws\"",
RedirectStandardInput = true,
UseShellExecute = false,
};
var process = Process.Start(processInfo);
SendTextToProcess(process, "f");//Try via SendMessage
using (var sr = process.StandardInput)//Try via StdIn
{
sr.Write("f");//does nothing
sr.Close();
}
}
[DllImport("user32.dll", EntryPoint = "FindWindowEx")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("User32.dll")]
public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam);
private void SendTextToProcess(Process p, string text)
{
const int WM_SETTEXT = 0x000C;
const int WM_KEYDOWN = 0x0100;
const int F_KEY = 0x46;
Thread.Sleep(500);
var child = FindWindowEx(p.MainWindowHandle, new IntPtr(0), "Edit", null);
SendMessage(child, WM_KEYDOWN, F_KEY, null);//does nothing
SendMessage(child, WM_SETTEXT, 0, text);//does nothing
}
答案 0 :(得分:1)
答案 1 :(得分:1)
找到了解决方案-通过在参数后面附加“ / M = {macroName}”,可以在启动PCSWS.EXE时运行VBScript宏。请注意,该宏必须存在于特定的文件夹中。
然后,宏使用autECLSession.autECLPS.SendKeys
发送击键。
像这样:
public void LaunchRPGApp(Application program)
{
MakeMacro(program);
const string wsPathAndFilename =
"C:\\Program Files (x86)\\IBM\\Client Access\\Emulator\\Private\\flast1.ws";
var processInfo = new ProcessStartInfo("pcsws.exe")
{
Arguments = "{wsPathandFilename} /M=name.mac"
};
Process.Start(processInfo);
}
private void MakeMacro(Application program)
{
var macroText = GetMacroText(program);//Method to get the content of the macro
var fileName =
$"C:\\Users\\{Environment.UserName}\\AppData\\Roaming\\IBM\\Client Access\\Emulator\\private\\name.mac";
using (var writer = new StreamWriter(fileName))
{
writer.Write(macroText);
}
}