的FindWindow和SetForegroundWindow的选择吗? [英] FindWindow and SetForegroundWindow alternatives?

查看:635
本文介绍了的FindWindow和SetForegroundWindow的选择吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找替代旧的User32.dll 版本切换到不同的应用程序的FindWindow() SetForegroundWindow()

I am searching for alternatives to the old User32.dll version of switching to a different application with FindWindow() and SetForegroundWindow().

我没有找到一个替代先用的使用Process.GetProcessesByName(),但我没有看到相应的方法来切换(设置为活动/前台),以该应用程序。

I did find an alternative to the first with the usage of Process.GetProcessesByName() but I do not see the corresponding method to switch (set active/foreground) to that application.

是否有这样做的一种方式,不使用的的方式与的User32.dll

Is there a way of doing that without using the old way with the User32.dll?

感谢您的帮助。

修改

我接受@Sorceri的答案虽然这不是我一直在寻找的答案。

I accepted the answer of @Sorceri although it is not the answer I was looking for.

推荐答案

答:否

不过,以帮助下一wonderer希望找到一个窗口,从这里C#激活它是你必须做的:

But, to help the next wonderer looking to find a window and activate it from C# here's what you have to do:

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

void ActivateApp(string processName)
{
    Process[] p = Process.GetProcessesByName(processName);

    // Activate the first application we find with this name
    if (p.Count() > 0)
        SetForegroundWindow(p[0].MainWindowHandle);
}

要带记事本的前面,比如,你会打电话:

To bring notepad to the front, for example, you would call:

ActivateApp("notepad");


作为附带说明 - 对于那些你谁试图您的应用程序的到前台内带来了窗口的只是调用的启动()方法


As a side note - for those of you who are trying to bring a window within your application to the foreground just call the Activate() method.

这篇关于的FindWindow和SetForegroundWindow的选择吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆