且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将我的应用程序带到前台?

更新时间:2023-02-06 23:05:40

你不能可靠地做到这一点.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).
  • 没有菜单处于活动状态.

当用户正在使用另一个窗口时,应用程序不能强制一个窗口到前台.相反,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 的文档显示在前台,但我能得到的只是闪烁的任务栏按钮(我作为用户希望它这样做).

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).