简体   繁体   English

在Delphi或Java中将窗口保持在顶部

[英]Keep window on top in Delphi or Java

Is it possible in Delphi to keep a window on top of all other windows? 在Delphi中是否可以将一个窗口保持在所有其他窗口之上? For example when you have an error message in your application, let's say you want to keep the window on top and make sure the user has to click something before he can do anything else. 例如,当您的应用程序中出现错误消息时,假设您希望将窗口保持在顶部,并确保用户必须单击某些内容才能执行其他操作。 And I really mean anything, like clicking another program in the background. 而且我的意思真的很重要,例如在后台单击另一个程序。 And how about in Java? 在Java中呢?

No. Raymond Chen of Microsoft has a great article about why not here . 否。Microsoft的Raymond Chen撰写了一篇很棒的文章,介绍了为什么不在这里 The gist of it is that no matter how hard you try to keep your window on top, someone else can always come along and do the same thing. 其要旨是,无论您多么努力地将窗口保持在顶部,其他人总是可以走过来做同样的事情。

You could do this in the old days. 过去您可以这样做。 It was called a system modal dialog and you used the now obsolete SetSysModalWindow() function. 它被称为系统模式对话框,并且您使用了已过时的SetSysModalWindow()函数。

They were utterly repugnant and so sense and order was restored when Windows NT based versions of Windows took over. 它们完全令人讨厌,因此当基于Windows NT的Windows版本接管时,它们的感觉和顺序得以恢复。

In Delphi you can do FormStyle:=fsStayOnTop; 在Delphi中,您可以执行FormStyle:=fsStayOnTop; . This will put you in front of all normal windows. 这会将您置于所有普通窗口的前面。

But if there are other windows which have that style set too(such as the task-bar) those might be on in front of yours. 但是,如果还有其他设置了样式的窗口(例如任务栏),则这些窗口可能位于您的前面。 In particular among those windows the one that has focus is has the highest priority. 特别是在那些窗口中,具有焦点的窗口具有最高优先级。

You can try to ensure that your window always has focus, but that's rarely a good idea. 您可以尝试确保窗口始终具有焦点,但这不是一个好主意。 And you will incur the wraith of Raymond. 您将招致雷蒙德的恐惧。

You can also use a layered window. 您也可以使用分层窗口。 I think those are in front of normal always-on-top windows. 我认为这些是在普通的始终位于顶部的窗户前面的。 But this has severe side effects and is most likely not the correct choice for you. 但这具有严重的副作用,很可能不是您的正确选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM