我知道这是一个坏主意的所有原因。如果一个应用程序窃取输入焦点,我不喜欢,但这是纯粹的个人使用,我想要它发生;它不会打扰任何东西。
(为了好奇:我在NetBeans中运行单元测试,它会生成一个日志文件。当我的后台应用程序看到日志文件的时间戳更改时,我希望它解析日志文件并显示结果)。
This question没有帮助,也没有谷歌搜索。看来BringToFront()没有工作很长时间,我找不到任何替代方法。
有任何想法吗?
解决方法
你不能可靠地做到这一点。 Windows XP有一个允许它的解决方法,但是从那时起,版本大部分都禁止它(见下面的注释)。在
SetForegroundWindow
的MSDN文档的备注部分明确说明:
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:
- 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.
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.
请注意引用文件的最后一段,特别是第一句。
的问题
this is for purely personal use and I want it to happen; it will not disturb anything.
任何应用程序都可以尝试做同样的事情。 “纯粹的个人使用”如何告诉您是个人而不是任何应用程序?