C#实现打开另一个程序并前置显示
来源:互联网 发布:网络安全检查通报 编辑:程序博客网 时间:2024/05/22 13:09
[DllImport("user32.dll ")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
//根据任务栏应用程序显示的名称找相应窗口的句柄
[DllImport("User32.dll", EntryPoint = "FindWindow")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
private const int SW_RESTORE = 9;
private void OpenSerialPortUtility(object sender, EventArgs e)
{
//第一种方法
IntPtr findPtr = FindWindow(null, "友善串口调试助手");
if (findPtr.ToInt32() != 0)
{
ShowWindow(findPtr, SW_RESTORE); //将窗口还原,如果不用此方法,缩小的窗口不能激活
SetForegroundWindow(findPtr);//将指定的窗口选中(激活)
}
else
{
System.Diagnostics.Process.Start(@"D:\Program Files (x86)\Serial Port Utility\SerialPortUtility.exe");
}
//第二种方法
//遍历进程列表查找目标程序是否运行运行则前置否则启动
//Process[] pList = Process.GetProcesses(".");
//bool b = false;
//foreach (Process p in pList)
//{
// if (p.ProcessName == "SerialPortUtility")
// {
// b = true;
// //Process.GetCurrentProcess();
// ShowWindow(p.MainWindowHandle, SW_RESTORE); //将窗口还原,如果不用此方法,缩小的窗口不能激活
// bool res = SetForegroundWindow(p.MainWindowHandle);
// if (res == false)
// {
// }
// break;
// }
//}
//if (b == false)
//{
// System.Diagnostics.Process.Start(@"D:\Program Files (x86)\Serial Port Utility\SerialPortUtility.exe");
//}
}
阅读全文
0 0
- C#实现打开另一个程序并前置显示
- c# 进程窗口显示并前置
- 在C#中打开另一个程序
- c#实现关闭当前窗体并打开另一个已经创建的窗体
- VC程序中打开一个另一个程序并关闭
- 查找另一个程序,并将其显示在最前端
- C#与Emgu 从当前窗口打开另一个窗口 并在其窗口打开图片
- 打开文件(读取文件),并实现显示
- 加载页面时自动打开另一个新页面的并同时打开一个exe程序
- C#实现文件拖放并打开文件
- Android应用打开另一个程序
- c# 程序只能运行一次(多次运行只能打开同一个程序) 并激活第一个实例,使其获得焦点,并在最前端显示.
- c# 程序只能运行一次(多次运行只能打开同一个程序) 并激活第一个实例,使其获得焦点,并在最前端显示.
- c# 程序只能运行一次(多次运行只能打开同一个程序) 并激活第一个实例,使其获得焦点,并在最前端显示.
- c# 程序只能运行一次(多次运行只能打开同一个程序) 并激活第一个实例,使其获得焦点,并在最前端显示.
- c# 程序只能运行一次(多次运行只能打开同一个程序) 并激活第一个实例,使其获得焦点,并在最前端显示.
- 在C#中启动另一个程序的实现方法
- C#中打开word 文件并在richTextBox中显示
- libtool version mismatch error
- ArcEngine 地图图片输出 栅格不清晰
- Windows下使用SparkR进行数据分析
- 欢迎使用CSDN-markdown编辑器
- scp在Centos上使用出现WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!
- C#实现打开另一个程序并前置显示
- 2017全球青年创业者大会早鸟票
- 使用Cookie实现自动登录
- python核心编程读书笔记--第1章eclipse插件
- 怎么对at89s52单片机进行烧录
- CoverageMaster winAMS
- Java scanner录入数字与字符
- 框架应用 : Spring MVC
- 大小写字母转化