如何将我的申请放在最前面? [英] How to bring my application to the front?

查看:69
本文介绍了如何将我的申请放在最前面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个坏主意的所有原因。如果应用程序窃取了输入焦点,我不喜欢它,但这只是出于个人目的,我希望它能够实现。它不会打扰任何东西。

I know all the reasons why it is a bad idea. I dislike it if an application steals input focus, but this is for purely personal use and I want it to happen; it will not disturb anything.

(出于好奇:我正在NetBeans中运行单元测试,这会生成一个日志文件。当我的后台应用程序看到日志文件的时间戳更改时,我希望它解析日志文件,然后显示在最前面以显示结果。)

(for the curious: I am running unit tests in NetBeans, which generate a log file. When my background application sees the log file's timestamp change I want it to parse the log file and come to the front to show the results).

这个问题没有帮助,也没有进行谷歌搜索。似乎 BringToFront()很久没有用了,我找不到其他替代方法。

This question did not help, nor did googling. It seems that BringToFront() hasn't worked for a long time and I can't find any alternative that does.

有什么想法吗?

推荐答案

您不能可靠地做到这一点。 Windows XP有一个允许它的解决方法,但是此后的版本在很大程度上禁止了它(请参阅下面的注释)。这在 SetForegroundWindow

You can't do this reliably. Windows XP had a workaround that would allow it, but versions since then prohibit it for the most part (see note below). This is expressly stated in the remarks section of the MSDN documentation on SetForegroundWindow:


系统限制了哪些进程可以设置前景窗口。仅当满足以下条件之一时,进程才能设置前台窗口:

The system restricts which processes can set the foreground window. A process can set the foreground window only if one of the following conditions is true:


  • 该进程是前台进程。

  • 该进程由前台进程启动。

  • 该进程收到了最后一个输入事件。

  • 没有前台

  • 正在调试前台进程。

  • 前台未锁定(请参见LockSetForegroundWindow)。

  • 前台锁定超时已到期(请参见SystemParametersInfo中的SPI_GETFOREGROUNDLOCKTIMEOUT)。

  • 没有菜单处于活动状态。

  • The process is the foreground process.
  • The process was started by the foreground process.
  • The process received the last input event.
  • There is no foreground process.
  • The foreground process is being debugged.
  • The foreground is not locked (see LockSetForegroundWindow).
  • The foreground lock time-out has expired (see SPI_GETFOREGROUNDLOCKTIMEOUT in SystemParametersInfo).
  • No menus are active.

当用户使用另一个窗口时,应用程序无法将窗口强制到前台。相反,Windows会闪烁窗口的任务栏按钮以通知用户。

An application cannot force a window to the foreground while the user is working with another window. Instead, Windows flashes the taskbar button of the window to notify the user.

请注意所引用文档的最后一段,尤其是第一段

Note the final paragraph of the quoted documentation, especially the first sentence.

问题


这纯粹是个人用途,我希望它发生它不会打扰任何东西。

this is for purely personal use and I want it to happen; it will not disturb anything.

是任何应用程序都可以尝试做同样的事情。 纯粹用于个人用途如何告诉您是您本人,而不只是任何应用程序? :-)

is that any application could try to do the same thing. How does "purely personal use" tell it's you personally and not just any application? :-)

注意:我已经尝试了所有可以想到的方法,以使IDE的文档在单击帮助工具按钮时显示在前台,但是我可以get是闪烁的任务栏按钮(我也是用户希望这样做的按钮)。

Note: I've tried everything I can think of to get the IDE's documentation to show in the foreground when I click the help toolbutton, but all I can get is the flashing taskbar button (and I as the user want it to do so).

这篇关于如何将我的申请放在最前面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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