日期:2014-05-20  浏览次数:20964 次

如何调用单一外部程序?
ProcessStartInfo   psi   =   new   ProcessStartInfo( "help.exe ");
Process   ps   =   Process.Start(psi);

在一个按钮的事件里面我调用了一个“help.exe”,显示了一个帮助的flash文件,如何让之后点击这个按钮时让焦点到这个flash文件上来,不再显示更多的帮助文件?

现在的问题是多点一下就多显示一个帮助文件。

------解决方案--------------------
//也许是这样

Process[] vProcesses = Process.GetProcessesByName( "help.exe ");
if (vProcesses.Length <= 0)
{
ProcessStartInfo psi = new ProcessStartInfo( "help.exe ");
Process ps = Process.Start(psi);
}
else
{
//ShowWindow(vProcesses[0].MainWindowHandle, SW_SHOW);//API
}

------解决方案--------------------
使用singleton模式,在类的构造函数中使用process启动 "help.exe ",并在重复判断时,将help.exe进程主窗口提前
------解决方案--------------------
public static void CreateProcess(string fn, string Arguments, MsgCallback Callback)
{
ProcessStartInfo pi = new ProcessStartInfo();
pi.FileName = fn;
pi.Arguments = Arguments;
pi.UseShellExecute = false;
pi.CreateNoWindow = true;
pi.WindowStyle = ProcessWindowStyle.Hidden;
pi.RedirectStandardOutput = true;
pi.RedirectStandardError = true;

System.Diagnostics.Process p = new Process();


p.StartInfo = pi;
p.Start();

while (!p.HasExited)
{
System.Windows.Forms.Application.DoEvents();

if (Callback != null)
{
string s;
while ((s = p.StandardOutput.ReadLine()) != null)
{
Callback(s);
}
}
p.WaitForExit(100);
}

}
------解决方案--------------------
public delegate void MsgCallback(string msg);
------解决方案--------------------
up
------解决方案--------------------
大哥,你就不能google一下?
这样不就行了:
[DllImport( "user32.dll ", EntryPoint = "FindWindow ")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport( "user32.dll ")]
static extern IntPtr SetActiveWindow(IntPtr hWnd);

[DllImport( "user32.dll ")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);

IntPtr DIALOG_HANDLER = FindWindow(null, 进程主窗体名);
if (DIALOG_HANDLER != IntPtr.Zero)
{
SetForegroundWindow(DIALOG_HANDLER);
}