views:

299

answers:

4

Hi,

I have a main form. This main form generate another form. This new form should be fill before having access to other window. I used Myform.ShowDialog() to make this form modal.

I would like that my form will be on top of every type of other windows even if these windows are not part of my application (for example: Internet explorer page, opened Word document...).

Do you any solution ??

Thanks,

+2  A: 

It sounds like you're using .NET

In which case you can use the Form.TopMost property

myForm->TopMost = true;
myForm->ShowDialog();

http://msdn.microsoft.com/en-us/library/system.windows.forms.form.topmost.aspx

Kevin Laity
A: 

Using Form.TopMost will make the window appear above any other window in your application, but it does not work other applications.

While I have seen apps that make their window float on top of all other windows, I don't think you can make a modal dialog box that prevents you from using other applications.

A really dirty hack would be to have a timer the forces your window to the foreground every second. It means that users would not be able to use any other application in a meaningful way, but they will definitely hate you for it.

You could also try simulating the Windows Vista/7 -style UAC dialog by taking a snapshot of the desktop, making a full-screen window with that image in it, and then rendering your window on top. However, experience shows that users don't like those UAC dialogs either.

antonm
Not true, fire up visual studio and try it. Make a new forms application (in C# for example), and in the Load method, set this.TopMost = true. Then focus another window on top of it. This functionality has been present at least since Windows 95, maybe longer. Traditionally it has been referred to as "Always on top"
Kevin Laity
This is true if it was your application on focus at the time the dialog will pupop. But if the focus is on internet explorer when the dialog popup the windows will stay in the back until you will select it. Thanks,
A: 

won't form->DoModal() do the trick? (works in MFC anyways?)

jilles de wit
I think this will work within the application but does not stay on top of windows from other programs.
theycallmemorty
This is as good as you can get in windows AFAIK. It used to be possible in windows 3.1, maybe even windows 95, but no longer. Good thing too, annoying behaviour :-)
jilles de wit
A: 

Raymond Chen proved why it's impossible:

Imagine if it was possible for applications to do this, you did, and another application did this too. Now obviously that application would be on top of every windows, including yours, yet your application would be on top of every other window, including theirs. It's a logical impossibility that your window is on top of theirs AND their window is on top of yours. Hence it follows logically that it is not possible for any application to claim the topmost window.

MSalters
one of the windows would be topmost
CiscoIPPhone
Obviously, violating the premise that the other application could make its window topmost.
MSalters