3

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,

Svisstack
  • 16,203
  • 6
  • 66
  • 100
  • 1
    The fact you're asking how to make something "more top most" didn't already indicate to you that there might be a problem with your design? That's not `WS_TOPMOST` works. – Cody Gray - on strike Feb 01 '11 at 14:05
  • 5
    Obligatory Raymond Chen link - http://blogs.msdn.com/b/oldnewthing/archive/2005/06/07/426294.aspx – stuartd Feb 01 '11 at 14:11
  • I'm not going to try to guess what "stroger top most" might mean. You are going to have to pinvoke SetParent(). – Hans Passant Feb 01 '11 at 14:47

3 Answers3

8

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"

Gabriel Magana
  • 4,338
  • 24
  • 23
2

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#.

Pieter van Ginkel
  • 29,160
  • 8
  • 71
  • 111
  • why you asserting a one application must be on screen? i must have one fullscreen application with some important program and second is semi transparent to warning about unaswered actions on telephone, then i must have 2 ontop. – Svisstack Feb 01 '11 at 14:14
  • @Svisstack - I do not entirely understand how you conclude I believe only one application must be on screen. Could you elaborate? – Pieter van Ginkel Feb 01 '11 at 14:24
  • @Pieter: One application must be on screen always because doing very imporant things. Second application is opens only small popups semi transparent windows on right bottom of screen and i want this windwos be under application then this application must be more topmost. – Svisstack Feb 01 '11 at 14:30
  • @Shivsstack - I believe the information I provided should be enough for you to achieve exactly that. Are you missing specific information in my explanation? – Pieter van Ginkel Feb 01 '11 at 14:40
  • @Shivsstack: You can't have two applications on top *simultaneously*. One of them is always going to cover up the other. It's time to buy a bigger monitor, or add a second one. – Cody Gray - on strike Feb 01 '11 at 14:46
  • @Code Gray - This is not the issue (if I understand correctly). The issue is that @Svisstack wants to control the z-ordering within the top lever windows. Because in principle this should not differ from controlling z-ordering with non-top-level windows, the provided answer should work. – Pieter van Ginkel Feb 01 '11 at 14:47
  • @Pieter: Yeah, I completely agree with your answer. I was replying to the OP's comments about why only one application can be on screen at a time, or why only one thing can be topmost. But perhaps I've misunderstood the exchange entirely. The question doesn't seem to make a lot of sense to me. For the record, this should clearly be the accepted answer; it's the only one that explains *how* to activate another window. – Cody Gray - on strike Feb 01 '11 at 15:06
0

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

Anton Semenov
  • 6,227
  • 5
  • 41
  • 69