Erik Stens
Erik Stens

Reputation: 1807

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?

Upvotes: 0

Views: 886

Answers (3)

Ken White
Ken White

Reputation: 125718

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.

Upvotes: 6

CodesInChaos
CodesInChaos

Reputation: 108810

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.

Upvotes: 0

David Heffernan
David Heffernan

Reputation: 613063

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.

Upvotes: 0

Related Questions