2 Application Top Most problem

3.6k views Asked by At

I developed 2 applications one in Win32 API and second in C# WPF. I have a problem, 2 applications must be top most, but second (in C#) must be stroger top most than first application, problem is second application is run from autostart then will be always faster launched than first application, and first application is more top most than second?

How i can do second application more top most? Or how i can show second application on topmost when already have top most and this is under first application?

Can anyone help me? Greetings,

3

There are 3 answers

0
Gabriel Magana On BEST ANSWER

From http://msdn.microsoft.com/en-us/library/system.windows.window.topmost.aspx:

In the group of windows that have Topmost property is set to true, the window that is currently activated is the topmost window.

So activate the window that you want to be the top-top-topmost :-) ...

EDIT: I agree with Pieter that doing this is something that is almost always a bad idea (taking control from the user). This is why MS does not go out of its way to give you tools to do stuff like you want to do. I'll give you the benefit of the doubt and not tell you "do not do this"

7
Pieter van Ginkel On

This is not something you should want to do.

Whether one application or the other is on top, is something you want to leave to the user.

However, there are options.

Using FindWindow, you can find the window handle of the window that was started first. Then, when you have this handle, you can use SetWindowPos to ensure that your window is on top of the other window you've found. You use the z-ordering arguments of SetWindowPos to achieve this.

Note: these are both PInvoke methods. Use the PInvoke for FindWindow and SetWindowPos to call these methods from C#.

0
Anton Semenov On

I see only one way. Second app should monitor first untill first app lunched. After that, you should remove top most style from second app and take it back. This action brings second app top most. It's not elegant but it works