如何关注过程 [英] how to give a focus to process
本文介绍了如何关注过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友们,
我正在用C#开发应用程序.
我想集中精力处理在系统托盘上运行的进程(如应用程序).
我想还原应用程序以打开主窗体.
我该如何实现?
感谢
Hi friends,
I''m developing an application in c#.
I want give focus to process, like application, running on system tray.
I want to restore the application to open in the main form.
How can I achieve this?
thanks
推荐答案
您的问题不是很清楚,但据我了解,您希望从应用程序中集中一个正在运行的进程.
为此,以下是将应用程序名称作为输入的代码:
Your question is not very clear but what I understand is that, you wish to focus a running process from your application.
For that below is the code which take application name as input:
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace WindowsApplication1 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
private void button1_Click(object sender, EventArgs e) {
Process[] procs = Process.GetProcessesByName("notepad"); //app name here
if (procs.Length > 0) {
// Which one? I'll just pick the first
if (procs[0].MainWindowHandle != IntPtr.Zero)
SetForegroundWindow(procs[0].MainWindowHandle);
}
}
}
}
资料来源:
http://social.msdn.microsoft.com /forums/zh-CN/Vsexpressvcs/thread/6573bf2a-41a1-46d2-a1c5-797c8e0bd781/ [
Source:
http://social.msdn.microsoft.com/forums/en-US/Vsexpressvcs/thread/6573bf2a-41a1-46d2-a1c5-797c8e0bd781/[^]
这篇关于如何关注过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文