A: 

You can use the Process class to start flash.exe directly - and use an appropriate ProcessStartInfo settings to show the window in a hidden state - or with a WindowStyle of hidden or minimized.

You could also consider using the SetWindowsHookEx API to intercept the process start API calls, and when the process is flash.exe run some code to restore you window to top-most status.

LBushkin
It is a 3rd party application which is starting flash. So, I have no control over it. I think the application was designed poorly.
blak3r
+3  A: 

Setting the TopMost property (or adding the WS_EX_TOPMOST style to a window) does not make it unique in the system. Any number of topmost windows may be created by any number of applications; the only guarantee is that all topmost windows will be drawn 'above' all non-topmost windows. If there are two or more topmost windows, the Z-order still applies. From your description, I suspect that flash.exe is also creating a topmost window.

Aside from periodically forcing your window to the top of the Z-order, I think there is little you can do. Be warned, however, that this approach is dangerous: if two or more windows are simultaneously trying to force themselves to the top of the Z-order, the result will be a flickering mess that the user will likely have to use the task manager to escape.

I recommend that your program not attempt to meddle with other processes on the computer (unless that is its explicit purpose, e.g. a task manager clone). The computer belongs to the user, and he may not value your program more highly than all others.

Addendum:

For the emergency situation described in the comments, I would look at possible solutions along these lines:

  1. How does the third party application normally get started and stopped? Am I permitted to close it the same way? If it is a service, the Service Control Manager can stop it. If it is a regular application, sending an escape keystroke (with SendInput() perhaps) or WM_CLOSE message to its main window may work.

  2. If I can't close it nicely, am I permitted to kill it? If so, TerminateProcess() should work.

  3. If I absolutely have to leave the other process running, I would try to see if I can programmatically invoke fast user switching to take me to a different session (in which there will be no competing topmost windows). I don't know where in the API to start with this one. (Peter Ruderman suggests SwitchDesktop() for this purpose in his answer.)

Matthew Xavier
@Matthew Xavier Normally, I'd agree with your suggestion to not meddle with the user's computers. In this case, the application is for an emergency alert system. The computer is not a personal computer but a dedicated content management system which generates a video display for LCD/Plasma Screens located throughout an organization. The customer wants a way to override the content during an emergency. Any suggestions? Nice post!
blak3r
@Matthew Xavier Thanks for all your suggestions. I replied to your addendum in the question.
blak3r
A: 

Matthew's answer is excellent, but I suspect you may be asking the wrong question. Why does your application need to be topmost? If you're trying to create a kiosk or some such, then topmost is not the way to go.

Edit: After reading your response to Matthew's comment, I'd suggest creating a new desktop and switching to it before displaying your alert. (See CreateDesktop and SwitchDesktop in MSDN.)

Peter Ruderman