Keep window on top in Delphi or Java
Is it possible in Delphi to keep a window on top of all other windows? 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?
No. Raymond Chen of Microsoft has a great article about why not here. 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.
They were utterly repugnant and so sense and order was restored when Windows NT based versions of Windows took over.
In Delphi you can do 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.
精彩评论