您的位置:首页 > 其它

wpf 打开外部程序并在需要时激活

2014-12-21 11:56 295 查看
打开外部程序使用Process

激活窗体,通过SetForegroundWindow函数传递Process获取的句柄激活

_external = new Process();


[DllImport("User32.dll", EntryPoint = "SetForegroundWindow")]
public static extern int SetForegroundWindow(IntPtr hWnd);

public void Run(string file, string args)
{
bool _bExisted = true;

try
{
if (_external.HasExited == false)
{
_bExisted = false;
SetForegroundWindow(_external.MainWindowHandle);
return;
}
}
catch (Exception e)
{
Global.MainLogging.LogError("ExternalProcess.Run:param1:" + file + ",param2:" + args + "," + e.ToString());
}
finally
{
if (_bExisted) RunExternal(file, args);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐